Loading...
Searching...
No Matches
juce_EnumHelpers.h File Reference

## Namespaces

namespace | juce

## Macros

#define | JUCE_DECLARE_SCOPED_ENUM_BITWISE_OPERATORS(EnumType)
| Macro to enable bitwise operations for scoped enums (enum struct/class).

## Functions

template<typename EnumType, std::enable_if_t< std::is_enum_v< EnumType >, int > = 0>
constexpr bool | juce::hasBitValueSet (EnumType enumValue, EnumType valueToLookFor) noexcept
template<typename EnumType, std::enable_if_t< std::is_enum_v< EnumType >, int > = 0>
constexpr EnumType | juce::withBitValueSet (EnumType enumValue, EnumType valueToAdd) noexcept
template<typename EnumType, std::enable_if_t< std::is_enum_v< EnumType >, int > = 0>
constexpr EnumType | juce::withBitValueCleared (EnumType enumValue, EnumType valueToRemove) noexcept

## Macro Definition Documentation

## JUCE_DECLARE_SCOPED_ENUM_BITWISE_OPERATORS

#define JUCE_DECLARE_SCOPED_ENUM_BITWISE_OPERATORS | ( |  | EnumType | ) |

Value:
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
};
JUCE_DECLARE_SCOPED_ENUM_BITWISE_OPERATORS (MyEnum)
MyEnum e = MyEnum::one | MyEnum::two;
bool hasTwo = (e & MyEnum::two) != MyEnum{}; // true
bool hasTwo = hasBitValueSet (e, MyEnum::two); // true
e = withBitValueCleared (e, MyEnum::two);
bool hasTwo = hasBitValueSet (e, MyEnum::two); // false
JUCE_DECLARE_SCOPED_ENUM_BITWISE_OPERATORS
#define JUCE_DECLARE_SCOPED_ENUM_BITWISE_OPERATORS(EnumType)
Macro to enable bitwise operations for scoped enums (enum struct/class).
Definition juce_EnumHelpers.h:64
juce::withBitValueCleared
constexpr EnumType withBitValueCleared(EnumType enumValue, EnumType valueToRemove) noexcept
Definition juce_EnumHelpers.h:111
juce::hasBitValueSet
constexpr bool hasBitValueSet(EnumType enumValue, EnumType valueToLookFor) noexcept
Definition juce_EnumHelpers.h:99

### Purchase

Get JUCE

### Discover

What's New in JUCE Features

### Learn

Documentaion Tutorials Made with JUCE Resources

### Support

JUCE Forum Newsletter Archive

### About

Contact Us JUCE Legal JUCE Licensing FAQ

### Events

Audio Developer Conference
© Raw Material Software Limited