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)); + } };