function template
std::front_inserter
<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:
See also
- front_insert_iterator
- Front insert iterator (class template)
- back_inserter
- Construct a back insert iterator (function template)
- inserter
- Construct an insert iterator (function template)