From 52d5aa3dd307aea4b05bed128f2ce29b783aae77 Mon Sep 17 00:00:00 2001 From: tomershafir Date: Sun, 29 Sep 2024 22:13:37 +0300 Subject: [PATCH] sharded.hh: migrate to concepts Migrates static_assert calls on invoke variants to idiomatic C++20 concept requirements. Requirements are duplicated on proxy functions for improved readability, loose coupling and faster failures. --- include/seastar/core/sharded.hh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/include/seastar/core/sharded.hh b/include/seastar/core/sharded.hh index 578b2cfee2..06705c7523 100644 --- a/include/seastar/core/sharded.hh +++ b/include/seastar/core/sharded.hh @@ -292,6 +292,7 @@ public: /// \return Future that becomes ready once all calls have completed template requires std::invocable...> + && std::is_same_v...>>, future<>> future<> invoke_on_all(smp_submit_to_options options, Func func, Args... args) noexcept; /// Invoke a function on all instances of `Service`. @@ -301,6 +302,7 @@ public: /// \ref smp::submit_to() called behind the scenes. template requires std::invocable...> + && std::is_same_v...>>, future<>> future<> invoke_on_all(Func func, Args... args) noexcept { try { return invoke_on_all(smp_submit_to_options{}, std::move(func), std::move(args)...); @@ -321,6 +323,7 @@ public: /// processed the message. template requires std::invocable + && std::is_same_v>, future<>> future<> invoke_on_others(smp_submit_to_options options, Func func, Args... args) noexcept; /// Invoke a callable on all instances of \c Service except the instance @@ -336,6 +339,7 @@ public: /// \ref smp::submit_to() called behind the scenes. template requires std::invocable + && std::is_same_v>, future<>> future<> invoke_on_others(Func func, Args... args) noexcept { try { return invoke_on_others(smp_submit_to_options{}, std::move(func), std::move(args)...); @@ -797,11 +801,10 @@ sharded::invoke_on_all(smp_submit_to_options options, std::function template requires std::invocable...> + && std::is_same_v...>>, future<>> inline future<> sharded::invoke_on_all(smp_submit_to_options options, Func func, Args... args) noexcept { - static_assert(std::is_same_v...>>, future<>>, - "invoke_on_all()'s func must return void or future<>"); try { return invoke_on_all(options, invoke_on_multiple_func_type([func = std::move(func), args = std::tuple(std::move(args)...)] (Service& service) mutable { return std::apply([&service, &func] (Args&&... args) mutable { @@ -816,11 +819,10 @@ sharded::invoke_on_all(smp_submit_to_options options, Func func, Args.. template template requires std::invocable + && std::is_same_v>, future<>> inline future<> sharded::invoke_on_others(smp_submit_to_options options, Func func, Args... args) noexcept { - static_assert(std::is_same_v>, future<>>, - "invoke_on_others()'s func must return void or future<>"); try { return invoke_on_all(options, [orig = this_shard_id(), func = std::move(func), args = std::tuple(std::move(args)...)] (Service& s) mutable -> future<> { return this_shard_id() == orig ? make_ready_future<>() : futurize_apply(func, std::tuple_cat(std::forward_as_tuple(s), args));;