]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | |
2 | // Copyright Oliver Kowalke 2014. | |
3 | // Distributed under the Boost Software License, Version 1.0. | |
4 | // (See accompanying file LICENSE_1_0.txt or copy at | |
5 | // http://www.boost.org/LICENSE_1_0.txt) | |
6 | ||
7 | #include <cstdlib> | |
8 | #include <iostream> | |
9 | #include <tuple> | |
10 | ||
11 | #include <boost/context/all.hpp> | |
12 | ||
13 | namespace ctx = boost::context; | |
14 | ||
15 | ctx::execution_context< int > f1( ctx::execution_context< int > ctx, int data) { | |
16 | std::cout << "f1: entered first time: " << data << std::endl; | |
17 | std::tie( ctx, data) = ctx( data + 1); | |
18 | std::cout << "f1: entered second time: " << data << std::endl; | |
19 | std::tie( ctx, data) = ctx( data + 1); | |
20 | std::cout << "f1: entered third time: " << data << std::endl; | |
21 | return ctx; | |
22 | } | |
23 | ||
24 | std::tuple< ctx::execution_context< int >, int > f2( ctx::execution_context< int > ctx, int data) { | |
25 | std::cout << "f2: entered: " << data << std::endl; | |
26 | return std::make_tuple( std::move( ctx), -1); | |
27 | } | |
28 | ||
29 | int main() { | |
30 | int data = 0; | |
31 | ctx::execution_context< int > ctx( f1); | |
32 | std::tie( ctx, data) = ctx( data + 1); | |
33 | std::cout << "f1: returned first time: " << data << std::endl; | |
34 | std::tie( ctx, data) = ctx( data + 1); | |
35 | std::cout << "f1: returned second time: " << data << std::endl; | |
36 | std::tie( ctx, data) = ctx( ctx::exec_ontop_arg, f2, data + 1); | |
37 | std::cout << "f1: returned third time" << std::endl; | |
38 | ||
39 | std::cout << "main: done" << std::endl; | |
40 | ||
41 | return EXIT_SUCCESS; | |
42 | } |