]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/context/example/v2/throw.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / context / example / v2 / throw.cpp
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 <stdexcept>
10 #include <tuple>
11
12 #include <boost/context/all.hpp>
13
14 struct my_exception {
15 boost::context::execution_context< void > ctx;
16
17 my_exception( boost::context::execution_context< void > && ctx_) :
18 ctx( std::forward< boost::context::execution_context< void > >( ctx_) ) {
19 }
20 };
21
22 boost::context::execution_context<void> f1(boost::context::execution_context<void> ctx) {
23 try {
24 for (;;) {
25 std::cout << "f1()" << std::endl;
26 ctx = ctx();
27 }
28 } catch ( my_exception & e) {
29 std::cout << "f1(): my_exception catched" << std::endl;
30 ctx = std::move( e.ctx);
31 }
32 return ctx;
33 }
34
35 boost::context::execution_context<void> f2(boost::context::execution_context<void> ctx) {
36 throw my_exception( std::move( ctx) );
37 return ctx;
38 }
39
40 int main() {
41 boost::context::execution_context< void > ctx( f1);
42 ctx = ctx();
43 ctx = ctx();
44 ctx = ctx( boost::context::exec_ontop_arg, f2);
45
46 std::cout << "main: done" << std::endl;
47
48 return EXIT_SUCCESS;
49 }