Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
Miscellaneous
Miscellaneous
complex
exception
functional
iterator
limits
locale
memory
new
numeric
stdexcept
typeinfo
utility
valarray
iterator
advance
back_inserter
distance
front_inserter
inserter
iterator
iterator_traits
iterator categories:
BidirectionalIterator
ForwardIterator
InputIterator
OutputIterator
RandomAccessIterator
predefined iterators:
back_insert_iterator
front_insert_iterator
insert_iterator
istreambuf_iterator
istream_iterator
ostreambuf_iterator
ostream_iterator
reverse_iterator


front_inserter

function template
<iterator>
template <class Container>
  front_insert_iterator<Container> front_inserter (Container& x);

Constructs a front insert iterator

This function generates a front insert iterator for a container.

A front insert iterator is a special type of output iterator specifically designed to allow algorithms that usually overwrite elements (such as copy) to instead insert new elements at the front of the container.

Parameters

x
Container for which the front insert iterator is constructed.

Return value

A front_insert_iterator that inserts elements at the beginning of container x.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// front_inserter example
#include <iostream>
#include <iterator>
#include <deque>
using namespace std;
int main () {
  deque<int> firstdeque, seconddeque;
  for (int i=1; i<=5; i++)
  { firstdeque.push_back(i); seconddeque.push_back(i*10); }
  copy (seconddeque.begin(),seconddeque.end(),front_inserter(firstdeque));
  deque<int>::iterator it;
  for ( it = firstdeque.begin(); it!= firstdeque.end(); ++it )
	  cout << *it << " ";
  cout << endl;
  return 0;
}


Output:

50 40 30 20 10 1 2 3 4 5

See also