Topic: validity of iterators
Author: gurnec@my-dejanews.com
Date: 1998/09/29 Raw View
Siemel Naran wrote in message ...
>On 25 Sep 1998 22:11:09 GMT, Boris Schaefer
>
>>what is guaranteed by the standard with regards to the validity of
>>iterators.
>
>After push_back, etc:
>
>list iterator : valid
>vector iterator: not valid
>tree iterator : possibly valid, but don't count on it
You must have gotten vector and tree (map) backwards.
After an insert on a map, former iterators into that map are guaranteed
to be valid. (Incidentally, push_back isn't defined for maps because it
doesn't really make sense.)
After a push_back to a vector, the former iterators are probably valid.
They aren't only if a "reallocation" is performed. If the return of
capacity() is greater than the return of size(), no reallocation will be
performed.
-Chris
email: gurnec_at_yahoo_dot_com
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Boris Schaefer <sbo@psy.med.uni-muenchen.de>
Date: 1998/09/25 Raw View
hi,
what is guaranteed by the standard with regards to the validity of
iterators.
I'm having a list of `thing's and I keep an iterator to one special
case. Now I use push_back, push_front and pop_back and pop_front on
the list. Is there a guarantee, that the iterator to the one special
case will always be valid, unless I pop it off the list.
--
Boris Schaefer -- sbo@psy.med.uni-muenchen.de
Any sufficiently advanced technology is indistinguishable from a rigged demo.
- Andy Finkel, computer guy
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: sbnaran@dirac.ceg.uiuc.edu (Siemel Naran)
Date: 1998/09/27 Raw View
On 25 Sep 1998 22:11:09 GMT, Boris Schaefer
>what is guaranteed by the standard with regards to the validity of
>iterators.
After push_back, etc:
list iterator : valid
vector iterator: not valid
tree iterator : possibly valid, but don't count on it
--
----------------------------------
Siemel B. Naran (sbnaran@uiuc.edu)
----------------------------------
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: "P.J. Plauger" <pjp@dinkumware.com>
Date: 1998/09/27 Raw View
Boris Schaefer <sbo@psy.med.uni-muenchen.de> wrote in article <m3d88kw1yd.fsf@skywalker.grs.de>...
> I'm having a list of `thing's and I keep an iterator to one special
> case. Now I use push_back, push_front and pop_back and pop_front on
> the list. Is there a guarantee, that the iterator to the one special
> case will always be valid, unless I pop it off the list.
An Iterator that designates an element of a list<T> object remains valid until
the element is erased.
P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com/hot_news.html
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]