This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/23633] map::insert() invalidates reverse_iterators
- From: "chris at bubblescope dot net" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 30 Aug 2005 15:35:34 -0000
- Subject: [Bug libstdc++/23633] map::insert() invalidates reverse_iterators
- References: <20050830125045.23633.relf@os2.ru>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- 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