From 055291fab84b0053d20a6775df8138ec2b93b0ae Mon Sep 17 00:00:00 2001 From: Radoslaw Zarzynski Date: Fri, 20 Sep 2019 21:24:30 +0200 Subject: [PATCH] crimson: deduplicate errorator's error set. Signed-off-by: Radoslaw Zarzynski --- src/crimson/common/errorator.h | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/crimson/common/errorator.h b/src/crimson/common/errorator.h index 927aa20cf6219..1150161603f27 100644 --- a/src/crimson/common/errorator.h +++ b/src/crimson/common/errorator.h @@ -234,6 +234,17 @@ struct errorator { static_assert((... && is_error_v), "errorator expects presence of ::is_error in all error types"); + template + struct contains_once { + static constexpr bool value = + (0 + ... + std::is_same_v) == 1; + }; + template + static constexpr bool contains_once_v = contains_once::value; + + static_assert((... && contains_once_v), + "no error type in errorator can be duplicated"); + template class future : private seastar::future { using base_t = seastar::future; @@ -268,12 +279,21 @@ struct errorator { struct make_errorator, ErrorVisitorRetsHeadT, ErrorVisitorRetsTailT...> { + private: + using step_errorator = errorator; + + public: using type = std::conditional_t< - is_error_v, + // 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, + typename make_errorator::type>; }; // finish the recursion -- 2.39.5