Topic: invalidated iterators and end()
Author: anti_spam_email2003@yahoo.com (Me)
Date: Wed, 2 Jun 2004 17:43:50 +0000 (UTC) Raw View
If I have code like:
cont::iterator e = c.end();
for (cont::iterator i = c.begin(); i != e; ) {
i = c.erase(i);
}
Where c is a container (like list or map) that doesn't invalidate
iterators on insertion or removal. Is the e iterator above also
guaranteed not to be invalidated?
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: kuyper@wizard.net (James Kuyper)
Date: Thu, 3 Jun 2004 21:37:06 +0000 (UTC) Raw View
anti_spam_email2003@yahoo.com (Me) wrote in message news:<682764f7.0406012246.5f88f91@posting.google.com>...
> If I have code like:
>
> cont::iterator e = c.end();
>
> for (cont::iterator i = c.begin(); i != e; ) {
> i = c.erase(i);
> }
>
> Where c is a container (like list or map) that doesn't invalidate
> iterators on insertion or removal. Is the e iterator above also
> guaranteed not to be invalidated?
Yes - it's the iterator value that is invalidated; the iterator itself
is invalidated only because it's value has been invalidated. That
implies that all iterators that contain a give value get invalidated,
whenever that value gets invalidated. Conversely, all copies of an
iterator value remain valid as long that value remains valid.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]