front_insert_iterator class template — Iterator to insert elements at the front of a container
template <typename Container> class front_insert_iterator : public iterator<output_iterator_tag,void,void,void,void> { protected: Container* container; public: typedef Container container_type; explicit front_insert_iterator(Container& x); front_insert_iterator<Container>& operator=(typename Container::const_reference value); front_insert_iterator<Container>& operator*( ); front_insert_iterator<Container>& operator++( ); front_insert_iterator<Container> operator++(int); };
The front_insert_iterator
class template implements an output iterator that stores elements in
a container by calling the container's push_front
function. The most convenient
way to create a front_insert_iterator
object is to use the
front_inserter
function
template.
The way front_insert_iterator
works seems slightly
unconventional, although it is perfectly reasonable for an output
iterator: the *
operator returns
the iterator, not an element of the container. Thus, the expression
*iter
=
value
assigns value
to the iterator
itself. The iterator's assignment operator adds value
to the underlying container by
calling the container's push_front
function. Thus, the iterator
does not maintain any notion of a position, and the increment
operator is a no-op.
The following are the member functions of front_insert_iterator
:
explicit
front_insert_iterator
(Container& x)
Initializes the container
member with &x
.
front_insert_iterator<Container>&
operator=
(typename
Container::const_reference value)
Calls container->push_front(value)
. The
return value is *this
.
front_insert_iterator<Container>&
operator*
( )
Returns *this
.
front_insert_iterator<Container>&
operator++
( )
, front_insert_iterator<Container>
operator++
(int)
Returns *this
with no
side effects.