summaryrefslogtreecommitdiff
path: root/libs/context/example/execution_context/parameter.cpp
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@baserock.org>2015-04-08 03:09:47 +0000
committer <>2015-05-05 14:37:32 +0000
commitf2541bb90af059680aa7036f315f052175999355 (patch)
treea5b214744b256f07e1dc2bd7273035a7808c659f /libs/context/example/execution_context/parameter.cpp
parented232fdd34968697a68783b3195b1da4226915b5 (diff)
downloadboost-tarball-master.tar.gz
Imported from /home/lorry/working-area/delta_boost-tarball/boost_1_58_0.tar.bz2.HEADboost_1_58_0master
Diffstat (limited to 'libs/context/example/execution_context/parameter.cpp')
-rw-r--r--libs/context/example/execution_context/parameter.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/libs/context/example/execution_context/parameter.cpp b/libs/context/example/execution_context/parameter.cpp
new file mode 100644
index 000000000..c33de7382
--- /dev/null
+++ b/libs/context/example/execution_context/parameter.cpp
@@ -0,0 +1,55 @@
+
+// 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 <string>
+
+#include <boost/context/all.hpp>
+#include <boost/lexical_cast.hpp>
+
+class X{
+private:
+ int * inp_;
+ std::string outp_;
+ std::exception_ptr excptr_;
+ boost::context::execution_context caller_;
+ boost::context::execution_context callee_;
+
+public:
+ X():
+ inp_( nullptr),
+ outp_(),
+ excptr_(),
+ caller_(boost::context::execution_context::current()),
+ callee_(boost::context::fixedsize_stack(),
+ [=](){
+ try {
+ int i = * inp_;
+ outp_ = boost::lexical_cast<std::string>(i);
+ caller_.resume();
+ } catch (...) {
+ excptr_=std::current_exception();
+ }
+ })
+ {}
+
+ std::string operator()(int i){
+ inp_ = & i;
+ callee_.resume();
+ if(excptr_){
+ std::rethrow_exception(excptr_);
+ }
+ return outp_;
+ }
+};
+
+int main() {
+ X x;
+ std::cout<<x(7)<<std::endl;
+ std::cout << "done" << std::endl;
+}