header_utils
Loading...
Searching...
No Matches
ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE > Struct Template Reference

A (constexpr) value struct that represents a set of bits mapped to an enum (implemented as a bitset) More...

#include <enum_flags.h>

Public Types

typedef VALUE_TYPE value_type
 The underlying integral value type that holds the bits representing the flags.
 
typedef ENUM_TYPE enum_type
 Type of the enum that is the source of the flags.
 
typedef enum_flags< ENUM_TYPE, VALUE_TYPE > self_type
 
using value_type = VALUE_TYPE
 The underlying integral value type that holds the bits representing the flags.
 
using enum_type = ENUM
 Type of the enum that is the source of the flags.
 
using self_type = enum_flags
 
using flag_changes = enum_flag_changes< ENUM, VALUE_TYPE >
 

Public Member Functions

EF_CONSTEXPR enum_flags (const enum_flags &other) EF_NOEXCEPT
 
EF_CONSTEXPR enum_flagsoperator= (const enum_flags &other) EF_NOEXCEPT
 
EF_CONSTEXPR enum_flags (enum_type base_value) EF_NOEXCEPT
 
EF_CONSTEXPR enum_flags (value_type value) EF_NOEXCEPT
 
EF_NODISCARD EF_CONSTEXPR bool is_set (enum_type flag) const EF_NOEXCEPT
 Returns whether or not flag is set.
 
EF_NODISCARD EF_CONSTEXPR bool contain (enum_type flag) const EF_NOEXCEPT
 Same as is_set.
 
EF_NODISCARD EF_CONSTEXPR bool contains (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 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 EF_EXPLICITOP operator bool () const EF_NOEXCEPT
 
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_CONSTEXPR self_typeset (enum_type e) EF_NOEXCEPT
 Sets the given flag.
 
EF_CONSTEXPR self_typeset (self_type other) EF_NOEXCEPT
 Sets the flags in the other
 
EF_CONSTEXPR self_typeunset (enum_type e) EF_NOEXCEPT
 Unsets the given flag.
 
EF_CONSTEXPR self_typeunset (self_type other) EF_NOEXCEPT
 Unsets the flags in the other set.
 
EF_CONSTEXPR self_typetoggle (enum_type e) EF_NOEXCEPT
 Toggles the given flag.
 
EF_CONSTEXPR self_typetoggle (self_type other) EF_NOEXCEPT
 Toggles the flags in the other set.
 
EF_CONSTEXPR self_typeset_to (enum_type e, bool val) EF_NOEXCEPT
 Sets the given flags to val
 
EF_CONSTEXPR self_typeset_to (self_type other, bool val) EF_NOEXCEPT
 Sets the flags in the other set 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)
 
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_NODISCARD EF_CONSTEXPR self_type operator+ (enum_type flag) const EF_NOEXCEPT
 
EF_NODISCARD EF_CONSTEXPR self_type operator- (enum_type flag) const EF_NOEXCEPT
 
EF_NODISCARD EF_CONSTEXPR self_type operator+ (self_type flags) const EF_NOEXCEPT
 
EF_NODISCARD EF_CONSTEXPR self_type operator- (self_type flags) const EF_NOEXCEPT
 
EF_CONSTEXPR bool operator== (self_type other) const EF_NOEXCEPT
 
EF_CONSTEXPR bool operator< (enum_flags const &other) const EF_NOEXCEPT
 
EF_CONSTEXPR bool operator> (enum_flags const &other) const EF_NOEXCEPT
 
EF_CONSTEXPR bool empty () const EF_NOEXCEPT
 
EF_CONSTEXPR void clear () EF_NOEXCEPT
 
constexpr enum_flags (const enum_flags &) noexcept=default
 
constexpr enum_flags (enum_flags &&) noexcept=default
 
constexpr enum_flagsoperator= (const enum_flags &) noexcept=default
 
constexpr enum_flagsoperator= (enum_flags &&) noexcept=default
 
constexpr enum_flags (enum_type base_value) noexcept
 
constexpr enum_flags (value_type value) noexcept
 
template<typename... ARGS>
constexpr enum_flags (enum_type base_value, ARGS... args) noexcept
 Constructs the value with all the given flags set.
 
constexpr enum_flags (all_flags_t) noexcept
 
constexpr enum_flags (no_flags_t) noexcept
 
constexpr bool is_set (enum_type flag) const noexcept
 Returns whether or not flag is set.
 
constexpr bool contain (enum_type flag) const noexcept
 Same as is_set.
 
constexpr bool contains (enum_type flag) const noexcept
 Same as is_set.
 
constexpr int count () const noexcept
 Returns the number of flags set.
 
constexpr ENUM nth_set (size_t n) const noexcept
 Returns the value of the nth set bit in the set.
 
constexpr ENUM first_set () const noexcept
 Returns the lowest numerical value in the set. Returns an unspecified value if no values are in the set.
 
template<typename T , typename... ARGS>
constexpr bool contains_any_of (T arg, ARGS... args) const noexcept
 Returns whether or not any of the given flags are set.
 
constexpr bool are_any_set () const noexcept
 Returns whether or not any of the given flags are set.
 
constexpr bool full () const noexcept
 Returns whether *this == all()
 
constexpr bool contains_any_of (self_type other) const noexcept
 Returns whether or not any of the flags in the other set are set.
 
template<typename... ARGS>
constexpr bool contains_all_of (ARGS... args) const noexcept
 Returns whether or not all of the given flags are set.
 
constexpr bool contains_all_of (self_type other) const noexcept
 Returns whether or not all of the flags in the other set are set.
 
constexpr operator bool () const noexcept
 
constexpr enum_type to_enum_type () const noexcept
 Returns the underlying value representing this set cast to the enum_type.
 
template<std::convertible_to< ENUM >... ARGS>
constexpr self_typeset (ARGS... args) noexcept
 Sets the given flags.
 
constexpr self_typeset (self_type other) noexcept
 Sets the flags in the other
 
template<std::convertible_to< ENUM >... ARGS>
constexpr self_typeunset (ARGS... args) noexcept
 TODO: insert() as an alias for set()
 
constexpr self_typeunset (self_type other) noexcept
 Unsets the flags in the other set.
 
template<std::convertible_to< ENUM >... ARGS>
constexpr self_typetoggle (ARGS... args) noexcept
 TODO: erase() as an alias for unset()
 
constexpr self_typetoggle (self_type other) noexcept
 Toggles the flags in the other set.
 
template<std::convertible_to< ENUM >... ARGS>
constexpr self_typeset_to (bool val, ARGS... args) noexcept
 Sets the given flags to val
 
constexpr self_typeset_to (bool val, self_type other) noexcept
 Sets the flags in the other set to val
 
constexpr self_type but_only (self_type flags) const noexcept
 Returns a value with our bits from only the flags that are also set in flags (an intersection)
 
constexpr self_type intersected_with (self_type flags) const noexcept
 Returns a value with our bits from only the flags that are also set in flags (an intersection)
 
constexpr self_type operator+ (enum_type flag) const noexcept
 
constexpr self_type operator- (enum_type flag) const noexcept
 
constexpr self_type operator+ (self_type flags) const noexcept
 
constexpr self_type operator- (self_type flags) const noexcept
 
constexpr self_type except_for (self_type flags) const noexcept
 
constexpr self_type without (self_type flags) const noexcept
 
template<std::convertible_to< ENUM >... ARGS>
constexpr self_type except_for (ARGS... args) const noexcept
 
template<std::convertible_to< ENUM >... ARGS>
constexpr self_type without (ARGS... args) const noexcept
 
iterator begin () const noexcept
 
iterator end () const noexcept
 
iterator cbegin () const noexcept
 
iterator cend () const noexcept
 
constexpr bool empty () const noexcept
 
constexpr void clear () noexcept
 
template<typename FUNC >
constexpr auto for_each (FUNC &&callback) const
 Calls callback for each enum flag in the set.
 
constexpr void apply (flag_changes changes) noexcept
 
constexpr self_type operator+ (flag_changes changes) const noexcept
 

Static Public Member Functions

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_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_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 static EF_CONSTEXPR self_type none () EF_NOEXCEPT
 Returns a value with none of the bits set.
 
static constexpr self_type from_bits (value_type val) noexcept
 Creates the enum_flags set from the given underlying bits.
 
static constexpr self_type all () noexcept
 Returns a value with all bits set (including the ones not in the enum, if any)
 
static constexpr self_type all (enum_type last) noexcept
 Returns a value with all bits set, up to and including the last
 
static constexpr self_type none () noexcept
 Returns a value with none of the bits set.
 

Public Attributes

value_type bits
 

Detailed Description

template<typename ENUM_TYPE, typename VALUE_TYPE = unsigned long long>
struct ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >

A (constexpr) value struct that represents a set of bits mapped to an enum (implemented as a bitset)

Example
enum class door_flags { closed, locked, blue };
flags.set(door_flags::closed, door_flags::blue);
if (flags.is_set(door_flags::locked)) { ... }
if (flags.contains_all_of(door_flags::closed, door_flags::locked)) { print("Not getting in"); }
flags.toggle(door_flags::locked);
for (auto flag : flags)
print("{} is set", flag);
constexpr auto bit_count
Equal to the number of bits in the type.
Definition bits.h:33
A (constexpr) value struct that represents a set of bits mapped to an enum (implemented as a bitset)
Definition enum_flags.h:29
EF_CONSTEXPR self_type & set(enum_type e) EF_NOEXCEPT
Sets the given flag.
Definition enum_flags.h:86
  • Supports +/-/+=/-=/==/!= (decided not to support &/|/^/~ to not confuse the model and implementation).
  • Is as constexpr as I could make it
  • You can specify the base integral value to store bits in (uint64_t by default)
  • Uses concepts to ensure most functions do not overflow or produce garbage results (e.g. enum values of -5 or 100 won't work with uint64_t)
  • The first template parameter doesn't have to be an enum, any integral value will work
  • It is also a range
Attention
The members of this class will only work correctly if the enum values you give are greater than 0 and lesser than the bit-width of the VALUE_TYPE
Template Parameters
ENUMthe type containing the value flags the set will hold
VALUE_TYPEthe underlying integral value that stores the bits representing the flags

Definition at line 28 of file enum_flags.h.

Member Typedef Documentation

◆ enum_type [1/2]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
typedef ENUM_TYPE ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::enum_type

Type of the enum that is the source of the flags.

Definition at line 34 of file enum_flags.h.

◆ enum_type [2/2]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
using ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::enum_type = ENUM

Type of the enum that is the source of the flags.

Definition at line 56 of file enum_flags.h.

◆ flag_changes

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
using ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::flag_changes = enum_flag_changes<ENUM, VALUE_TYPE>

Definition at line 306 of file enum_flags.h.

◆ self_type [1/2]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
typedef enum_flags<ENUM_TYPE, VALUE_TYPE> ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::self_type

Definition at line 35 of file enum_flags.h.

◆ self_type [2/2]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
using ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::self_type = enum_flags

Definition at line 57 of file enum_flags.h.

◆ value_type [1/2]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
typedef VALUE_TYPE ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::value_type

The underlying integral value type that holds the bits representing the flags.

Definition at line 31 of file enum_flags.h.

◆ value_type [2/2]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
using ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::value_type = VALUE_TYPE

The underlying integral value type that holds the bits representing the flags.

Definition at line 53 of file enum_flags.h.

Constructor & Destructor Documentation

◆ enum_flags() [1/9]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
EF_CONSTEXPR ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::enum_flags ( )
inline

Definition at line 39 of file enum_flags.h.

◆ enum_flags() [2/9]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
EF_CONSTEXPR ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::enum_flags ( const enum_flags< ENUM_TYPE, VALUE_TYPE > &  other)
inline

Definition at line 40 of file enum_flags.h.

◆ enum_flags() [3/9]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
EF_CONSTEXPR ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::enum_flags ( enum_type  base_value)
inline

Definition at line 43 of file enum_flags.h.

◆ enum_flags() [4/9]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
EF_CONSTEXPR ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::enum_flags ( value_type  value)
inlineexplicit

Definition at line 44 of file enum_flags.h.

◆ enum_flags() [5/9]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
constexpr ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::enum_flags ( enum_type  base_value)
inlineconstexprnoexcept

Definition at line 67 of file enum_flags.h.

◆ enum_flags() [6/9]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
constexpr ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::enum_flags ( value_type  value)
inlineexplicitconstexprnoexcept

Definition at line 68 of file enum_flags.h.

◆ enum_flags() [7/9]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
template<typename... ARGS>
constexpr ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::enum_flags ( enum_type  base_value,
ARGS...  args 
)
inlineconstexprnoexcept

Constructs the value with all the given flags set.

Definition at line 72 of file enum_flags.h.

◆ enum_flags() [8/9]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
constexpr ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::enum_flags ( all_flags_t  )
inlineconstexprnoexcept

Definition at line 86 of file enum_flags.h.

◆ enum_flags() [9/9]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
constexpr ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::enum_flags ( no_flags_t  )
inlineconstexprnoexcept

Definition at line 96 of file enum_flags.h.

Member Function Documentation

◆ all() [1/4]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
EF_NODISCARD static EF_CONSTEXPR self_type ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::all ( )
inlinestatic

Returns a value with all bits set (including the ones not in the enum, if any)

Definition at line 54 of file enum_flags.h.

◆ all() [2/4]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
static constexpr self_type ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::all ( )
inlinestaticconstexprnoexcept

Returns a value with all bits set (including the ones not in the enum, if any)

Definition at line 84 of file enum_flags.h.

◆ all() [3/4]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
EF_NODISCARD static EF_CONSTEXPR self_type ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::all ( enum_type  last)
inlinestatic

Returns a value with all bits set, up to and including the last

Definition at line 57 of file enum_flags.h.

◆ all() [4/4]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
static constexpr self_type ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::all ( enum_type  last)
inlinestaticconstexprnoexcept

Returns a value with all bits set, up to and including the last

Definition at line 90 of file enum_flags.h.

◆ apply()

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
constexpr void ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::apply ( flag_changes  changes)
inlineconstexprnoexcept

Definition at line 308 of file enum_flags.h.

◆ are_all_set()

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
EF_NODISCARD EF_CONSTEXPR bool ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::are_all_set ( self_type  other) const
inline

Returns whether or not all of the flags in the other set are set.

Definition at line 78 of file enum_flags.h.

◆ are_any_set() [1/3]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
EF_NODISCARD EF_CONSTEXPR bool ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::are_any_set ( ) const
inline

Returns whether or not any of the given flags are set.

Definition at line 71 of file enum_flags.h.

◆ are_any_set() [2/3]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
constexpr bool ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::are_any_set ( ) const
inlineconstexprnoexcept

Returns whether or not any of the given flags are set.

Definition at line 135 of file enum_flags.h.

◆ are_any_set() [3/3]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
EF_NODISCARD EF_CONSTEXPR bool ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::are_any_set ( self_type  other) const
inline

Returns whether or not any of the flags in the other set are set.

Note
are_any_set({}) is true, which is correct or not, depending on whether you want it to be correct or not :P

Definition at line 75 of file enum_flags.h.

◆ begin()

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
iterator ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::begin ( ) const
inlinenoexcept

Definition at line 269 of file enum_flags.h.

◆ but_only() [1/2]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
EF_NODISCARD EF_CONSTEXPR self_type ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::but_only ( self_type  flags) const
inline

Returns a value with our bits from only the flags that are also set in flags (an intersection)

Definition at line 115 of file enum_flags.h.

◆ but_only() [2/2]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
constexpr self_type ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::but_only ( self_type  flags) const
inlineconstexprnoexcept

Returns a value with our bits from only the flags that are also set in flags (an intersection)

Definition at line 203 of file enum_flags.h.

◆ cbegin()

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
iterator ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::cbegin ( ) const
inlinenoexcept

Definition at line 271 of file enum_flags.h.

◆ cend()

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
iterator ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::cend ( ) const
inlinenoexcept

Definition at line 272 of file enum_flags.h.

◆ clear() [1/2]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
EF_CONSTEXPR void ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::clear ( )
inline

Definition at line 141 of file enum_flags.h.

◆ clear() [2/2]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
constexpr void ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::clear ( )
inlineconstexprnoexcept

Definition at line 275 of file enum_flags.h.

◆ contain() [1/2]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
EF_NODISCARD EF_CONSTEXPR bool ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::contain ( enum_type  flag) const
inline

Same as is_set.

Definition at line 66 of file enum_flags.h.

◆ contain() [2/2]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
constexpr bool ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::contain ( enum_type  flag) const
inlineconstexprnoexcept

Same as is_set.

Definition at line 104 of file enum_flags.h.

◆ contains() [1/2]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
EF_NODISCARD EF_CONSTEXPR bool ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::contains ( enum_type  flag) const
inline

Same as is_set.

Definition at line 68 of file enum_flags.h.

◆ contains() [2/2]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
constexpr bool ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::contains ( enum_type  flag) const
inlineconstexprnoexcept

Same as is_set.

Definition at line 107 of file enum_flags.h.

◆ contains_all_of() [1/2]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
template<typename... ARGS>
constexpr bool ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::contains_all_of ( ARGS...  args) const
inlineconstexprnoexcept

Returns whether or not all of the given flags are set.

Definition at line 149 of file enum_flags.h.

◆ contains_all_of() [2/2]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
constexpr bool ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::contains_all_of ( self_type  other) const
inlineconstexprnoexcept

Returns whether or not all of the flags in the other set are set.

Definition at line 156 of file enum_flags.h.

◆ contains_any_of() [1/2]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
constexpr bool ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::contains_any_of ( self_type  other) const
inlineconstexprnoexcept

Returns whether or not any of the flags in the other set are set.

Note
contains_any_of({}) is true, which is correct or not, depending on whether you want it to be correct or not :P

Definition at line 144 of file enum_flags.h.

◆ contains_any_of() [2/2]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
template<typename T , typename... ARGS>
constexpr bool ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::contains_any_of ( arg,
ARGS...  args 
) const
inlineconstexprnoexcept

Returns whether or not any of the given flags are set.

Definition at line 128 of file enum_flags.h.

◆ count()

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
constexpr int ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::count ( ) const
inlineconstexprnoexcept

Returns the number of flags set.

Definition at line 111 of file enum_flags.h.

◆ empty() [1/2]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
EF_CONSTEXPR bool ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::empty ( ) const
inline

Definition at line 140 of file enum_flags.h.

◆ empty() [2/2]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
constexpr bool ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::empty ( ) const
inlineconstexprnoexcept

Definition at line 274 of file enum_flags.h.

◆ end()

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
iterator ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::end ( ) const
inlinenoexcept

Definition at line 270 of file enum_flags.h.

◆ except_for() [1/2]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
template<std::convertible_to< ENUM >... ARGS>
constexpr self_type ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::except_for ( ARGS...  args) const
inlineconstexprnoexcept

Definition at line 224 of file enum_flags.h.

◆ except_for() [2/2]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
constexpr self_type ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::except_for ( self_type  flags) const
inlineconstexprnoexcept

Definition at line 219 of file enum_flags.h.

◆ first_set()

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
constexpr ENUM ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::first_set ( ) const
inlineconstexprnoexcept

Returns the lowest numerical value in the set. Returns an unspecified value if no values are in the set.

Definition at line 123 of file enum_flags.h.

◆ for_each()

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
template<typename FUNC >
constexpr auto ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::for_each ( FUNC &&  callback) const
inlineconstexpr

Calls callback for each enum flag in the set.

Parameters
callbackThe function to call. It can return something convertible bool, and if it does, the iteration will stop when the function returns something true
Returns
void, or the value returned by the callback if it returned something true, or the value-initialized return type

TODO: See if this would be faster with a simple loop

Definition at line 284 of file enum_flags.h.

◆ from_bits() [1/2]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
EF_NODISCARD static EF_CONSTEXPR self_type ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::from_bits ( value_type  val)
inlinestatic

Creates the enum_flags set from the given underlying bits.

Definition at line 47 of file enum_flags.h.

◆ from_bits() [2/2]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
static constexpr self_type ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::from_bits ( value_type  val)
inlinestaticconstexprnoexcept

Creates the enum_flags set from the given underlying bits.

Definition at line 76 of file enum_flags.h.

◆ full()

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
constexpr bool ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::full ( ) const
inlineconstexprnoexcept

Returns whether *this == all()

Definition at line 139 of file enum_flags.h.

◆ intersected_with() [1/2]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
EF_NODISCARD EF_CONSTEXPR self_type ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::intersected_with ( self_type  flags) const
inline

Returns a value with our bits from only the flags that are also set in flags (an intersection)

Definition at line 118 of file enum_flags.h.

◆ intersected_with() [2/2]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
constexpr self_type ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::intersected_with ( self_type  flags) const
inlineconstexprnoexcept

Returns a value with our bits from only the flags that are also set in flags (an intersection)

Definition at line 207 of file enum_flags.h.

◆ is_set() [1/2]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
EF_NODISCARD EF_CONSTEXPR bool ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::is_set ( enum_type  flag) const
inline

Returns whether or not flag is set.

Definition at line 63 of file enum_flags.h.

◆ is_set() [2/2]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
constexpr bool ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::is_set ( enum_type  flag) const
inlineconstexprnoexcept

Returns whether or not flag is set.

Definition at line 100 of file enum_flags.h.

◆ none() [1/2]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
EF_NODISCARD static EF_CONSTEXPR self_type ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::none ( )
inlinestatic

Returns a value with none of the bits set.

Definition at line 60 of file enum_flags.h.

◆ none() [2/2]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
static constexpr self_type ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::none ( )
inlinestaticconstexprnoexcept

Returns a value with none of the bits set.

Definition at line 94 of file enum_flags.h.

◆ nth_set()

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
constexpr ENUM ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::nth_set ( size_t  n) const
inlineconstexprnoexcept

Returns the value of the nth set bit in the set.

Definition at line 115 of file enum_flags.h.

◆ operator bool() [1/2]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
EF_CONSTEXPR EF_EXPLICITOP ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::operator bool ( ) const
inline

Definition at line 80 of file enum_flags.h.

◆ operator bool() [2/2]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
constexpr ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::operator bool ( ) const
inlineexplicitconstexprnoexcept

Definition at line 158 of file enum_flags.h.

◆ operator+() [1/5]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
EF_NODISCARD EF_CONSTEXPR self_type ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::operator+ ( enum_type  flag) const
inline

Definition at line 120 of file enum_flags.h.

◆ operator+() [2/5]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
constexpr self_type ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::operator+ ( enum_type  flag) const
inlineconstexprnoexcept

Definition at line 210 of file enum_flags.h.

◆ operator+() [3/5]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
constexpr self_type ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::operator+ ( flag_changes  changes) const
inlineconstexprnoexcept

Definition at line 322 of file enum_flags.h.

◆ operator+() [4/5]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
EF_NODISCARD EF_CONSTEXPR self_type ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::operator+ ( self_type  flags) const
inline

Definition at line 123 of file enum_flags.h.

◆ operator+() [5/5]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
constexpr self_type ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::operator+ ( self_type  flags) const
inlineconstexprnoexcept

Definition at line 215 of file enum_flags.h.

◆ operator-() [1/4]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
EF_NODISCARD EF_CONSTEXPR self_type ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::operator- ( enum_type  flag) const
inline

Definition at line 121 of file enum_flags.h.

◆ operator-() [2/4]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
constexpr self_type ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::operator- ( enum_type  flag) const
inlineconstexprnoexcept

Definition at line 212 of file enum_flags.h.

◆ operator-() [3/4]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
EF_NODISCARD EF_CONSTEXPR self_type ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::operator- ( self_type  flags) const
inline

Definition at line 124 of file enum_flags.h.

◆ operator-() [4/4]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
constexpr self_type ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::operator- ( self_type  flags) const
inlineconstexprnoexcept

Definition at line 217 of file enum_flags.h.

◆ operator<()

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
EF_CONSTEXPR bool ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::operator< ( enum_flags< ENUM_TYPE, VALUE_TYPE > const other) const
inline

Definition at line 135 of file enum_flags.h.

◆ operator=()

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
EF_CONSTEXPR enum_flags & ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::operator= ( const enum_flags< ENUM_TYPE, VALUE_TYPE > &  other)
inline

Definition at line 41 of file enum_flags.h.

◆ operator==()

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
EF_CONSTEXPR bool ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::operator== ( self_type  other) const
inline

Definition at line 132 of file enum_flags.h.

◆ operator>()

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
EF_CONSTEXPR bool ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::operator> ( enum_flags< ENUM_TYPE, VALUE_TYPE > const other) const
inline

Definition at line 136 of file enum_flags.h.

◆ set() [1/4]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
template<std::convertible_to< ENUM >... ARGS>
constexpr self_type & ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::set ( ARGS...  args)
inlineconstexprnoexcept

Sets the given flags.

Definition at line 166 of file enum_flags.h.

◆ set() [2/4]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
EF_CONSTEXPR self_type & ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::set ( enum_type  e)
inline

Sets the given flag.

Definition at line 86 of file enum_flags.h.

◆ set() [3/4]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
EF_CONSTEXPR self_type & ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::set ( self_type  other)
inline

Sets the flags in the other

Definition at line 88 of file enum_flags.h.

◆ set() [4/4]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
constexpr self_type & ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::set ( self_type  other)
inlineconstexprnoexcept

Sets the flags in the other

Definition at line 168 of file enum_flags.h.

◆ set_to() [1/4]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
template<std::convertible_to< ENUM >... ARGS>
constexpr self_type & ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::set_to ( bool  val,
ARGS...  args 
)
inlineconstexprnoexcept

Sets the given flags to val

Definition at line 188 of file enum_flags.h.

◆ set_to() [2/4]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
constexpr self_type & ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::set_to ( bool  val,
self_type  other 
)
inlineconstexprnoexcept

Sets the flags in the other set to val

Definition at line 195 of file enum_flags.h.

◆ set_to() [3/4]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
EF_CONSTEXPR self_type & ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::set_to ( enum_type  e,
bool  val 
)
inline

Sets the given flags to val

Definition at line 101 of file enum_flags.h.

◆ set_to() [4/4]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
EF_CONSTEXPR self_type & ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::set_to ( self_type  other,
bool  val 
)
inline

Sets the flags in the other set to val

Definition at line 108 of file enum_flags.h.

◆ to_enum_type() [1/2]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
EF_NODISCARD EF_CONSTEXPR enum_type ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::to_enum_type ( ) const
inline

Returns the underlying value representing this set cast to the enum_type.

Definition at line 83 of file enum_flags.h.

◆ to_enum_type() [2/2]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
constexpr enum_type ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::to_enum_type ( ) const
inlineconstexprnoexcept

Returns the underlying value representing this set cast to the enum_type.

Definition at line 162 of file enum_flags.h.

◆ toggle() [1/4]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
template<std::convertible_to< ENUM >... ARGS>
constexpr self_type & ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::toggle ( ARGS...  args)
inlineconstexprnoexcept

TODO: erase() as an alias for unset()

Toggles the given flags

Definition at line 182 of file enum_flags.h.

◆ toggle() [2/4]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
EF_CONSTEXPR self_type & ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::toggle ( enum_type  e)
inline

Toggles the given flag.

Definition at line 96 of file enum_flags.h.

◆ toggle() [3/4]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
EF_CONSTEXPR self_type & ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::toggle ( self_type  other)
inline

Toggles the flags in the other set.

Definition at line 98 of file enum_flags.h.

◆ toggle() [4/4]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
constexpr self_type & ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::toggle ( self_type  other)
inlineconstexprnoexcept

Toggles the flags in the other set.

Definition at line 184 of file enum_flags.h.

◆ unset() [1/4]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
template<std::convertible_to< ENUM >... ARGS>
constexpr self_type & ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::unset ( ARGS...  args)
inlineconstexprnoexcept

TODO: insert() as an alias for set()

Unsets the given flags

Definition at line 174 of file enum_flags.h.

◆ unset() [2/4]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
EF_CONSTEXPR self_type & ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::unset ( enum_type  e)
inline

Unsets the given flag.

Definition at line 91 of file enum_flags.h.

◆ unset() [3/4]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
EF_CONSTEXPR self_type & ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::unset ( self_type  other)
inline

Unsets the flags in the other set.

Definition at line 93 of file enum_flags.h.

◆ unset() [4/4]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
constexpr self_type & ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::unset ( self_type  other)
inlineconstexprnoexcept

Unsets the flags in the other set.

Definition at line 176 of file enum_flags.h.

◆ without() [1/2]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
template<std::convertible_to< ENUM >... ARGS>
constexpr self_type ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::without ( ARGS...  args) const
inlineconstexprnoexcept

Definition at line 226 of file enum_flags.h.

◆ without() [2/2]

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
constexpr self_type ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::without ( self_type  flags) const
inlineconstexprnoexcept

Definition at line 221 of file enum_flags.h.

Member Data Documentation

◆ bits

template<typename ENUM_TYPE , typename VALUE_TYPE = unsigned long long>
value_type ghassanpl::enum_flags< ENUM_TYPE, VALUE_TYPE >::bits

Definition at line 37 of file enum_flags.h.