chris said:
Out of interest, do you agree that changing the values of a set in such
a way that the relative order of elements if changed is actually
forbidden? Is it 23.1.2 points 9 and 10 that say this?
My take on this is actually more cautious [and I also urge you to post
your question to comp.std.c++ for clarification]. I think that 23.1.2/9
and 23.1.2/10 simply indicate that the process of _iterating_ through
a container must present a particular order of elements. It does not
say that we can't change values of elements.
There is an embedded conflict in the description of iterators of 'set'.
OOH, they can allow changing of the value_type (i.e. the value type can
be a reference to a non-const object). OTOH, doing so may require
invalidating the rest of iterators (and the whole iteration procedure)
so that it has to be restarted and 'begin()' or 'rbegin()' actually
force at least a re-check of the "structural integrity" of the container.
If only the requirements were a bit stronger, for example, to prohibit
the assignment to *i (where 'i' is std::set::iterator), then everything
would probably fall into place and an implementation that defines the
std::set::iterator::value_type to be a reference to non-const would
suddenly become non-conforming.
It just worries me, because most implementations of set will not just
not be sorted, but simply not work if you start changing the elements
(in particular they will stop making sure that inserted elements are
unique, and it's possible they might crash). I'm kind of suprised now I
think about it you can get a non-constant iterator to the elements of sets.
I think a good discussion in comp.std.c++ is in order, if it didn't happen
already.
Victor