3#if __cplusplus >= 201103L || defined(__cpp_constexpr)
4#define EF_CONSTEXPR constexpr
5#define EF_EXPLICITOP explicit
6#define EF_NOEXCEPT noexcept
7#if __has_cpp_attribute(nodiscard)
8#define EF_NODISCARD [[nodiscard]]
21 template <
typename RESULT_TYPE,
typename ENUM_TYPE>
27 template <
typename ENUM_TYPE,
typename VALUE_TYPE =
unsigned long long>
39 EF_CONSTEXPR
enum_flags() EF_NOEXCEPT : bits(0) {}
41 EF_CONSTEXPR enum_flags& operator=(
const enum_flags&
other) EF_NOEXCEPT { bits =
other.bits;
return *
this; }
44 EF_CONSTEXPR
explicit enum_flags(
value_type value) EF_NOEXCEPT : bits(value) {}
80 EF_CONSTEXPR EF_EXPLICITOP
operator bool()
const EF_NOEXCEPT {
return bits != 0; }
129 EF_CONSTEXPR self_type& operator+=(self_type
flags) EF_NOEXCEPT { bits |=
flags.bits;
return *
this; }
130 EF_CONSTEXPR self_type& operator-=(self_type
flags) EF_NOEXCEPT { bits &=
~flags.bits;
return *
this; }
132 EF_CONSTEXPR
bool operator==(self_type
other)
const EF_NOEXCEPT {
return bits ==
other.bits; }
133 EF_CONSTEXPR
bool operator!=(self_type
other)
const EF_NOEXCEPT {
return bits !=
other.bits; }
135 EF_CONSTEXPR
bool operator<(enum_flags
const&
other)
const EF_NOEXCEPT {
return bits <
other.bits; }
136 EF_CONSTEXPR
bool operator>(enum_flags
const&
other)
const EF_NOEXCEPT {
return bits >
other.bits; }
137 EF_CONSTEXPR
bool operator<=(enum_flags
const&
other)
const EF_NOEXCEPT {
return bits <=
other.bits; }
138 EF_CONSTEXPR
bool operator>=(enum_flags
const&
other)
const EF_NOEXCEPT {
return bits >=
other.bits; }
140 EF_CONSTEXPR
bool empty()
const EF_NOEXCEPT {
return bits == 0; }
141 EF_CONSTEXPR
void clear() EF_NOEXCEPT { bits = 0; }
constexpr auto bit_count
Equal to the number of bits in the type.
Primary namespace for everything in this library.
A (constexpr) value struct that represents a set of bits mapped to an enum (implemented as a bitset)
EF_CONSTEXPR self_type & set_to(self_type other, bool val) EF_NOEXCEPT
Sets the flags in the other set to val
EF_NODISCARD static EF_CONSTEXPR self_type from_bits(value_type val) EF_NOEXCEPT
Creates the enum_flags set from the given underlying bits.
EF_CONSTEXPR self_type & unset(self_type other) EF_NOEXCEPT
Unsets the flags in the other set.
EF_NODISCARD static EF_CONSTEXPR self_type all(enum_type last) EF_NOEXCEPT
Returns a value with all bits set, up to and including the last
EF_NODISCARD EF_CONSTEXPR enum_type to_enum_type() const EF_NOEXCEPT
Returns the underlying value representing this set cast to the enum_type.
EF_NODISCARD static EF_CONSTEXPR self_type all() EF_NOEXCEPT
Returns a value with all bits set (including the ones not in the enum, if any)
EF_CONSTEXPR self_type & unset(enum_type e) EF_NOEXCEPT
Unsets the given flag.
EF_CONSTEXPR self_type & toggle(self_type other) EF_NOEXCEPT
Toggles the flags in the other set.
EF_NODISCARD EF_CONSTEXPR bool are_all_set(self_type other) const EF_NOEXCEPT
Returns whether or not all of the flags in the other set are set.
EF_CONSTEXPR self_type & set(enum_type e) EF_NOEXCEPT
Sets the given flag.
EF_NODISCARD EF_CONSTEXPR bool contain(enum_type flag) const EF_NOEXCEPT
Same as is_set.
EF_NODISCARD EF_CONSTEXPR bool are_any_set() const EF_NOEXCEPT
Returns whether or not any of the given flags are set.
EF_NODISCARD EF_CONSTEXPR bool are_any_set(self_type other) const EF_NOEXCEPT
Returns whether or not any of the flags in the other set are set.
EF_NODISCARD EF_CONSTEXPR self_type intersected_with(self_type flags) const EF_NOEXCEPT
Returns a value with our bits from only the flags that are also set in flags (an intersection)
EF_CONSTEXPR self_type & set_to(enum_type e, bool val) EF_NOEXCEPT
Sets the given flags to val
EF_NODISCARD EF_CONSTEXPR self_type but_only(self_type flags) const EF_NOEXCEPT
Returns a value with our bits from only the flags that are also set in flags (an intersection)
ENUM_TYPE enum_type
Type of the enum that is the source of the flags.
EF_CONSTEXPR self_type & set(self_type other) EF_NOEXCEPT
Sets the flags in the other
EF_NODISCARD EF_CONSTEXPR bool is_set(enum_type flag) const EF_NOEXCEPT
Returns whether or not flag is set.
EF_CONSTEXPR self_type & toggle(enum_type e) EF_NOEXCEPT
Toggles the given flag.
EF_NODISCARD static EF_CONSTEXPR self_type none() EF_NOEXCEPT
Returns a value with none of the bits set.
VALUE_TYPE value_type
The underlying integral value type that holds the bits representing the flags.
EF_NODISCARD EF_CONSTEXPR bool contains(enum_type flag) const EF_NOEXCEPT
Same as is_set.