[Bug libstdc++/23633] map::insert() invalidates reverse_iterators

chris at bubblescope dot net gcc-bugzilla@gcc.gnu.org
Tue Aug 30 15:49:00 GMT 2005


------- Additional Comments From chris at bubblescope dot net  2005-08-30 15:35 -------
While this behaviour is suprising, it is also not a bug. The problem comes from the fact that
&*(reverse_iterator(i)) = &*(i-1), so when you dereference a reverse_iterator the value you actually get is 
from the iterator before the one is stored inside the reverse_iterator (I hope that makes sense). That might 
seem strange, but there are good reasons for it, and it's unavoidable.

in std::map, this causes problems, as the an iterator can be inserted between i and i-1 (as in this case 
here), making the thing a reverse_iterator points at can change.

Personally, I've always considered reverse_iterator a bit of a nasty hack. In this case I'm sure we are correct 
with respect to the standard, and there really isn't a good way to fix either map or reverse_iterator so this 
code acts as you expect I'm afraid.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |chris at bubblescope dot net


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23633



More information about the Gcc-bugs mailing list