#include <iostream>
#include <deque>
#include <iterator>
#include <algorithm>
using namespace std;
template <class T>
class Print
{
public:
void operator () (T& t)
{
cout << t << " ";
}
};
//=============================
int main ()
{
int ary[5];
fill(ary,ary+5,1);
deque<int> d;
deque<int>::iterator It;
Print<int> print;
copy(ary,ary+5,
back_inserter(d));
cout << "deque d : ";
for_each(d.begin(),d.end(),print);
cout << endl;
It = d.begin();
// insert value "5" at the position "It"
cout << "d.insert(It,5) : ";
d.insert(It,5);
for_each(d.begin(),d.end(),print);
cout << endl;
// insert range ary+2 - ary+5 at the position "It"
It = d.begin()+5;
cout << "d.insert(It,ary+2,ary+5 : ";
d.insert(It,ary+2,ary+5);
for_each(d.begin(),d.end(),print);
cout << endl;
// insert 2 value of "20" at the position "It"
It = d.end()-2;
cout << "d.insert(It,2,20) : ";
d.insert(It,2,20);
for_each(d.begin(),d.end(),print);
cout << endl;
getchar();
return 0;
}