Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > insert question..

Reply
Thread Tools

insert question..

 
 
Mattias B
Guest
Posts: n/a
 
      11-21-2003
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

 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      11-21-2003
"Mattias B" <(E-Mail Removed)> 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


 
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
Insert Multiple Records Using One Insert Statemen with MySQLdb module anton.ranieri.it@gmail.com Python 1 12-06-2008 12:47 PM
insert in std::map does not insert the object simon.elbaz@free.fr C++ 1 11-04-2007 11:42 PM
Insert & Insert/Repeat buttons in a detailsview eagle ASP .Net Datagrid Control 0 07-12-2007 12:47 PM
Detailsview loses insert mode contents when Insert fails... cannontrodder ASP .Net 1 07-25-2006 08:38 AM
DetailsView - Changing to Insert Mode (Not By Using the Insert Button In the DetailsView Control) Feege ASP .Net Web Controls 0 12-20-2005 12:28 AM



Advertisments