2
0
mirror of https://github.com/boostorg/context.git synced 2026-01-23 17:32:16 +00:00
Files
context/example/v2/parameter.cpp
Oliver Kowalke 68a57f29b3 rename captued_context to execution_context
- split into execution_context v2 (previous captured_context)
  and execution_context v1
- v1 enabled if segmented-stacks=on at b2 commandline
2016-02-06 12:18:38 +01:00

61 lines
1.6 KiB
C++

// Copyright Oliver Kowalke 2014.
// 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 <exception>
#include <iostream>
#include <memory>
#include <string>
#include <boost/context/all.hpp>
#include <boost/lexical_cast.hpp>
namespace ctx = boost::context;
class X{
private:
std::exception_ptr excptr_;
ctx::execution_context ctx_;
public:
X():
excptr_(),
ctx_(
[=](ctx::execution_context ctx, void * vp){
try {
for (;;) {
int i = * static_cast< int * >( vp);
std::string str = boost::lexical_cast<std::string>(i);
auto result = ctx( & str);
ctx = std::move( std::get<0>( result) );
vp = std::get<1>( result);
}
} catch ( ctx::detail::forced_unwind const&) {
throw;
} catch (...) {
excptr_=std::current_exception();
}
return ctx;
})
{}
std::string operator()(int i){
auto result = ctx_( & i);
ctx_ = std::move( std::get<0>( result) );
void * ret = std::get<1>( result);
if(excptr_){
std::rethrow_exception(excptr_);
}
return * static_cast< std::string * >( ret);
}
};
int main() {
X x;
std::cout<<x(7)<<std::endl;
std::cout << "done" << std::endl;
}