The front_insert_iterator
is an iterator adapter that acts as an output iterator, but which converts expressions of the form *itr = value
into calls to push_front
on an STL container. The front_insert_iterator
constructor takes in a reference to another STL container class that should have push_front
invoked on it. Because the front_insert_iterator
calls push_front
on the element it wraps, the container type must support the push_front
function. Consequently, you cannot use a front_insert_iterator
on an STL map
or set
; for those classes, consider using insert_iterator
. Also, since vector
does not support push_front
, you cannot use a front_insert_iterator
on an STL vector
.
front_insert_iterator
is a template type whose argument is the type of container to which the front_insert_iterator
should forward its requests. For example, to invoke push_front
on a container of type deque<int>
, you would use a front_insert_iterator<deque<int> >
. Remember to include the extra space between the closing angle brackets or you will get a compile-time error!
Since the above syntax can get a bit clunky, the STL provides a utility function, front_inserter
, which creates front_insert_iterator
s.
front_insert_iterator<Container>
Utility Functions
front_insert_iterator<Container>
Member Functions
front_insert_iterator<Container>
Utility FunctionsConstructs a new front_insert_iterator
that calls push_front
on the element specified as the parameter when dereferenced. It is preferable to create front_insert_iterator
s using front_inserter
rather than through a constructor call, since the compiler will figure out the correct type of front_insert_iterator
to create. Since in most cases you will create front_insert_iterator
s as parameters to functions, this function also lets you avoid writing out the type of the front_insert_iterator
longhand.
front_insert_iterator<Container>
Member Functionsfront_insert_iterator
on the specified element.Constructs a new front_insert_iterator
that calls push_front
on the element specified as the parameter when dereferenced.