iterator insert(iterator it, const T& x = T());
void insert(iterator it, size_type n, const T& x);
void insert(iterator it, const_iterator first, const_iterator last);
Each of the member functions inserts, before the element pointed to by it
in the controlled sequence, a sequence
specified by the remaining operands. The first member function inserts a single element with value x
and returns an
iterator that points to the newly inserted element. The second member function inserts a repetition of n
elements of
value x
. The last member function inserts the sequence [first, last)
.
In this implementation, if a translator does not support member template functions, the template:
template<class InIt>
void insert(iterator it, InIt first, InIt last);
is replaced by:
void
insert
(iterator it, const_iterator first, const_iterator last);
When inserting a single element, the number of element copies is linear in the number of elements between the insertion
point and the nearer end of the sequence. When inserting a single element at either end of the sequence, the amortized
number of element copies is constant. When inserting N
elements, the number of element copies is linear in N
plus the
number of elements between the insertion point and the nearer end of the sequence -- except when the template
member is specialized for InIt
an input or forward iterator, which behaves like N
single insertions. Inserting an element
at either end invalidates all iterators, but no references, that designate existing elements. Otherwise, inserting an element
invalidates all iterators and references.
See the related sample program.