14template <
typename enum_type>
15constexpr std::underlying_type_t<enum_type>
to_underlying(enum_type e) {
return static_cast<std::underlying_type_t<enum_type>
>(e); }
18template <
typename enum_type>
20 static constexpr bool value =
false;
23template <
typename enum_type>
27template <
typename enum_type, std::enable_if_t<is_enum_incrementable_v<enum_type>,
bool> = true>
35template <
typename enum_type, std::enable_if_t<is_enum_incrementable_v<enum_type>,
bool> = true>
44template <
typename enum_type, std::enable_if_t<is_enum_incrementable_v<enum_type>,
bool> = true>
52template <
typename enum_type, std::enable_if_t<is_enum_incrementable_v<enum_type>,
bool> = true>
61#define DECLARE_INCREMENT_DECREMENT_OPERATORS(enum_type) \
62 template <> struct is_enum_incrementable<enum_type> { \
63 static const bool value = true; \
68#define DECLARE_ENUM_AS_BIT_SET(enum_type) \
69 inline constexpr enum_type operator | (enum_type m1, enum_type m2) { return static_cast<enum_type>(to_underlying(m1) | to_underlying(m2)); } \
70 inline constexpr enum_type operator & (enum_type m1, enum_type m2) { return static_cast<enum_type>(to_underlying(m1) & to_underlying(m2)); } \
71 inline constexpr enum_type operator ^ (enum_type m1, enum_type m2) { return static_cast<enum_type>(to_underlying(m1) ^ to_underlying(m2)); } \
72 inline constexpr enum_type& operator |= (enum_type& m1, enum_type m2) { m1 = m1 | m2; return m1; } \
73 inline constexpr enum_type& operator &= (enum_type& m1, enum_type m2) { m1 = m1 & m2; return m1; } \
74 inline constexpr enum_type& operator ^= (enum_type& m1, enum_type m2) { m1 = m1 ^ m2; return m1; } \
75 inline constexpr enum_type operator ~(enum_type m) { return static_cast<enum_type>(~to_underlying(m)); }
78#define DECLARE_ENUM_AS_ADDABLE(EnumType) \
79 template <typename OtherEnumType, typename = typename std::enable_if<std::is_enum_v<OtherEnumType>, OtherEnumType>::type> \
80 constexpr OtherEnumType operator + (OtherEnumType m1, EnumType m2) { \
81 return static_cast<OtherEnumType>(to_underlying(m1) + to_underlying(m2)); \
90template <
typename T,
class =
typename std::enable_if_t<std::is_enum_v<T>>>
91debug_inline
constexpr bool HasFlag(
const T x,
const T y)
101template <
typename T,
class =
typename std::enable_if_t<std::is_enum_v<T>>>
117template <
typename Tenum,
typename Tstorage>
133 for (
const Tenum &value : values) {
138 constexpr auto operator <=>(
const EnumBitSet &)
const noexcept =
default;
169 if (this->
Test(value)) {
170 return this->
Reset(value);
172 return this->
Set(value);
181 inline constexpr bool Test(Tenum value)
const
203 return (this->
data & other.
data) != 0;
220 inline constexpr Tstorage
base() const noexcept
Tstorage BaseType
Storage type of this EnumBitSet, be ConvertibleThroughBase.
constexpr EnumBitSet(std::initializer_list< const Tenum > values)
Construct an EnumBitSet from a list of enum values.
constexpr bool All(const EnumBitSet &other) const
Test if all of the enum values are set.
constexpr Tstorage base() const noexcept
Retrieve the raw value behind this EnumBitSet.
constexpr EnumBitSet & Set(Tenum value)
Set the enum value.
constexpr bool Any(const EnumBitSet &other) const
Test if any of the enum values are set.
Tenum EnumType
Enum type of this EnumBitSet.
Tstorage data
Bitmask of enum values.
constexpr EnumBitSet & Flip(Tenum value)
Flip the enum value.
constexpr EnumBitSet & Reset(Tenum value)
Reset the enum value to not set.
constexpr bool Test(Tenum value) const
Test if the enum value is set.
constexpr enum_type & operator--(enum_type &e)
Prefix decrement.
debug_inline constexpr void ToggleFlag(T &x, const T y)
Toggle a value in a bitset enum.
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23)
constexpr enum_type & operator++(enum_type &e)
Prefix increment.
debug_inline constexpr bool HasFlag(const T x, const T y)
Checks if a value in a bitset enum is set.
Trait to enable prefix/postfix incrementing operators.