From 043e38601fe0ecd5a8ff8b5040ea5e9c7eaeae97 Mon Sep 17 00:00:00 2001 From: q66 Date: Fri, 17 Mar 2017 01:14:56 +0100 Subject: [PATCH] instantiate yielder at point of func call --- ostd/coroutine.hh | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/ostd/coroutine.hh b/ostd/coroutine.hh index ff4863e..8fbdcb2 100644 --- a/ostd/coroutine.hh +++ b/ostd/coroutine.hh @@ -145,10 +145,11 @@ namespace detail { return std::forward(coro_rtype::get(p_result)); } - void call_helper(Y &&yielder) { - std::apply([this, yielder = std::move(yielder)](auto ...args) { + template + void call_helper(C &coro) { + std::apply([this, &coro](auto ...args) { coro_rtype::store(p_result, std::forward(p_func( - std::move(yielder), std::forward(*args)... + Y{coro}, std::forward(*args)... ))); }, p_args); } @@ -180,9 +181,10 @@ namespace detail { return std::forward(coro_rtype::get(p_result)); } - void call_helper(Y &&yielder) { + template + void call_helper(C &coro) { coro_rtype::store( - p_result, std::forward(p_func(std::move(yielder))) + p_result, std::forward(p_func(Y{coro})) ); } @@ -210,9 +212,10 @@ namespace detail { void get_result() {} - void call_helper(Y &&yielder) { - std::apply([this, yielder = std::move(yielder)](auto ...args) { - p_func(std::move(yielder), std::forward(*args)...); + template + void call_helper(C &coro) { + std::apply([this, &coro](auto ...args) { + p_func(Y{coro}, std::forward(*args)...); }, p_args); } @@ -237,8 +240,9 @@ namespace detail { void get_result() {} - void call_helper(Y &&yielder) { - p_func(std::move(yielder)); + template + void call_helper(C &coro) { + p_func(Y{coro}); } void swap(coro_stor &other) { @@ -387,7 +391,7 @@ public: private: void resume_call() { - p_stor.call_helper(yield_type{*this}); + p_stor.call_helper(*this); } detail::coro_stor p_stor;