-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstdFuncType.cpp
48 lines (35 loc) · 980 Bytes
/
stdFuncType.cpp
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
#include <iostream>
#include <functional>
#include <vector>
#include <algorithm>
using namespace std;
bool check(string &test) {
return test.size() == 3;
}
class Check {
public:
bool operator()(string &test) {
return test.size() == 5;
}
} check1;
void run(function<bool(string&)> check) {
string test = "dog";
cout << check(test) << endl;
}
int main() {
int size = 5;
vector<string> vec{"one", "two", "three"};
auto lambda = [size](string test) {return test.size() == size;};
int count = count_if(vec.begin(), vec.end(), [size](string test){ return test.size() == size;});
cout << count << endl;
count = count_if(vec.begin(), vec.end(), check);
cout << count << endl;
count = count_if(vec.begin(), vec.end(), check1);
cout << count << endl;
run(lambda);
run(check1);
run(check);
function<int(int, int)> add = [](int one, int two){ return one+two };
cout << add(7, 3) << endl;
return 0;
}