pointers to std::list elements

Discussion in 'C++' started by n.torrey.pines, Nov 17, 2006.

  1. 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 ?
     
    n.torrey.pines, Nov 17, 2006
    #1
    1. Advertising

  2. 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
     
    Victor Bazarov, Nov 17, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jimjim
    Replies:
    18
    Views:
    7,401
    Default User
    Apr 12, 2004
  2. Replies:
    6
    Views:
    662
    Jim Langston
    Oct 30, 2005
  3. Adam Hartshorne
    Replies:
    2
    Views:
    381
    Nitin Motgi
    Jan 27, 2006
  4. Juha Nieminen
    Replies:
    22
    Views:
    1,048
    Kai-Uwe Bux
    Oct 12, 2007
  5. cerr

    pointers, pointers, pointers...

    cerr, Apr 7, 2011, in forum: C Programming
    Replies:
    12
    Views:
    694
Loading...

Share This Page