diff --git a/example/Jamfile.v2 b/example/Jamfile.v2 index 5c5599d..1389d61 100644 --- a/example/Jamfile.v2 +++ b/example/Jamfile.v2 @@ -47,3 +47,7 @@ exe parser exe segmented : segmented.cpp ; + +exe chained + : chained.cpp + ; diff --git a/example/chained.cpp b/example/chained.cpp new file mode 100644 index 0000000..aadd9bf --- /dev/null +++ b/example/chained.cpp @@ -0,0 +1,70 @@ + +// 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 +#include + +#include + +template +struct test +{ + using pull_type = typename coroutine::pull_type; + using push_type = typename coroutine::push_type; + + pull_type * child = nullptr; + + void start_child_coroutine() + { + child = new pull_type + ( + [](push_type & yield) + { + std::cout << "2"; + yield(); + std::cout << "2"; + yield(); + std::cout << "2"; + yield(); + std::cout << "2"; + yield(); + std::cout << "2"; + yield(); + std::cout << "2"; + } + ); + } + + pull_type start_parent_coroutine() + { + return pull_type + ( + [this](push_type & yield) + { + std::cout << "1"; + start_child_coroutine(); + yield(); + std::cout << "1"; + } + ); + } + + test() + { + auto parent = start_parent_coroutine(); + while (*child) + { + (*child)(); + } + std::cout << std::endl; + } +}; + + +int main() { + test> t2; + std::cout << "Done" << std::endl; +}