-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathpacked_task.cpp
More file actions
54 lines (41 loc) · 873 Bytes
/
packed_task.cpp
File metadata and controls
54 lines (41 loc) · 873 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
47
48
49
50
51
52
53
54
#include <iostream>
#include <utility>
#include <cmath>
#include <thread>
#include <future>
#include <functional>
using namespace std;
int f(int x, int y)
{
return pow(x, y);
}
void task_lambda()
{
packaged_task<int(int, int)> task([](int a, int b) {
return pow(a, b);
});
auto result = task.get_future();
task(2, 9);
cout << "task_lambda:\t" << result.get() << endl;
}
void task_bind()
{
packaged_task<int()> task(bind(f, 2, 11));
auto result = task.get_future();
task();
cout << "task_bind:\t" << result.get() << endl;
}
void task_thread()
{
packaged_task<int(int, int)> task(f);
auto result = task.get_future();
//thread task_thread(std::move(task), 2, 10);
//task_thread.join();
//cout << "task_thread:\t" << result.get() << endl;
}
int main(int argc, const char *argv[])
{
task_lambda();
task_bind();
return 0;
}