2
0
mirror of https://github.com/boostorg/context.git synced 2026-01-21 04:42:43 +00:00
Files
context/example/callcc/jump_mov.cpp
2017-01-05 18:59:02 +01:00

64 lines
1.6 KiB
C++

// Copyright Oliver Kowalke 2016.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include <cstdlib>
#include <iostream>
#include <boost/context/continuation.hpp>
namespace ctx = boost::context;
class moveable {
public:
bool state;
int value;
moveable() :
state( false),
value( -1) {
}
moveable( int v) :
state( true),
value( v) {
}
moveable( moveable && other) :
state( other.state),
value( other.value) {
other.state = false;
other.value = -1;
}
moveable & operator=( moveable && other) {
if ( this == & other) return * this;
state = other.state;
value = other.value;
other.state = false;
other.value = -1;
return * this;
}
moveable( moveable const& other) = delete;
moveable & operator=( moveable const& other) = delete;
};
ctx::continuation f1( ctx::continuation && c) {
moveable data = ctx::transfer_data< moveable >( c);
c = ctx::resume( std::move( c), std::move( data) );
return std::move( c);
}
int main() {
ctx::continuation c;
moveable data1{ 3 };
c = ctx::callcc( std::allocator_arg, ctx::fixedsize_stack{}, f1, std::move( data1) );
moveable data2;
data2 = ctx::transfer_data< moveable >( c);
std::cout << "main: done" << std::endl;
return EXIT_SUCCESS;
}