-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathExer10_28.cpp
More file actions
40 lines (40 loc) · 1.09 KB
/
Exer10_28.cpp
File metadata and controls
40 lines (40 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include <deque>
#include <list>
#include <vector>
#include <algorithm>
#include <iterator>
#include <functional>
using std::cout;
using std::endl;
using std::deque;
using std::list;
using std::vector;
using namespace std::placeholders;
void print(const int &i, char c = ' ')
{
cout << i << c;
}
int main()
{
vector<int> ivec{ 1, 2, 3, 4, 5, 6, 7, 8, 9 };
vector<int> ivec2;
list<int> ilst;
deque<int> idq;
copy(ivec.cbegin(), ivec.cend(), back_inserter(ivec2));
copy(ivec.cbegin(), ivec.cend(), front_inserter(ilst));
copy(ivec.cbegin(), ivec.cend(), inserter(idq, idq.begin()));
cout << "ivec, original:\t";
for_each(ivec.cbegin(), ivec.cend(), bind(print, _1, ' '));
cout << endl;
cout << "ivec2, back_inserter:\t";
for_each(ivec2.cbegin(), ivec2.cend(), bind(print, _1, ' '));
cout << endl;
cout << "ilst, front_insert:\t";
for_each(ilst.cbegin(), ilst.cend(), bind(print, _1, ' '));
cout << endl;
cout << "idq, inserter:\t";
for_each(idq.cbegin(), idq.cend(), bind(print, _1, ' '));
cout << endl;
return 0;
}