I prefer to get info from the source, for this case this is ISO-IEC 14882, where erase method is described as the following:
"iterator erase(const_iterator position);
iterator erase(const_iterator first, const_iterator last);Effects: Invalidates iterators and references at or after the point of the erase.
Complexity: The destructor of T is called the number of times equal to the number of the elements erased, but the move assignment operator of T is called the number of times equal to the number of elements in the vector after the erased elements.
Throws: Nothing unless an exception is thrown by the copy constructor, move constructor, assignment operator, or move assignment operator of T."
Can't find information about returned iterator, of course, I Googled and got:
An iterator pointing to the new location of the element that followed the last element erased by the function call
Can't understand there this is described in the standard
Could you point me on it?
Update: my question is not about how vector::erase
works,
but rather from where in the standard, as I accept as reliable source of information we can deduce information about returned value
The information is in a slightly un-intuitive place. What erase
returns is detailed under the sequence containers section of general container requirements section, specificly [sequence.reqmts]/11
The iterator returned from
a.erase(q)
points to the element immediately followingq
prior to the element being erased. If no such element exists,a.end()
is returned.
and [sequence.reqmts]/12
The iterator returned by
a.erase(q1, q2)
points to the element pointed to byq2
prior to any elements being erased. If no such element exists,a.end()
is returned.
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