• Advertisement
Sign in to follow this  

STL List question

This topic is 4044 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello everyone, When I remove an element from an STL List, are all iterators (other than the ones related to the removed element) valid? As far as Google goes, they're supposed to be valid for a List and not necessarily valid for a Vector, but I just wanted to confirm that with anyone here who's worked with this. Thanks, Francis Xavier

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by FrancisXavier
When I remove an element from an STL List, are all iterators (other than the ones related to the removed element) valid?
Yup.
Quote:
As far as Google goes, they're supposed to be valid for a List and not necessarily valid for a Vector, but I just wanted to confirm that with anyone here who's worked with this.
That's right. vector has different behavior than list in this respect.

For more details, check out the SGI documentation for list and vector (or any other reliable reference).

Share this post


Link to post
Share on other sites
I got my answer after searching on Google thoroughly.

From http://www.sgi.com/tech/stl/List.html,
"[3] A similar property holds for all versions of insert() and erase(). List<T, Alloc>::insert() never invalidates any iterators, and list<T, Alloc>::erase() only invalidates iterators pointing to the elements that are actually being erased."

Thanks,
Francis Xavier

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement