List Iterators question

Ok I have a list(let's call it list1) and I would like to mark an element in list1.

What I'm doing right now is getting an iterator that marks a position in list1 and assumes that we are marking that element.

Ie.
list<int> list1;
list<int>::iterator iter;
list1.push_back(2);
iter = list1.end();
iter--; //end is a sentinel.

Now iter is pointing to 2. What I'd like to know is that does STL guarantee that as long as that specific element 2 is not removed, iter will always be pointing to that?

Ie. If i do a bunch of adds/removes to list1 but do not touch the element 2 whatsoever, will iter still be pointing to the location of 2.
Hey,

iter will be pointing to the specific element as long as you dont move the iterator or delete the specific element.
Yes, you are guaranteed that by STL for the list<> container. In general, iterator guarantees are container-specific.
Topic archived. No new replies allowed.