pointers to std::list elements

N

n.torrey.pines

If I insert and delete elements in a std::list, does the standard
guarantee that the pointers to the intact elements remain valid? If so,
where?

Example:

list<int> lst;
lst.push_back(1);
lst.push_back(2);
lst.push_back(3);
lst.push_back(4);

int* p = &(++lst.begin()); // *p == 2

lst.remove(3);
lst.push_front(5);
lst.resize(10);

assert(*p == 2); // guaranteed ?
 
V

Victor Bazarov

n.torrey.pines said:
If I insert and delete elements in a std::list, does the standard
guarantee that the pointers to the intact elements remain valid? If
so, where?

Yes, it does. In the Clause 23 somewhere. Look for 'invalidate' or
'invalidates'. If you don't find that 'insert' or 'erase' specifies
that it invalidates, then it does not.

V
 

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,755
Messages
2,569,536
Members
45,016
Latest member
TatianaCha

Latest Threads

Top