Templa 0.0.1-alpha
C++ Metaprogramming Utilities
Loading...
Searching...
No Matches
templa::FlagEnum< ENUM > Struct Template Reference

A utility wrapper for using scoped or unscoped enum types as bit flags. More...

#include <flagnum.hpp>

Public Types

using underlying_t = typename std::underlying_type<ENUM>::type
 The underlying integral type used for bitwise operations.

Public Member Functions

 FlagEnum ()
 Default constructor. Initializes with no flags set.
 FlagEnum (ENUM single_flag)
 Constructs from a single enum flag.
 FlagEnum (const FlagEnum &o)
 Copy constructor.
 ~FlagEnum ()=default
 Default destructor.
constexpr FlagEnumoperator|= (ENUM addValue)
 Bitwise OR assignment with an enum value.
constexpr FlagEnumoperator&= (ENUM maskValue)
 Bitwise AND assignment with an enum value.
constexpr bool operator== (ENUM maskValue) const noexcept
 Equality comparison with an enum value.
 operator bool () const noexcept
 Boolean conversion operator.

Public Attributes

underlying_t mask = 0x000
 Bitmask storing the combined flag state.

Detailed Description

template<typename ENUM>
struct templa::FlagEnum< ENUM >

A utility wrapper for using scoped or unscoped enum types as bit flags.

Provides a type-safe way to combine, test, and manipulate enum flags using bitwise operations.

Template Parameters
ENUMThe enumeration type. Must satisfy std::is_enum.
Note
The enum values are implicitly cast to their underlying integral type.

Member Function Documentation

◆ operator bool()

template<typename ENUM>
templa::FlagEnum< ENUM >::operator bool ( ) const
inlineexplicitnoexcept

Boolean conversion operator.

Returns
True if any flag is set; false otherwise.

◆ operator&=()

template<typename ENUM>
FlagEnum & templa::FlagEnum< ENUM >::operator&= ( ENUM maskValue)
inlineconstexpr

Bitwise AND assignment with an enum value.

Parameters
maskValueEnum value to AND with.
Returns
Reference to this object.

◆ operator==()

template<typename ENUM>
bool templa::FlagEnum< ENUM >::operator== ( ENUM maskValue) const
inlineconstexprnoexcept

Equality comparison with an enum value.

Parameters
maskValueEnum value to test against.
Returns
True if all bits in maskValue are set in the current mask.

◆ operator|=()

template<typename ENUM>
FlagEnum & templa::FlagEnum< ENUM >::operator|= ( ENUM addValue)
inlineconstexpr

Bitwise OR assignment with an enum value.

Parameters
addValueEnum value to OR into the mask.
Returns
Reference to this object.

The documentation for this struct was generated from the following file: