diff --git a/include/ircd/json/tuple.h b/include/ircd/json/tuple.h index 84cd3f966..abd443003 100644 --- a/include/ircd/json/tuple.h +++ b/include/ircd/json/tuple.h @@ -106,13 +106,6 @@ template using tuple_value_type = typename tuple_element::value_type; -template -constexpr size_t -tuple::size() -{ - return std::tuple_size(); -} - template auto & stdcast(const tuple &o) @@ -906,6 +899,13 @@ tuple::tuple(const tuple &t) }); } +template +constexpr size_t +tuple::size() +{ + return std::tuple_size(); +} + template +constexpr bool +is_tuple() +{ + return is_specialization_of::value; +} + +template +constexpr typename std::enable_if(), size_t>::type +size() +{ + return std::tuple_size::value; +} + +template +constexpr size_t +size(const std::tuple &t) +{ + return size>(); +} + // // Iteration of a tuple // @@ -41,8 +62,7 @@ namespace ircd::util template -constexpr -typename std::enable_if>::value, void>::type +constexpr typename std::enable_if>::value, void>::type for_each(std::tuple &t, func&& f) {} @@ -250,8 +270,7 @@ runtil(const std::tuple &t, template -constexpr -typename std::enable_if<(i > 0), bool>::type +constexpr typename std::enable_if<(i > 0), bool>::type runtil(std::tuple &t, func&& f) { @@ -261,8 +280,7 @@ runtil(std::tuple &t, template -constexpr -typename std::enable_if<(i == -1), bool>::type +constexpr typename std::enable_if<(i == -1), bool>::type runtil(const std::tuple &t, func&& f) { @@ -277,8 +295,7 @@ runtil(const std::tuple &t, template -constexpr -typename std::enable_if<(i == -1), bool>::type +constexpr typename std::enable_if<(i == -1), bool>::type runtil(std::tuple &t, func&& f) { @@ -290,6 +307,37 @@ runtil(std::tuple &t, return runtil(t, std::forward(f)); } +// +// test() is a logical inversion of until() for intuitive find()-like +// boolean semantics. +// + +template +constexpr auto +test(std::tuple &t, + func&& f) +{ + return !until(t, [&f](auto&& arg) + { + return !f(arg); + }); +} + +template +constexpr auto +rtest(std::tuple &t, + func&& f) +{ + return !runtil(t, [&f](auto&& arg) + { + return !f(arg); + }); +} + // // Kronecker delta //