From e5fb68d2c11005f41800979c48d7afdfd770ed6c Mon Sep 17 00:00:00 2001 From: Michael Fabian 'Xaymar' Dirks Date: Sat, 21 Dec 2019 18:05:32 +0100 Subject: [PATCH] utility: Add any and exact matching for enum class bitmasks --- source/utility.hpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/source/utility.hpp b/source/utility.hpp index 9e2d2a7..8e1d821 100644 --- a/source/utility.hpp +++ b/source/utility.hpp @@ -48,6 +48,20 @@ typename std::enable_if::enable, Enum>::type oper return static_cast(static_cast(lhs) & static_cast(rhs)); } +template +typename std::enable_if::enable, bool>::type any(Enum lhs) +{ + using underlying = typename std::underlying_type::type; + return static_cast(lhs) != static_cast(0); +} + +template +typename std::enable_if::enable, bool>::type exact(Enum lhs, Enum rhs) +{ + using underlying = typename std::underlying_type::type; + return static_cast(lhs) == static_cast(rhs); +} + #define P_ENABLE_BITMASK_OPERATORS(x) \ template<> \ struct enable_bitmask_operators { \