Using the assignment operator on the insert_iterator, even when dereferenced, causes the container to insert a new element at its beginning. The other typical operators of an output iterator are also defined for insert_iterator, but have no effect.
It is defined with an identical operation to:
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
|
The library provides a function, called inserter, that automatically generates an insert_iterator class from a container and an iterator.
Member functions
- constructor
- insert_iterator objects are constructed from a container and an iterator pointing to an element of this container.
- operator=
- Inserts a new element in the container, initializing its value to a copy of the argument.
- operator*
- Does nothing. Returns a reference to the object.
- operator++
- Does nothing. Returns a reference to the object.
Example
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
|
Output:
1 2 3 10 20 30 40 50 4 5 |
See also
| inserter | Construct an insert iterator (function template) |
| back_insert_iterator | Back insert iterator (class template) |
| front_insert_iterator | Front insert iterator (class template) |
