Type-safe bitfield operations on scoped enums.
More...
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<>
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.
◆ operator&()
Intersects two enum values into a flags object.
- Parameters
-
| a | First flag value. |
| b | Second flag value. |
- Returns
- A flags object containing the intersection.
Definition at line 344 of file flags.hpp.
◆ operator^()
Toggles two enum values into a flags object.
- Parameters
-
| a | First flag value. |
| b | Second flag value. |
- Returns
- A flags object with toggled bits.
Definition at line 357 of file flags.hpp.
◆ operator|()
Combines two enum values into a flags object.
Enables natural syntax for combining flag enum values without explicitly constructing flags objects.
- Parameters
-
| a | First flag value. |
| b | Second flag value. |
- Returns
- A flags object containing both flags.
Definition at line 331 of file flags.hpp.
◆ operator~()
Computes the bitwise complement of an enum value.
- Parameters
-
| a | The flag value to complement. |
- Returns
- A flags object with all bits inverted.
Definition at line 369 of file flags.hpp.