Flags

template<IsEnum ENUM>
class Flags

Template for creating a type that can do a bit-wise OR on values defined as enum.

Example:

enum MyFlag : unsigned int { FLAG1 = 0x1, FLAG2 = 0x2, FLAG3 = 0x4 };

using MyFlags = Flags<MyFlag>;

MyFlags flags = FLAG1 | FLAG3;

assert(flags & FLAG1);
assert(flags & FLAG3);

Template Parameters:

ENUM – enum defining the flags

Public Functions

inline constexpr bool has_flags() const noexcept

Test if there are set flags.

Returns:

true if there are any flags set, false otherwise

inline constexpr Flags &operator|=(ENUM rhs) noexcept

Set a flag.

Parameters:

rhs – Flag to set

Returns:

New flags

inline constexpr Flags &operator|=(Flags rhs)

Set flags.

Parameters:

rhsFlags to set

Returns:

New flags

inline constexpr Flags operator|(ENUM rhs) const noexcept

Add a new flag and return the result.

Parameters:

rhs – Flag to add

Returns:

New flags

inline constexpr Flags operator|(Flags rhs) const

Add flags.

Parameters:

rhsFlags to set

Returns:

New flags

inline constexpr bool operator&(ENUM flag) const noexcept

Test if a flag is set.

Parameters:

flag – Flag to test

Returns:

true if the flag flag is set, false otherwise