diff --git a/include/continuable/detail/base.hpp b/include/continuable/detail/base.hpp index 17d08af..cfe96ec 100644 --- a/include/continuable/detail/base.hpp +++ b/include/continuable/detail/base.hpp @@ -217,7 +217,7 @@ constexpr auto invoker_of(traits::identity) { /// Returns a sequenced invoker which is able to invoke /// objects where std::get is applicable. -constexpr auto sequenced_unpack_invoker() { +inline auto sequenced_unpack_invoker() { return [](auto&& callback, auto&& next_callback, auto&&... args) { auto result = std::forward(callback)( std::forward(args)...); @@ -286,9 +286,14 @@ void packed_dispatch(Executor&& executor, Invoker&& invoker, std::forward(executor)(std::move(work)); } -template -struct result_proxy { +template +struct result_proxy; + +template +struct result_proxy, Callback, Executor, + NextCallback> { Callback callback_; Executor executor_; NextCallback next_callback_; @@ -316,33 +321,6 @@ struct result_proxy { } }; -/// Invokes a continuation with a given callback. -/// Passes the next callback to the resulting continuable or -/// invokes the next callback directly if possible. -/// -/// For example given: -/// - Continuation: continuation<[](auto&& callback) { callback("hi"); }> -/// - Callback: [](std::string) { } -/// - NextCallback: []() { } -/// -template -void invoke_proxy(hints::signature_hint_tag, - Continuation&& continuation, Callback&& callback, - Executor&& executor, NextCallback&& next_callback) { - - result_proxy, std::decay_t, - std::decay_t, Args...> - proxy{std::forward(callback), std::forward(executor), - std::forward(next_callback)}; - - // Invoke the continuation with a proxy callback. - // The proxy callback is responsible for passing - // the result to the callback as well as decorating it. - attorney::invoke_continuation(std::forward(continuation), - std::move(proxy)); -} - /// Returns the next hint when the callback is invoked with the given hint template constexpr auto next_hint_of(traits::identity /*callback*/, @@ -387,10 +365,27 @@ auto chain_continuation(Continuation&& continuation, Callback&& callback, partial_callable = std::move(partial_callable), executor = std::forward(executor) ](auto&& next_callback) mutable { - invoke_proxy(hint_of(traits::identity_of(continuation)), - std::move(continuation), std::move(partial_callable), - std::move(executor), - std::forward(next_callback)); + + // Invokes a continuation with a given callback. + // Passes the next callback to the resulting continuable or + // invokes the next callback directly if possible. + // + // For example given: + // - Continuation: continuation<[](auto&& callback) { callback("hi"); }> + // - Callback: [](std::string) { } + // - NextCallback: []() { } + using Hint = decltype(hint_of(traits::identity_of(continuation))); + result_proxy, + std::decay_t, + std::decay_t> + proxy{std::move(partial_callable), std::move(executor), + std::forward(next_callback)}; + + // Invoke the continuation with a proxy callback. + // The proxy callback is responsible for passing + // the result to the callback as well as decorating it. + attorney::invoke_continuation(std::forward(continuation), + std::move(proxy)); }, next_hint, ownership_); }