Re: Exception-safety of erase
In the Standard in point 23.1 $10 in the forth point we can read:
"no copy constructor or assignment operator of a returned iterator
throws an exception.". Fine. But there is no definition of what is
named a "returned iterator".
It's an iterator type that appears as the return type of a standard
library (member) function.
Are those the container's member types "iterator" and
"const_iterator" (and maybe revers iterators as well when they
exist?). It would be nice and logical. But on the other hand why
wouldn't the Standard say just "iterator" (and those other iterators -
maybe a common term could be introduced here) instead of the cryptic
(IMHO) "returned iterator"?
I don't remember exactly, but when Greg Colvin and I wrote that text I
think we were trying to avoid implying that user's iterators couldn't
throw. What about std::reverse_iterator<myiterator> for example?
Since 23.1 $5 (Table 65) requires, for "X denoting a container
class containing objects of type T", that X::iterator be "iterator
type pointing to T" then instead of writing (in 23.1 $10, forth
subpoint) "no copy constructor or assignment operator of a returned
iterator throws an exception." I would have write rather something
like "no copy constructor or assignment operator of type <tt>iterator</
tt> member type throws an exception.".
But as you pointed out it all comes down to how one understands a
particular selection of English words in an English sentence since
that is what it is. Maybe language specifications should be written in
some kind of formal language? :)
Note that it is not obvious (again IMHO) that the Standard meant
here any iterators not just those instances returned by container
functions. I don't see any reason to think that the Standard just used
a strange name. And although copy constructor and assignment operator
belong to iterator's type and not particular instance their behavior
naturally depends on that particular instance. And thous the non-
throwing guarantee may depend on the instance as well.
No. And do you know how I know that? It's because that wasn't our
intention when we wrote the text.
I'm not joking; the intention of the authors matters when interpreting
the standard. We can't eliminate every bit of potential ambiguity in
the standard, since it's written in (a form of) english.
Fine. That answers my question here. Lets hope that STL
implementators (and actually any STL compliant container
implementators) agree to that. :)
Adam Badura
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]