From f1f9d619527d93df0822643ac1f8cfc7444e6aa0 Mon Sep 17 00:00:00 2001 From: Denis Blank Date: Tue, 27 Nov 2018 02:39:41 +0100 Subject: [PATCH] Attempt to remove the plain handler --- include/continuable/continuable-base.hpp | 11 +++---- .../continuable/continuable-primitives.hpp | 8 ++--- include/continuable/detail/core/base.hpp | 32 ++++++++----------- test/playground/test-playground.cpp | 3 -- 4 files changed, 22 insertions(+), 32 deletions(-) diff --git a/include/continuable/continuable-base.hpp b/include/continuable/continuable-base.hpp index 77f3ebd..a628a85 100644 --- a/include/continuable/continuable-base.hpp +++ b/include/continuable/continuable-base.hpp @@ -316,14 +316,14 @@ public: /// \returns Returns a continuable_base with an asynchronous return type /// depending on the previous result type. /// - /// /// \since 2.0.0 template auto fail(T&& callback, E&& executor = detail::types::this_thread_executor_tag{}) && { - return detail::base::chain_continuation( - std::move(*this).finish(), std::forward(callback), + return detail::base::chain_continuation< + detail::base::handle_results::no, detail::base::handle_errors::forward>( + std::move(*this).finish(), + detail::base::strip_exception_arg(std::forward(callback)), std::forward(executor)); } @@ -345,9 +345,8 @@ public: /// \since 2.0.0 template auto fail(continuable_base&& continuation) && { - continuation.freeze(); return std::move(*this).fail( - [continuation = std::move(continuation)](exception_t) mutable { + [continuation = std::move(continuation).freeze()](exception_t) mutable { std::move(continuation).done(); }); } diff --git a/include/continuable/continuable-primitives.hpp b/include/continuable/continuable-primitives.hpp index 1a2976b..ce3b688 100644 --- a/include/continuable/continuable-primitives.hpp +++ b/include/continuable/continuable-primitives.hpp @@ -73,7 +73,7 @@ namespace cti { /// for whether it resolves the callback instantly with its arguments /// without having side effects. /// -/// \since 3.1.0 +/// \since 4.0.0 struct is_ready_arg_t {}; /// Represents the tag type that is used to query the continuation @@ -81,7 +81,7 @@ struct is_ready_arg_t {}; /// without having side effects. /// It's required that the query of is_ready_arg_t returns true. /// -/// \since 3.1.0 +/// \since 4.0.0 struct get_arg_t {}; /// Represents the tag type that is used to disambiguate the @@ -89,7 +89,7 @@ struct get_arg_t {}; /// /// \note see continuable::next for details. /// -/// \since 3.1.0 +/// \since 4.0.0 struct exception_arg_t {}; /// \copydoc exception_arg_t @@ -110,7 +110,7 @@ typedef exception_arg_t dispatch_error_tag; /// A custom error type may be set through /// defining `CONTINUABLE_WITH_CUSTOM_ERROR_TYPE`. /// -/// \since 3.1.0 +/// \since 4.0.0 using exception_t = detail::types::exception_t; /// \copydoc exception_t diff --git a/include/continuable/detail/core/base.hpp b/include/continuable/detail/core/base.hpp index 755c1a9..4fe74e6 100644 --- a/include/continuable/detail/core/base.hpp +++ b/include/continuable/detail/core/base.hpp @@ -387,7 +387,6 @@ enum class handle_results { /// Tells whether we handle the error through the callback enum class handle_errors { no, //< The error is forwarded to the next callable - plain, //< The error is the only argument accepted by the callable forward //< The error is forwarded to the callable while keeping its tag }; /// \endcond @@ -438,24 +437,6 @@ struct error_handler_base { } }; template -struct error_handler_base { - /// The operator which is called when an error occurred - void operator()(exception_arg_t, exception_t exception) && { - constexpr auto result = traits::identify(this)->callback_), - std::move(exception)))>{}; - - auto invoker = decoration::exception_invoker_of(result); - - // Invoke the error handler - on_executor(std::move(static_cast(this)->executor_), - std::move(invoker), - std::move(static_cast(this)->callback_), - std::move(static_cast(this)->next_callback_), - std::move(exception)); - } -}; -template struct error_handler_base { /// The operator which is called when an error occurred void operator()(exception_arg_t, exception_t exception) && { @@ -543,6 +524,7 @@ auto make_callback(Callback&& callback, Executor&& executor, std::forward(next_callback)}; } +// TODO fixate the args /// Once this was a workaround for GCC bug: /// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64095 struct final_callback : util::non_copyable { @@ -605,6 +587,18 @@ next_hint_of(std::integral_constant, return current; } +/// Removes the exception_arg_t from the arguments passed to the given callable +template +auto strip_exception_arg(Callable&& callable) { + return [callable = std::forward(callable)] // + (exception_arg_t, auto&&... args) mutable + -> decltype(util::invoke(std::declval(), // + std::declval()...)) { + return util::invoke(std::move(callable), // + std::forward(args)...); + }; +} + /// Chains a callback together with a continuation and returns a continuation: /// /// For example given: diff --git a/test/playground/test-playground.cpp b/test/playground/test-playground.cpp index 3f4b0eb..ee8d8ac 100644 --- a/test/playground/test-playground.cpp +++ b/test/playground/test-playground.cpp @@ -26,7 +26,4 @@ using namespace cti; int main(int, char**) { // ... - make_exceptional_continuable(exception_t{}).fail([](exception_t) { - // ... - }); }