From 4f042c9bfbb128d80ab485722eed634949ec2e71 Mon Sep 17 00:00:00 2001 From: Radoslaw Zarzynski Date: Thu, 26 Sep 2019 13:43:39 +0200 Subject: [PATCH] crimson: clean-up errorator's error set checks. Signed-off-by: Radoslaw Zarzynski --- src/crimson/common/errorator.h | 72 ++++++++++++++-------------------- 1 file changed, 30 insertions(+), 42 deletions(-) diff --git a/src/crimson/common/errorator.h b/src/crimson/common/errorator.h index f8d8dc61599..8b1d7543c74 100644 --- a/src/crimson/common/errorator.h +++ b/src/crimson/common/errorator.h @@ -288,6 +288,10 @@ struct errorator { static constexpr bool value = (0 + ... + std::is_same_v) == 1; }; + template + struct contains_once> { + static constexpr bool value = (... && contains_once::value); + }; template static constexpr bool contains_once_v = contains_once::value; @@ -329,21 +333,20 @@ struct errorator { ErrorVisitorRetsHeadT, ErrorVisitorRetsTailT...> { private: - using step_errorator = errorator; + using step_errorator = errorator; + // add ErrorVisitorRetsHeadT only if 1) it's an error type and + // 2) isn't already included in the errorator's error set. + // It's enough to negate contains_once_v as any errorator<...> + // type is already guaranteed to be free of duplications. + using next_errorator = std::conditional_t< + is_error_v && + !step_errorator::template contains_once_v, + typename step_errorator::template extend, + step_errorator>; public: - using type = std::conditional_t< - // add ErrorVisitorRetsHeadT only if 1) it's an error type and - // 2) isn't already included in the errorator's error set. - // It's enough to negate contains_once_v as any errorator<...> - // type is already guaranteed to be free of duplications. - is_error_v && - !step_errorator::template contains_once_v, - typename make_errorator, - ErrorVisitorRetsTailT...>::type, - typename make_errorator::type>; + using type = typename make_errorator::type; }; // finish the recursion template @@ -369,9 +372,7 @@ struct errorator { operator ErroratedFuture () && { using dest_errorator_t = \ typename ErroratedFuture::errorator_type; - using this_errorator_t = errorator; - - static_assert(!dest_errorator_t::template is_less_errorated_v, + static_assert(dest_errorator_t::template contains_once_v, "conversion is possible to more-or-eq errorated future!"); return std::move(*this).as_plain_future(); } @@ -410,8 +411,7 @@ struct errorator { : base_t( seastar::make_exception_future( errorator_type::make_exception_ptr(e))) { - // this is `fold expression` of C++17. - static_assert((... || (std::is_same_v)), + static_assert(errorator_type::contains_once_v, "ErrorT is not enlisted in errorator"); } @@ -513,8 +513,7 @@ struct errorator { template static auto make_plain_exception_future(ErrorT&& e) noexcept { - using decayed_t = std::decay_t; - static_assert((... || std::is_same_v), + static_assert(contains_once_v>, "passing further disallowed ErrorT"); return ::seastar::make_exception_future( make_exception_ptr(std::forward(e))); @@ -524,8 +523,7 @@ struct errorator { struct pass_further { template decltype(auto) operator()(ErrorT&& e) { - using decayed_t = std::decay_t; - static_assert((... || std::is_same_v), + static_assert(contains_once_v>, "passing further disallowed ErrorT"); return std::forward(e); } @@ -534,8 +532,7 @@ struct errorator { struct discard_all { template decltype(auto) operator()(ErrorT&&) { - static_assert((... || std::is_same_v>), + static_assert(contains_once_v>, "discarding disallowed ErrorT"); } }; @@ -556,9 +553,6 @@ struct errorator { template using extend = errorator; - template - static constexpr bool is_carried_v = count_v > 0; - // get a new errorator by summing and deduplicating error set of // the errorator `unify<>` is applied on with another errorator // provided as template parameter. @@ -577,7 +571,7 @@ struct errorator { // into head and tail. Mix error set of this errorator with head // of the other one only if it isn't already present in the set. using step_errorator = std::conditional_t< - is_carried_v == false, + contains_once_v == false, errorator, errorator>; using rest_errorator = errorator; @@ -592,20 +586,6 @@ struct errorator { using type = errorator; }; - // comparing errorators - template - struct is_less_errorated { - // NOP. - }; - template - struct is_less_errorated> { - static constexpr bool value = \ - ((!is_carried_v) || ...); - }; - template - static constexpr bool is_less_errorated_v = \ - is_less_errorated::value; - private: template static decltype(auto) plainify(seastar::future&& fut) { @@ -691,6 +671,14 @@ public: template using futurize = ::seastar::futurize; + + // get a new errorator by extending current one with new error + template + using extend = errorator; + + // errorator with empty error set never contains any error + template + static constexpr bool contains_once_v = false; }; // class errorator, <> specialization -- 2.39.5