1 | #include <iostream>
|
---|
2 | #include <memory>
|
---|
3 | #include <boost/version.hpp>
|
---|
4 | #include <boost/noncopyable.hpp>
|
---|
5 | #include <boost/coroutine2/coroutine.hpp>
|
---|
6 |
|
---|
7 | using namespace std;
|
---|
8 |
|
---|
9 | class Task : private boost::noncopyable
|
---|
10 | {
|
---|
11 | private:
|
---|
12 | typedef boost::coroutines2::coroutine<void> Coro;
|
---|
13 | typedef Coro::pull_type CoroPull;
|
---|
14 | typedef Coro::push_type CoroPush;
|
---|
15 |
|
---|
16 | public:
|
---|
17 | CoroPull * m_yield;
|
---|
18 | CoroPush m_coro;
|
---|
19 | Task(std::function<void(void)> const & entryPoint)
|
---|
20 | : m_yield(nullptr),
|
---|
21 | m_coro([this, entryPoint] (CoroPull & myYield)
|
---|
22 | {
|
---|
23 | m_yield = &myYield;
|
---|
24 | entryPoint();
|
---|
25 | })
|
---|
26 | {}
|
---|
27 | };
|
---|
28 |
|
---|
29 | void printer(void)
|
---|
30 | {
|
---|
31 | cout << "hello" << endl;
|
---|
32 | }
|
---|
33 |
|
---|
34 | int main(void)
|
---|
35 | {
|
---|
36 | Task mytask(&printer);
|
---|
37 | mytask.m_coro();
|
---|
38 |
|
---|
39 | return 0;
|
---|
40 | }
|
---|