static_assert (std::is_enum_v<EnumType>, \
"JUCE_DECLARE_SCOPED_ENUM_BITWISE_OPERATORS " \
"should only be used with enum types"); \
constexpr auto operator& (EnumType a, EnumType b) \
{ \
using base_type = std::underlying_type<EnumType>::type; \
return static_cast<EnumType> (base_type (a) & base_type (b)); \
} \
constexpr auto operator| (EnumType a, EnumType b) \
{ \
using base_type = std::underlying_type<EnumType>::type; \
return static_cast<EnumType> (base_type (a) | base_type (b)); \
} \
constexpr auto operator~ (EnumType a) \
{ \
using base_type = std::underlying_type<EnumType>::type; \
return static_cast<EnumType> (~base_type (a)); \
} \
constexpr auto& operator|= (EnumType& a, EnumType b) \
{ \
a = (a | b); \
return a; \
} \
constexpr auto& operator&= (EnumType& a, EnumType b) \
{ \
a = (a & b); \
return a; \
}
Macro to enable bitwise operations for scoped enums (enum struct/class).
To use this, add the line JUCE_DECLARE_SCOPED_ENUM_BITWISE_OPERATORS (MyEnum) after your enum declaration at file scope level.
e.g.
enum class MyEnum
{
one = 1 << 0,
two = 1 << 1,
three = 1 << 2
};
MyEnum e = MyEnum::one | MyEnum::two;
bool hasTwo = (e & MyEnum::two) != MyEnum{};
#define JUCE_DECLARE_SCOPED_ENUM_BITWISE_OPERATORS(EnumType)
Macro to enable bitwise operations for scoped enums (enum struct/class).
Definition juce_EnumHelpers.h:64
constexpr EnumType withBitValueCleared(EnumType enumValue, EnumType valueToRemove) noexcept
Definition juce_EnumHelpers.h:111
constexpr bool hasBitValueSet(EnumType enumValue, EnumType valueToLookFor) noexcept
Definition juce_EnumHelpers.h:99