From 01399ebfd296fb3d08284078070c0d798ee56c7e Mon Sep 17 00:00:00 2001 From: Samuel Just Date: Fri, 17 Jan 2020 12:56:46 -0800 Subject: [PATCH] common/crimson/errorator: add universal pass_further_all, discard_all, all_same_way In many cases, we simply want to add catch-all handling. Signed-off-by: Samuel Just --- src/crimson/common/errorator.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/crimson/common/errorator.h b/src/crimson/common/errorator.h index d9ae99913df4f..3750b67360a50 100644 --- a/src/crimson/common/errorator.h +++ b/src/crimson/common/errorator.h @@ -872,6 +872,31 @@ namespace ct_error { ct_error_code; using not_connected = ct_error_code; using timed_out = ct_error_code; + + struct pass_further_all { + template + decltype(auto) operator()(ErrorT&& e) { + return std::forward(e); + } + }; + + struct discard_all { + template + decltype(auto) operator()(ErrorT&&) { + } + }; + + template + static decltype(auto) all_same_way(ErrorFunc&& error_func) { + return [ + error_func = std::forward(error_func) + ] (auto&& e) mutable -> decltype(auto) { + using decayed_t = std::decay_t; + auto&& handler = + decayed_t::error_t::handle(std::forward(error_func)); + return std::invoke(std::move(handler), std::forward(e)); + }; + }; } using stateful_errc = stateful_error_t; -- 2.39.5