a.size() is incremented by n. The relative order of elements
already in the sequence is unchanged.
Range insert
a.insert(p, i, j)
[i,j) is a valid range. a.size() plus the distance from i to
j does not exceed a.max_size().
Inserts a copy of the range [i,j) before p. [1][2][3]
a.size() is incremented by the distance from i to j.
The relative order of elements already in the sequence is unchanged.
Erase
a.erase(p)
p is a dereferenceable iterator in a.
Destroys the element pointed to by p and removes it from a. [3]
a.size() is decremented by 1. The relative order of the other
elements in the sequence is unchanged. The return value is an iterator
to the element immediately following the one that was erased.
Range erase
a.erase(p,q)
[p,q) is a valid range in a.
Destroys the elements in the range [p,q) and removes them from
a. [3]
a.size() is decremented by the distance from i to j.
The relative order of the other elements in the sequence is unchanged.
The return value is an iterator to the element immediately
following the ones that were erased.
Clear
a.clear()
Equivalent to a.erase(a.begin(), a.end())
Resize
a.resize(n, t)
n <= a.max_size()
Modifies the container so that it has exactly n elements, inserting
elements at the end or erasing elements from the end if necessary.
If any elements are inserted, they are copies of t. If n > a.size(),
this expression is equivalent to a.insert(a.end(), n - size(), t).
If n < a.size(), it is equivalent to a.erase(a.begin() + n, a.end()).
a.size() == n
Resize
a.resize(n)
n <= a.max_size()
Equivalent to a.resize(n, T()).
a.size() == n
Complexity guarantees
The fill constructor, default fill
constructor, and range constructor are linear.
Front is amortized constant time.
Fill insert, range insert, and range erase are linear.
The complexities of single-element insert and erase are sequence
dependent.
[1]
At present (early 1998), not all compilers support
"member templates". If your compiler supports member
templates then i and j may be of any type that
conforms to the Input Iterator
requirements. If your compiler does not yet support member
templates, however, then i and j must be of type
const T* or of type X::const_iterator.
[2]
Note that p equal to a.begin() means to insert
something at the beginning of a (that is, before any elements
already in a), and p equal to a.end() means
to append something to the end of a.
[3]Warning: there is no guarantee that a valid iterator on
a is still valid after an insertion or an erasure. In some
cases iterators do remain valid, and in other cases they do not. The
details are different for each sequence class.
[4]a.insert(p, n, t) is guaranteed to be no slower then calling
a.insert(p, t)n times. In some cases it is significantly
faster.
[5]Vector is usually preferable to
deque and list.
Deque is useful in the case of frequent
insertions at both the beginning and end of the sequence, and
list and slist are useful in the case of frequent insertions
in the middle of the sequence. In almost all other situations,
vector is more efficient.