From 9fcca617dfa19be5a033b8cd1555a1eeb87aa86a Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Thu, 3 Feb 2022 19:46:54 -0800 Subject: [PATCH] ircd::util: Complete the closure_bool template tool. --- include/ircd/util/closure.h | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/include/ircd/util/closure.h b/include/ircd/util/closure.h index 24145040a..6c2686451 100644 --- a/include/ircd/util/closure.h +++ b/include/ircd/util/closure.h @@ -57,11 +57,19 @@ template struct ircd::util::closure :F { - using proto_type = bool (A...); - using func_type = F; + using proto_bool_type = bool (A...); + using proto_void_type = void (A...); + + using func_bool_type = F; + using func_void_type = F; template - closure(lambda &&o) noexcept; + closure(lambda &&o, + typename std::enable_if::value, int>::type = 0) noexcept; + + template + closure(lambda &&o, + typename std::enable_if::value, int>::type = 0) noexcept; }; template @@ -70,14 +78,35 @@ template template [[gnu::always_inline]] inline -ircd::util::closure::closure(lambda &&o) +ircd::util::closure::closure(lambda &&o, + typename std::enable_if::value, int>::type) noexcept :F { [o(std::move(o))](A&&... a) { + static_assert + ( + std::is_same(a)...))>() + ); + o(std::forward(a)...); return true; } } {} + +template + class F, + class... A> +template +[[gnu::always_inline]] +inline +ircd::util::closure::closure(lambda &&o, + typename std::enable_if::value, int>::type) +noexcept +:F +{ + std::forward(o) +} +{}