]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/context/example/callcc/throw.cpp
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / boost / libs / context / example / callcc / throw.cpp
1
2 // Copyright Oliver Kowalke 2016.
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 <exception>
9 #include <iostream>
10 #include <stdexcept>
11 #include <string>
12
13 #include <boost/context/continuation.hpp>
14
15 namespace ctx = boost::context;
16
17 struct my_exception : public std::runtime_error {
18 ctx::continuation c;
19 my_exception( ctx::continuation && c_, std::string const& what) :
20 std::runtime_error{ what },
21 c{ std::move( c_) } {
22 }
23 };
24
25 int main() {
26 ctx::continuation c = ctx::callcc([](ctx::continuation && c) {
27 for (;;) {
28 try {
29 std::cout << "entered" << std::endl;
30 c = c.resume();
31 } catch ( my_exception & ex) {
32 std::cerr << "my_exception: " << ex.what() << std::endl;
33 return std::move( ex.c);
34 }
35 }
36 return std::move( c);
37 });
38 c = c.resume_with(
39 [](ctx::continuation && c){
40 throw my_exception(std::move( c), "abc");
41 return std::move( c);
42 });
43
44 std::cout << "main: done" << std::endl;
45
46 return EXIT_SUCCESS;
47 }