ontop.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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 <tuple>
  8. #include <boost/context/continuation.hpp>
  9. namespace ctx = boost::context;
  10. int main() {
  11. int data = 0;
  12. ctx::continuation c = ctx::callcc( [&data](ctx::continuation && c) {
  13. std::cout << "f1: entered first time: " << data << std::endl;
  14. data += 1;
  15. c = c.resume();
  16. std::cout << "f1: entered second time: " << data << std::endl;
  17. data += 1;
  18. c = c.resume();
  19. std::cout << "f1: entered third time: " << data << std::endl;
  20. return std::move( c);
  21. });
  22. std::cout << "f1: returned first time: " << data << std::endl;
  23. data += 1;
  24. c = c.resume();
  25. std::cout << "f1: returned second time: " << data << std::endl;
  26. data += 1;
  27. c = c.resume_with( [&data](ctx::continuation && c){
  28. std::cout << "f2: entered: " << data << std::endl;
  29. data = -1;
  30. return std::move( c);
  31. });
  32. std::cout << "f1: returned third time" << std::endl;
  33. std::cout << "main: done" << std::endl;
  34. return EXIT_SUCCESS;
  35. }