Ticket #13297: main.cpp

File main.cpp, 775 bytes (added by lars@…, 5 years ago)
Line 
1#include <iostream>
2#include <memory>
3#include <boost/version.hpp>
4#include <boost/noncopyable.hpp>
5#include <boost/coroutine2/coroutine.hpp>
6
7using namespace std;
8
9class Task : private boost::noncopyable
10{
11private:
12 typedef boost::coroutines2::coroutine<void> Coro;
13 typedef Coro::pull_type CoroPull;
14 typedef Coro::push_type CoroPush;
15
16public:
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
29void printer(void)
30{
31 cout << "hello" << endl;
32}
33
34int main(void)
35{
36 Task mytask(&printer);
37 mytask.m_coro();
38
39 return 0;
40}