[ create a new paste ] login | about

Link: http://codepad.org/yRqRfQBI    [ raw code | fork ]

C++, pasted on Sep 18:
template<typename coroutine>
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";
            }
        );
    }

    pull_type start_parent_coroutine()
    {
        return pull_type
        (
            [this](push_type & yield)
            {
                std::cout << "1";
                start_child_coroutine();
                yield(); // comment this to see crash on assert in Boost.Coroutine2
                std::cout << "1";
            }
        );
    }

    test()
    {
        auto parent = start_parent_coroutine();
        (*child)();
        std::cout << std::endl;
    }
};


int main()
{
    std::cout << "When using Boost.Coroutine  result is ";
    test<boost::coroutines::coroutine<void>> t1;
    std::cout << "When using Boost.Coroutine2 result is ";
    test<boost::coroutines2::coroutine<void>> t2;
}


Create a new paste based on this one


Comments: