-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexamples.cpp
More file actions
64 lines (44 loc) · 1.68 KB
/
examples.cpp
File metadata and controls
64 lines (44 loc) · 1.68 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
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <utility>
#include <set>
#include "combinators.hpp"
using namespace std;
int main() {
std::vector<int> v{6, 2, 3, 4, 5, 6};
set<int> s = {1,2,3,4};
std::vector<float> d(v.size());
std::cout << "**************Ex1******************" << std::endl;
//1. map over the vector and return a vector<float> with twice the value
auto f = _map(v,d, [](int x) { return x*2.0;});
for(int i = 0;i < d.size();i++) {
std::cout << std::fixed << d[i] << std::endl;
}
std::cout << "**************Ex2******************" << std::endl;
//2. (Set)return vector of pair with each element zipped with it's index
auto p = _zipWithIndex(s);
for(int i = 0;i < p.size();i++) {
std::cout << p[i].first << " " << p[i].second << std::endl;
}
std::cout << "**************Ex3******************" << std::endl;
//3. (Vector)return vector of pair with each element zipped with it's index
auto q = _zipWithIndex(v);
for(int i = 0;i < q.size();i++) {
std::cout << q[i].first << " " << q[i].second << std::endl;
}
std::cout << "**************Ex4******************" << std::endl;
//4. filter the elements based on a predicate
auto g = _filter(v, [](int x) { return x%2 == 0;});
for(int i = 0;i < g.size();i++) {
std::cout << g[i] << std::endl;
}
std::cout << "**************Ex5******************" << std::endl;
//4. not filter the elements based on a predicate
auto h = _filterNot(v, [](int x) { return x%2 == 0;});
for(int i = 0;i < h.size();i++) {
std::cout << h[i] << std::endl;
}
return 0;
}