utility: Add any and exact matching for enum class bitmasks

This commit is contained in:
Michael Fabian 'Xaymar' Dirks 2019-12-21 18:05:32 +01:00
parent cbada3e438
commit e5fb68d2c1

View file

@ -48,6 +48,20 @@ typename std::enable_if<enable_bitmask_operators<Enum>::enable, Enum>::type oper
return static_cast<Enum>(static_cast<underlying>(lhs) & static_cast<underlying>(rhs));
}
template<typename Enum>
typename std::enable_if<enable_bitmask_operators<Enum>::enable, bool>::type any(Enum lhs)
{
using underlying = typename std::underlying_type<Enum>::type;
return static_cast<underlying>(lhs) != static_cast<underlying>(0);
}
template<typename Enum>
typename std::enable_if<enable_bitmask_operators<Enum>::enable, bool>::type exact(Enum lhs, Enum rhs)
{
using underlying = typename std::underlying_type<Enum>::type;
return static_cast<underlying>(lhs) == static_cast<underlying>(rhs);
}
#define P_ENABLE_BITMASK_OPERATORS(x) \
template<> \
struct enable_bitmask_operators<x> { \