-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcpp11_for.cpp
More file actions
51 lines (39 loc) · 1.09 KB
/
cpp11_for.cpp
File metadata and controls
51 lines (39 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
41
42
43
44
45
46
47
48
49
50
51
#include <functional>
#include <iostream>
#include <vector>
#include <set>
#include <list>
#include <algorithm>
#include <string>
using namespace std;
int main()
{
//C++11 initialisation
vector<int> coll = { 1, 2, 3, 4, 5, 6};
// New for loop
for(auto item: coll)
{
cout << item << " ";
}
cout << endl;
string str = "abcdef";
string empty = "aaaaaa";
reverse(str.begin(), str.end());
cout << str << endl;
reverse_copy(str.begin(), str.end(), empty.begin());
cout << "copied: " << empty << endl;
auto min_pos = min_element(coll.cbegin(), coll.cend());
auto max_pos = max_element(coll.cbegin(), coll.cend());
cout << "min: " << *min_pos << ", max: " << *max_pos << endl;
//Inserters: back_inserter() calls col.push_back
//front_insert(col) calls col.push_front
//inserter(col, pos) works on associative container too but 'pos' is ignored
vector<int> coll1;
copy(coll.cbegin(), coll.cend(), back_inserter(coll1));
list<int> coll2;
copy(coll.cbegin(), coll.cend(), front_inserter(coll2));
set<int> set1;
copy(coll.cbegin(), coll.cend(),
inserter(set1, set1.begin()));
return 0;
}