Go to the documentation of this file.
9 #ifndef EAGINE_BITFIELD_HPP
10 #define EAGINE_BITFIELD_HPP
18 template <
typename Bit>
25 using value_type = std::make_unsigned_t<std::underlying_type_t<bit_type>>;
28 constexpr
bitfield() noexcept = default;
48 explicit constexpr
operator bool() const noexcept {
54 explicit constexpr
operator value_type() const noexcept {
92 template <
typename... B>
94 -> std::enable_if_t<all_are_same_v<
bit_type, B...>,
bool> {
105 template <
typename... B>
107 -> std::enable_if_t<all_are_same_v<
bit_type, B...>,
bool> {
118 template <
typename... B>
120 -> std::enable_if_t<all_are_same_v<
bit_type, B...>,
bool> {
148 return a._bits == b._bits;
153 return a._bits != b._bits;
204 #endif // EAGINE_BITFIELD_HPP
auto clear(bit_type b) noexcept -> bitfield &
Clears the specified bit.
Definition: bitfield.hpp:186
auto operator|=(bitfield b) noexcept -> bitfield &
Bitwise-or operator.
Definition: bitfield.hpp:163
Common code is placed in this namespace.
Definition: eagine.hpp:21
std::make_unsigned_t< std::underlying_type_t< bit_type > > value_type
The Integral type used to store the bits.
Definition: bitfield.hpp:25
constexpr auto bits() const noexcept -> value_type
Returns the bits in the underlying integer value type.
Definition: bitfield.hpp:59
Class for manipulating and testing a group of enumeration-based bits.
Definition: bitfield.hpp:19
constexpr auto has(bit_type bit) const noexcept
Tests if the specified bit is set.
Definition: bitfield.hpp:70
constexpr auto has_none(bit_type bit, B... bits) const noexcept -> std::enable_if_t< all_are_same_v< bit_type, B... >, bool >
Tests if none of the specified bits are set.
Definition: bitfield.hpp:119
constexpr auto is_empty() const noexcept
Indicates that none of the bits are set.
Definition: bitfield.hpp:42
constexpr bitfield(bit_type _bit) noexcept
Construction from the bit enumeration type value.
Definition: bitfield.hpp:35
constexpr friend auto operator&(bitfield a, bitfield b) noexcept -> bitfield
Bitwise-and operator.
Definition: bitfield.hpp:169
constexpr auto has_any(bit_type bit, B... bits) const noexcept -> std::enable_if_t< all_are_same_v< bit_type, B... >, bool >
Tests if any of the specified bits are set.
Definition: bitfield.hpp:106
constexpr auto has_not(bit_type bit) const noexcept
Tests if the specified bit is not set.
Definition: bitfield.hpp:81
constexpr friend auto operator~(bitfield b) noexcept -> bitfield
Bit inversion operator.
Definition: bitfield.hpp:181
generator_capability bit_type
The enumeration type specifying individual bit values.
Definition: bitfield.hpp:22
constexpr bitfield() noexcept=default
Default constructor.
constexpr auto has_only(bit_type bit) const noexcept
Tests if only the specified bit is set.
Definition: bitfield.hpp:131
constexpr friend auto operator|(bitfield a, bitfield b) noexcept -> bitfield
Bitwise-or operator.
Definition: bitfield.hpp:157
constexpr auto has_at_most(bit_type bit) const noexcept
Tests if at most the specified bit is set (or is empty).
Definition: bitfield.hpp:142
constexpr auto has_all(bit_type bit, B... bits) const noexcept -> std::enable_if_t< all_are_same_v< bit_type, B... >, bool >
Tests if all of the specified bits are set.
Definition: bitfield.hpp:93
auto clear() noexcept -> bitfield &
Clears all bits.
Definition: bitfield.hpp:193
constexpr friend auto operator!=(bitfield a, bitfield b) noexcept
Nonequality comparison.
Definition: bitfield.hpp:152
auto operator&=(bitfield b) noexcept -> bitfield &
Bitwise-and operator.
Definition: bitfield.hpp:175
constexpr friend auto operator==(bitfield a, bitfield b) noexcept
Equality comparison.
Definition: bitfield.hpp:147