By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,232 Members | 1,593 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,232 IT Pros & Developers. It's quick & easy.

insert question..

P: n/a
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

Jul 22 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
"Mattias B" <br****@ludd.luth.se> 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
Jul 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.