Template Class flags

Class Documentation

template<class Enum, class EnumUnderlyingType = int32_t>
class util::flags

A helper for storing an OR-combination of enum values.

tparam Enum

the used enum

tparam EnumUnderlyingType

the enum’s underlying type, 32-bit integer by default

Public Functions

explicit flags(Enum value)

Constructs a flags object initialized with the given enum value.

flags(std::initializer_list<Enum> values)

Constructs a flags object initialized with the flags from the initializer_list OR’d together.

flags() = default
~flags() = default
flags(flags &&other) noexcept = default
flags(const flags &other) = default
auto operator=(flags &&other) noexcept -> flags& = default
auto operator=(const flags &other) -> flags& = default
explicit operator EnumUnderlyingType() const

Casts to the underlying type of this enum.

Can be used if the value needs to be supplied to library functions or else.


explicit operator bool() const noexcept

Returns true if the flag is set to a value or false if not.


auto operator!() const noexcept -> bool

Returns true if the flag is not set to a value or false if it is.


auto flip(Enum value) noexcept -> flags&

Flips a given flag value.


void reset() noexcept

Resets all flag values.


void reset(Enum value) noexcept

Resets the given flag value.


auto set(Enum value, bool on = true) noexcept -> flags&

Toggles or untoggles a given flag value.


auto test(Enum value) const noexcept -> bool

Returns true if the given enum flag value is set or not.