-
Notifications
You must be signed in to change notification settings - Fork 0
/
Test.cpp
42 lines (32 loc) · 847 Bytes
/
Test.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
#include "ThreadPool.h"
#include <iostream>
auto free_func(int a, int b, int c)
{
return a + b + c;
}
auto lambda_func = [](auto&&... args) -> typename std::common_type<decltype(args)...>::type
{
return (args + ...);
};
struct Pod
{
auto mem_func(int a, int b, int c)
{
return a + b + c;
}
};
int main()
{
TP::ThreadPool tp(std::thread::hardware_concurrency());
// queue free function
auto f = tp.addTask(free_func, 1, 2, 3);
// queue variadic lambda or template wrapper
auto g = tp.addTask(lambda_func, 1, 2, 3.5);
// queue member function
auto h = tp.addTask(std::mem_fn(&Pod::mem_func), Pod {}, 1, 2, 3);
std::cout << f.get() << '\n'
<< g.get() << '\n'
<< h.get() << '\n';
tp.stop();
return 0;
}