-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.cpp
76 lines (68 loc) · 1.73 KB
/
main.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <iostream>
#include <vector>
#include "Concurrent.h"
int main()
{
{
auto asyncTask = [](int param) {
std::cout << "This is an async task! param is " << param << std::endl;
};
int i = 9;
auto future = Fate::ThreadPool::run(asyncTask, i);
future.wait();
}
{
std::vector<int> num = { 1, 2, 3, 4, 5, 6 };
auto mapFunc = [](int& element) {
element += 10;
};
auto future = Fate::Concurrent::map(num, mapFunc);
future.wait();
std::cout << "map test begin: " << std::endl;
for (const auto& element : num)
{
std::cout << element << " ";
}
std::cout << std::endl;
std::cout << "map test end!" << std::endl << std::endl;
}
{
std::vector<int> num = { 1, 2, 3, 4, 5, 6 };
auto mapFunc = [](int element) {
element += 10;
return element;
};
auto future = Fate::Concurrent::mapped(num, mapFunc);
auto ret = future.get();
std::cout << "mapped test begin: " << std::endl;
std::cout << "Origin: " << std::endl;
for (const auto& element : num)
{
std::cout << element << " ";
}
std::cout << std::endl;
std::cout << "Return: " << std::endl;
for (const auto& element : ret)
{
std::cout << element << " ";
}
std::cout << std::endl;
std::cout << "mapped test end!" << std::endl << std::endl;
}
{
std::vector<int> num = { 1, 2, 3, 4, 5, 6 };
auto mapFunc = [](int& element) {
return element + 10;
};
auto reduceFunc = [](int& reduceRet, int mapRet)
{
reduceRet += mapRet;
};
auto future = Fate::Concurrent::mappedReduced(num, mapFunc, reduceFunc, 19);
auto ret = future.get();
std::cout << "mappedReduced test begin: " << std::endl;
std::cout << "ret: " << ret << std::endl;
std::cout << "mappedReduced test end!" << std::endl << std::endl;
}
return 0;
}