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 <iostream>
9
10#include <boost/context/continuation.hpp>
11
12namespace ctx = boost::context;
13
14class moveable {
15public:
16 int value;
17
18 moveable() :
19 value( -1) {
20 }
21
22 moveable( int v) :
23 value( v) {
24 }
25
26 moveable( moveable && other) {
27 std::swap( a&: value, b&: other.value);
28 }
29
30 moveable & operator=( moveable && other) {
31 if ( this == & other) return * this;
32 value = other.value;
33 other.value = -1;
34 return * this;
35 }
36
37 moveable( moveable const& other) = delete;
38 moveable & operator=( moveable const& other) = delete;
39};
40
41int main() {
42 ctx::continuation c;
43 moveable data{ 1 };
44 c = ctx::callcc( std::allocator_arg, salloc: ctx::fixedsize_stack{},
45 fn: [&data](ctx::continuation && c){
46 std::cout << "entered first time: " << data.value << std::endl;
47 data = std::move( moveable{ 3 });
48 c = c.resume();
49 std::cout << "entered second time: " << data.value << std::endl;
50 data = std::move( moveable{});
51 return std::move( c);
52 });
53 std::cout << "returned first time: " << data.value << std::endl;
54 data.value = 5;
55 c = c.resume();
56 std::cout << "returned second time: " << data.value << std::endl;
57 std::cout << "main: done" << std::endl;
58 return EXIT_SUCCESS;
59}
60

source code of boost/libs/context/example/callcc/jump_mov.cpp