Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > pointers to std::list elements

Reply
Thread Tools

pointers to std::list elements

 
 
n.torrey.pines
Guest
Posts: n/a
 
      11-17-2006
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 ?


 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      11-17-2006
n.torrey.pines wrote:
> 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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
pointers, pointers, pointers... cerr C Programming 12 04-07-2011 11:17 PM
Does deleting a container of pointers also delete the (contained) pointers? Xamalek C++ 7 11-04-2003 04:17 PM
c++: pointers to pointers A C++ 3 10-29-2003 01:15 PM
pointers to pointers // exception handling error muser C++ 3 09-18-2003 06:19 PM
Template specialization of pointers with function pointers Phil C++ 1 09-16-2003 02:17 AM



Advertisments