|
vector::erasepublic member function
iterator erase ( iterator position ); iterator erase ( iterator first, iterator last ); Erase elements Removes from the vector container either a single element (position) or a range of elements ([first,last)).This effectively reduces the vector size by the number of elements removed, calling each element's destructor before. Because vectors keep an array format, erasing on positions other than the vector end also moves all the elements after the segment erased to their new positions, which may not be a method as efficient as erasing in other kinds of sequence containers (deque, list). This invalidates all iterator and references to elements after position or first. ParametersAll parameters are of member type iterator, which in vector containers are defined as a random access iterator type.
Return valueA random access iterator pointing to the new location of the element that followed the last element erased by the function call, which is the vector end if the operation erased the last element in the sequence.Example
Output:
ComplexityLinear on the number of elements erased (destructors) plus the number of elements after the last element deleted (moving).See also
|