From: Kefu Chai Date: Tue, 22 Nov 2022 12:22:54 +0000 (+0800) Subject: crimson/common: use concept for type constraints X-Git-Tag: v18.1.0~837^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=ca7dc80ea060a14a23d7a4ade59f99657e67483b;p=ceph-ci.git crimson/common: use concept for type constraints instead of using SFINAE, use concept for specifying the type constraints for better readability. Signed-off-by: Kefu Chai --- diff --git a/src/crimson/common/errorator.h b/src/crimson/common/errorator.h index d9fae76120a..b11fc30bc30 100644 --- a/src/crimson/common/errorator.h +++ b/src/crimson/common/errorator.h @@ -649,7 +649,7 @@ private: _future finally(FuncT &&func) { return this->then_wrapped( [func = std::forward(func)](auto &&result) mutable noexcept { - if constexpr (seastar::is_future>::value) { + if constexpr (seastar::InvokeReturnsAnyFuture) { return ::seastar::futurize_invoke(std::forward(func)).then_wrapped( [result = std::move(result)](auto&& f_res) mutable { // TODO: f_res.failed() diff --git a/src/crimson/common/interruptible_future.h b/src/crimson/common/interruptible_future.h index 299f1285046..00d77fbf334 100644 --- a/src/crimson/common/interruptible_future.h +++ b/src/crimson/common/interruptible_future.h @@ -142,6 +142,11 @@ struct is_interruptible_future< InterruptCond, FutureType>> : public std::true_type {}; +template +concept IsInterruptibleFuture = is_interruptible_future::value; +template +concept InvokeReturnsInterruptibleFuture = + IsInterruptibleFuture>; namespace internal { @@ -196,14 +201,13 @@ auto call_with_interruption_impl( } -template , - std::enable_if_t && - seastar::is_future::value, int> = 0> +template +requires (!InterruptCond::template is_interruption_v) auto call_with_interruption( InterruptCondRef interrupt_condition, Func&& func, Ret&& fut) { + using Result = std::invoke_result_t; // if "T" is already an interrupt exception, return it directly; // otherwise, upper layer application may encounter errors executing // the "Func" body. @@ -224,13 +228,13 @@ auto call_with_interruption( std::move(fut)); } -template , - std::enable_if_t, int> = 0> +template +requires (InterruptCond::template is_interruption_v) auto call_with_interruption( InterruptCondRef interrupt_condition, Func&& func, T&& arg) { + using Result = std::invoke_result_t; // if "T" is already an interrupt exception, return it directly; // otherwise, upper layer application may encounter errors executing // the "Func" body. @@ -238,11 +242,8 @@ auto call_with_interruption( std::get<0>(std::tuple(std::forward(arg)))); } -template , - std::enable_if_t< - !InterruptCond::template is_interruption_v && - !seastar::is_future::value, int> = 0> +template +requires (!InterruptCond::template is_interruption_v) && (!seastar::Future) auto call_with_interruption( InterruptCondRef interrupt_condition, Func&& func, T&& arg) @@ -309,7 +310,7 @@ struct interruptible_errorator; template struct parallel_for_each_ret { - static_assert(seastar::is_future::value); + static_assert(seastar::Future); using type = seastar::future<>; }; @@ -323,7 +324,7 @@ struct parallel_for_each_ret< template class parallel_for_each_state final : private seastar::continuation_base<> { using elem_ret_t = std::conditional_t< - is_interruptible_future::value, + IsInterruptibleFuture, typename FutureType::core_type, FutureType>; using future_t = interruptible_future_detail< @@ -1157,12 +1158,12 @@ public: }; } - template , - std::enable_if_t::value, int> = 0> + template AsyncAction> [[gnu::always_inline]] static auto do_for_each(Iterator begin, Iterator end, AsyncAction&& action) { - if constexpr (seastar::is_future::value) { + using Result = std::invoke_result_t; + if constexpr (seastar::Future) { return make_interruptible( ::seastar::do_for_each(begin, end, [action=std::move(action), @@ -1189,12 +1190,11 @@ public: } } - template , - std::enable_if_t::value, int> = 0> + template + requires (!InvokeReturnsInterruptibleFuture) [[gnu::always_inline]] static auto do_for_each(Iterator begin, Iterator end, AsyncAction&& action) { - if constexpr (seastar::is_future::value) { + if constexpr (seastar::InvokeReturnsAnyFuture) { return make_interruptible( ::seastar::do_for_each(begin, end, [action=std::move(action), @@ -1221,12 +1221,11 @@ public: } } - template , - std::enable_if_t::value, int> = 0> + template [[gnu::always_inline]] static auto repeat(AsyncAction&& action) { - if constexpr (seastar::is_future::value) { + using Result = std::invoke_result_t; + if constexpr (seastar::Future) { return make_interruptible( ::seastar::repeat( [action=std::move(action), @@ -1248,13 +1247,11 @@ public: ); } } - template , - std::enable_if_t< - !is_interruptible_future::value, int> = 0> + template + requires (!InvokeReturnsInterruptibleFuture) [[gnu::always_inline]] static auto repeat(AsyncAction&& action) { - if constexpr (seastar::is_future::value) { + if constexpr (seastar::InvokeReturnsAnyFuture) { return make_interruptible( ::seastar::repeat( [action=std::move(action), @@ -1362,18 +1359,14 @@ public: std::move(initial), std::move(reduce)); } - template::value - || is_interruptible_future::value, int> = 0> + template + requires seastar::Future || IsInterruptibleFuture static auto futurize_invoke_if_func(Fut&& fut) noexcept { return std::forward(fut); } - template::value - && !is_interruptible_future::value, int> = 0> + template + requires (!seastar::Future) && (!IsInterruptibleFuture) static auto futurize_invoke_if_func(Func&& func) noexcept { return seastar::futurize_invoke(std::forward(func)); }