Valid iterators in a std::list?

D

desktop

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.
 
J

Juha Nieminen

desktop said:
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.
 
D

dasjotre

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,992
Messages
2,570,220
Members
46,807
Latest member
ryef

Latest Threads

Top