0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-29 07:18:20 +02:00

ircd::util: Complete the closure_bool template tool.

This commit is contained in:
Jason Volk 2022-02-03 19:46:54 -08:00
parent 0b2b243c71
commit 9fcca617df

View file

@ -57,11 +57,19 @@ template<template<class, class...>
struct ircd::util::closure<F, bool, A...>
:F<bool (A...)>
{
using proto_type = bool (A...);
using func_type = F<proto_type>;
using proto_bool_type = bool (A...);
using proto_void_type = void (A...);
using func_bool_type = F<proto_bool_type>;
using func_void_type = F<proto_void_type>;
template<class lambda>
closure(lambda &&o) noexcept;
closure(lambda &&o,
typename std::enable_if<!std::is_constructible<func_bool_type, lambda>::value, int>::type = 0) noexcept;
template<class lambda>
closure(lambda &&o,
typename std::enable_if<std::is_constructible<func_bool_type, lambda>::value, int>::type = 0) noexcept;
};
template<template<class, class...>
@ -70,14 +78,35 @@ template<template<class, class...>
template<class lambda>
[[gnu::always_inline]]
inline
ircd::util::closure<F, bool, A...>::closure(lambda &&o)
ircd::util::closure<F, bool, A...>::closure(lambda &&o,
typename std::enable_if<!std::is_constructible<func_bool_type, lambda>::value, int>::type)
noexcept
:F<bool (A...)>
{
[o(std::move(o))](A&&... a)
{
static_assert
(
std::is_same<void, decltype(o(std::forward<A>(a)...))>()
);
o(std::forward<A>(a)...);
return true;
}
}
{}
template<template<class, class...>
class F,
class... A>
template<class lambda>
[[gnu::always_inline]]
inline
ircd::util::closure<F, bool, A...>::closure(lambda &&o,
typename std::enable_if<std::is_constructible<func_bool_type, lambda>::value, int>::type)
noexcept
:F<bool (A...)>
{
std::forward<lambda>(o)
}
{}