jump.cpp 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. // Copyright Oliver Kowalke 2016.
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. #include <cstdlib>
  6. #include <iostream>
  7. #include <boost/context/continuation.hpp>
  8. namespace ctx = boost::context;
  9. int main() {
  10. ctx::continuation c;
  11. int data = 1;
  12. c = ctx::callcc(
  13. [&data](ctx::continuation && c){
  14. std::cout << "entered first time: " << data << std::endl;
  15. data += 2;
  16. c = c.resume();
  17. std::cout << "entered second time: " << data << std::endl;
  18. return std::move( c);
  19. });
  20. std::cout << "returned first time: " << data << std::endl;
  21. data += 2;
  22. c = c.resume();
  23. if ( c) {
  24. std::cout << "returned second time: " << data << std::endl;
  25. } else {
  26. std::cout << "returned second time: execution context terminated" << std::endl;
  27. }
  28. std::cout << "main: done" << std::endl;
  29. return EXIT_SUCCESS;
  30. }