From 847f1785c2b179a140a9656c3c22bdeb5c5ee172 Mon Sep 17 00:00:00 2001 From: Radoslaw Zarzynski Date: Sat, 14 Sep 2019 00:42:53 +0200 Subject: [PATCH] crimson: rework discarding errors in errorator. Signed-off-by: Radoslaw Zarzynski --- src/crimson/common/errorator.h | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/crimson/common/errorator.h b/src/crimson/common/errorator.h index faa714afc94b6..39092e5966a6f 100644 --- a/src/crimson/common/errorator.h +++ b/src/crimson/common/errorator.h @@ -54,6 +54,10 @@ public: exception(const exception&) = default; }; +namespace _impl { + template struct always_false : std::false_type {}; +}; + template class maybe_handle_error_t { const std::type_info& type_info; @@ -95,10 +99,17 @@ public: // call `report_failed_future()` during `operator=()`. std::move(result).get_exception(); - constexpr bool explicitly_discarded = std::is_invocable_r< - struct ignore_marker_t&&, ErrorVisitorT, ErrorT>::value; - if constexpr (!explicitly_discarded) { + using return_t = std::invoke_result_t; + if constexpr (std::is_assignable_v) { result = std::forward(errfunc)(ErrorT::instance); + } else if constexpr (std::is_same_v) { + // void denotes explicit discarding + // execute for the sake a side effects. Typically this boils down + // to throwing an exception by the handler. + std::forward(errfunc)(ErrorT::instance); + } else { + static_assert(_impl::always_false::value, + "return of Error Visitor is not assignable to future"); } } } @@ -108,10 +119,6 @@ public: } }; -namespace _impl { - template struct always_false : std::false_type {}; -}; - template static constexpr auto composer(FuncHead&& head, FuncTail&&... tail) { return [ @@ -356,7 +363,6 @@ struct errorator { static_assert((... || std::is_same_v>), "discarding disallowed ErrorT"); - return ignore_marker_t{}; } }; -- 2.39.5