From 53fd815b7d74f23f2a90dfbf3839b791cb90f8db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fahller?= Date: Fri, 3 Nov 2023 22:39:36 +0100 Subject: [PATCH] Cleaned up co_yield and co_return handling --- include/trompeloeil.hpp | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/include/trompeloeil.hpp b/include/trompeloeil.hpp index 7885cea6..370f78d0 100644 --- a/include/trompeloeil.hpp +++ b/include/trompeloeil.hpp @@ -3986,7 +3986,10 @@ template static_assert(!is_coroutine || is_void || is_matching_type, "CO_YIELD is incompatible with the promise type"); constexpr auto valid = is_coroutine && !is_void && is_matching_type; - matcher->add_yield_expr(std::bool_constant{}, std::forward(e)); + if constexpr (valid) + { + matcher->add_yield_expr(std::forward(e)); + } return {matcher}; } template @@ -4023,8 +4026,10 @@ template "CO_RETURN for forbidden call does not make sense"); constexpr bool valid = !has_return && !has_co_return && is_coroutine && is_matching_type && !throws && upper_call_limit > 0; - using tag = std::bool_constant; - matcher->set_co_return(tag{}, std::forward(h)); + if constexpr (valid) + { + matcher->set_co_return(std::forward(h)); + } return {matcher}; } #endif @@ -4144,9 +4149,8 @@ template constexpr bool valid = is_coroutine && !throws && !has_return; if constexpr (valid) { - using tag = std::integral_constant; auto handler = co_throw_handler_t(std::forward(h)); - matcher->set_co_return(tag{}, std::move(handler)); + matcher->set_co_return(std::move(handler)); } return {matcher}; } @@ -4561,19 +4565,11 @@ template template void add_yield_expr( - std::true_type, E&& e) { auto expr = new yield_expr(std::forward(e)); yield_expressions->push_back(expr); } - - template - void - add_yield_expr( - std::false_type, - E&& - ); #endif template inline @@ -4598,19 +4594,12 @@ template inline void set_co_return( - std::true_type, T&& h) { using basic_t = typename std::remove_reference::type; using handler = co_return_handler_t; return_handler_obj.reset(new handler(std::forward(h), yield_expressions)); } - - template // Never called. Used to limit errmsg - static // with CO_RETURN of wrong type and after: - void // FORBIDDEN_CALL and others - set_co_return(std::false_type, T&&) - noexcept; #endif condition_list conditions;