By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,640 Members | 2,095 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,640 IT Pros & Developers. It's quick & easy.

Valid iterators in a std::list?

P: n/a
Are there any case where iterators in a std::list gets invalidated
besides from the iterator pointing to an element thats deleted?

It seems that its only the std::vector that invalidates iterators
pointing to elements after a deleted element since its practically just
an array.
Jun 19 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
desktop wrote:
It seems that its only the std::vector that invalidates iterators
pointing to elements after a deleted element since its practically just
an array.
I think this is so with deque too.
Jun 19 '07 #2

P: n/a
On 19 Jun, 08:39, desktop <f...@sss.comwrote:
Are there any case where iterators in a std::list gets invalidated
besides from the iterator pointing to an element thats deleted?
None other than members that erase elements
It seems that its only the std::vector that invalidates iterators
pointing to elements after a deleted element since its practically just
an array.
vector is not just an array

vector iterators are invalidated after erase, but only those
from the point of erase up. they are also invalidate after
insert, also from the point of insert up. In addition, if either
of the operations requires reallocation, all iterators are
invalidated.

this is similar or close for all containers with random access
iterators. At the moment they are deque, priority_queue,
vector and basic_string.

regards

DS

Jun 19 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.