forked from ryanhaining/cppitertools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestfilter.cpp
More file actions
46 lines (34 loc) · 930 Bytes
/
Copy pathtestfilter.cpp
File metadata and controls
46 lines (34 loc) · 930 Bytes
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
#include <filter.hpp>
#include <vector>
#include <iostream>
using iter::filter;
bool greater_than_four(int i) {
return i > 4;
}
class LessThanValue {
private:
int compare_val;
public:
LessThanValue() = delete;
LessThanValue(int v) : compare_val(v) { }
bool operator() (int i) {
return i < this->compare_val;
}
};
int main() {
std::vector<int> vec{1, 5, 6, 7, 2, 3, 8, 3, 2, 1};
std::cout << "Greater than 4 (function pointer)\n";
for (auto i : filter(greater_than_four, vec)) {
std::cout << i << '\n';
}
std::cout << "Less than 4 (lambda)\n";
for (auto i : filter([] (const int i) { return i < 4; }, vec)) {
std::cout << i << '\n';
}
LessThanValue lv(4);
std::cout << "Less than 4 (callable object)\n";
for (auto i : filter(lv, vec)) {
std::cout << i << '\n';
}
return 0;
}