Re: Exception-safety of erase
on Fri Jul 11 2008, Adam Badura <abadura-AT-o2.pl> wrote:
From the C++ Standard (point 17.4.4.8 Restrictions on exception
handling [lib.res.on.exception.handling] $3) we now that every C++
Standard Library function which does not have any exception-
specification and is not described otherwise may throw anything
(including objects of types not derived from std::exception). Or am I
mistaken?
That's correct.
From the C++ Standard (point 23.1 Container requirements
[lib.container.requirements] $10) we now that ?erase? on a container
will never throw an exception. Copy constructor or assignment operator
of an iterator returned from a container does not throw any exceptions
as well.
Those are requirements on the specific containers defined in the
standard, not on Containers in general (objects satisfying the
"Container" concept -- see table 65).
But ?erase? specification (23.1.1 Sequences [lib.sequence.reqmts])
does not require it to take as an argument iterator returned by the
container.
You're comparing apples and oranges here. The sequence requirements are
a concept. They only describe a subset of the requirements satisfied by
the standard containers. If you look at the synopses of the individual
containers you'll see that erase(...) always takes an iterator.
Actually it might take an argument of any type as long as
for ?q? being a valid dereferencable iterator into the container
expression ?erase(q)? is valid.
Yes.
But if it takes argument of a
different type then the iterator there is no guarantee in the Standard
that the conversion to that type will not throw.
True.
Thous actually calling ?erase? might result in an exception although
in that case the execution will never get into erase.
True in general, but not for the specific containers defined in the
standard library.
Cheers,
--
Dave Abrahams
BoostPro Computing
http://www.boostpro.com
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]