Re: rvalue containers - more problems
Am 09.04.2012 20:23, schrieb Gene Bushuyev:
In my previous post I described why I think there is a need for move
iterators for rvalue containers:
This time I stumbled upon a problem using rather common
std::set<std::string> container when I needed to move a large set of
strings to another container. As far as I can see, there is no way to
move strings from the set, because set provides only const iterator.
There are no functions in the set class which would allow moving
either whole set or an iterator range to another container.
This is correct. The short answer to that question is - as Dave
mentioned - that this would invalidate the invariants of the set, which
has effectively immutable keys (at least to the point that any
user-changes shall no have impact on the ordering).
The longer answer is: I agree that some form of mutable API would be
quite useful to have for sets. It would need to be some new form of API,
because you need to ensure that any "moved" key is no longer part of the
set (Thus it cannot have impact on the class invariants). Howard Hinnant
made a very promising comment in the closed LWG issue
(Look for the comment starting with "[ 2009-09-19 Howard adds: ]").
Now finally someone has to come up and make a full-fledged proposal out
of this ;-)
HTH & Greetings from Bremen,
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]