insert question..

Discussion in 'C++' started by Mattias B, Nov 21, 2003.

  1. Mattias B

    Mattias B Guest

    Hello!

    I have a question about how stl's insert works on containers and on
    vector in particular.

    The question is: is it OK to insert a value before end() with something
    like:

    vector<int> v;
    v.insert(v.end(), 1);

    In SGI's stl documentation it says that the iterator passed to insert
    must be a valid iterator in v. Is end() a valid operator or must an
    iterator be derefernceable in order to be valid?

    Regards,
    Mattias
    Mattias B, Nov 21, 2003
    #1
    1. Advertising

  2. "Mattias B" <> wrote...
    > I have a question about how stl's insert works on containers and on
    > vector in particular.
    >
    > The question is: is it OK to insert a value before end() with something
    > like:
    >
    > vector<int> v;
    > v.insert(v.end(), 1);


    Yes, it is OK. BTW, that's "push_back"s operational semantics
    for 'vector', 'list', and 'deque'.

    > In SGI's stl documentation it says that the iterator passed to insert
    > must be a valid iterator in v. Is end() a valid operator or must an
    > iterator be derefernceable in order to be valid?


    No, to be valid an iterator has to be either _to_ an element or
    "one past the end". That makes 'end()' a valid iterator, AFAIK.

    Victor
    Victor Bazarov, Nov 21, 2003
    #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. cannontrodder
    Replies:
    1
    Views:
    719
    cannontrodder
    Jul 25, 2006
  2. Replies:
    1
    Views:
    446
  3. Replies:
    1
    Views:
    1,777
    Albert Hopkins
    Dec 6, 2008
  4. eagle

    Insert & Insert/Repeat buttons in a detailsview

    eagle, Jul 12, 2007, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    1,043
    eagle
    Jul 12, 2007
  5. Feege
    Replies:
    0
    Views:
    444
    Feege
    Dec 20, 2005
Loading...

Share This Page