From 1b8e93d4875044c12331f5e4b29ce858367a5aa2 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sat, 25 Nov 2017 12:30:33 -0700 Subject: [PATCH] ircd::util: Consolidate a few typographical constexprs here. --- include/ircd/util.h | 69 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) diff --git a/include/ircd/util.h b/include/ircd/util.h index becebde2a..721643a0a 100644 --- a/include/ircd/util.h +++ b/include/ircd/util.h @@ -1260,12 +1260,79 @@ struct unlock_guard }; +template +constexpr bool +is_bool() +{ + using type = typename std::remove_reference::type; + return std::is_same::value; +} + +template +constexpr bool +is_number() +{ + using type = typename std::remove_reference::type; + return std::is_arithmetic::value; +} + +template +constexpr bool +is_floating() +{ + using type = typename std::remove_reference::type; + return is_number() && std::is_floating_point(); +} + +template +constexpr bool +is_integer() +{ + return is_number() && !is_floating(); +} + struct is_zero { - bool operator()(const size_t &value) const + template + typename std::enable_if + < + is_bool(), + bool>::type + test(const bool &value) + const + { + return !value; + } + + template + typename std::enable_if + < + is_integer() && + !is_bool(), + bool>::type + test(const size_t &value) + const { return value == 0; } + + template + typename std::enable_if + < + is_floating(), + bool>::type + test(const double &value) + const + { + return !(value > 0.0 || value < 0.0); + } + + template + bool operator()(T&& t) + const + { + return test(std::forward(t)); + } };