As for the title, is it ok to pass vec.end()
as the position parameter? I.e., is the behaviour of
std::vector<int> vec;
vec.insert(vec.end(), 0);
well defined?
Yes, it is well defined. Assume if vector is empty, begin()
equals to end()
. The effects is it inserts a copy of element before iterator.
§ Table 100 — Sequence container requirements (in addition to container)
|------------------------------------------------------------------------------|
|a.insert(p,t) | iterator Requires:T shall be CopyInsertable into X. For |
| | vector and deque, T shall also be CopyAssignable.|
| | Effects: Inserts a copy of t before p. |
-------------------------------------------------------------------------------|
also look at: std::vector::insert
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With