idfxx 1.0.0
Modern C++23 components for ESP-IDF
Loading...
Searching...
No Matches

Type-safe bitfield operations on scoped enums. More...

Namespaces

namespace  idfxx
 

Functions

template<idfxx::flag_enum E>
constexpr idfxx::flags< E > operator| (E a, E b) noexcept
 Combines two enum values into a flags object.
 
template<idfxx::flag_enum E>
constexpr idfxx::flags< E > operator& (E a, E b) noexcept
 Intersects two enum values into a flags object.
 
template<idfxx::flag_enum E>
constexpr idfxx::flags< E > operator^ (E a, E b) noexcept
 Toggles two enum values into a flags object.
 
template<idfxx::flag_enum E>
constexpr idfxx::flags< E > operator~ (E a) noexcept
 Computes the bitwise complement of an enum value.
 

Detailed Description

Type-safe bitfield operations on scoped enums.

Provides the flags<E> template class for type-safe flag combinations with operator overloading. Requires opt-in via enable_flags_operators<E>.

enum class my_flags : uint32_t {
none = 0,
read = 1u << 0,
write = 1u << 1,
exec = 1u << 2,
};
template<>
inline constexpr bool idfxx::enable_flags_operators<my_flags> = true;
auto perms = my_flags::read | my_flags::write;
if (perms.contains(my_flags::write)) { ... }
std::expected< T, std::error_code > result
result type wrapping a value or error code.
Definition error.hpp:120

Function Documentation

◆ operator&()

template<idfxx::flag_enum E>
constexpr idfxx::flags< E > operator& ( a,
b 
)
constexprnoexcept

Intersects two enum values into a flags object.

Parameters
aFirst flag value.
bSecond flag value.
Returns
A flags object containing the intersection.

Definition at line 344 of file flags.hpp.

◆ operator^()

template<idfxx::flag_enum E>
constexpr idfxx::flags< E > operator^ ( a,
b 
)
constexprnoexcept

Toggles two enum values into a flags object.

Parameters
aFirst flag value.
bSecond flag value.
Returns
A flags object with toggled bits.

Definition at line 357 of file flags.hpp.

◆ operator|()

template<idfxx::flag_enum E>
constexpr idfxx::flags< E > operator| ( a,
b 
)
constexprnoexcept

Combines two enum values into a flags object.

Enables natural syntax for combining flag enum values without explicitly constructing flags objects.

Parameters
aFirst flag value.
bSecond flag value.
Returns
A flags object containing both flags.

Definition at line 331 of file flags.hpp.

◆ operator~()

template<idfxx::flag_enum E>
constexpr idfxx::flags< E > operator~ ( a)
constexprnoexcept

Computes the bitwise complement of an enum value.

Parameters
aThe flag value to complement.
Returns
A flags object with all bits inverted.

Definition at line 369 of file flags.hpp.