13#ifndef BASE_BITSET_TYPE_HPP
14#define BASE_BITSET_TYPE_HPP
24template <typename Timpl, typename Tvalue_type, typename Tstorage, Tstorage Tmask = std::numeric_limits<Tstorage>::max()>
29 static constexpr Tstorage MASK = Tmask;
32 explicit constexpr BaseBitSet(Tstorage data) : data(data & Tmask) {}
34 constexpr auto operator <=>(
const BaseBitSet &)
const noexcept =
default;
40 inline constexpr Timpl &
Set()
43 return static_cast<Timpl&
>(*this);
51 inline constexpr Timpl &
Set(Tvalue_type value)
53 this->data |= (1ULL << Timpl::DecayValueType(value));
54 return static_cast<Timpl&
>(*this);
62 inline constexpr Timpl &
Set(
const Timpl &other)
64 this->data |= other.data;
65 return static_cast<Timpl&
>(*this);
74 inline constexpr Timpl &
Set(Tvalue_type value,
bool set)
76 return set ? this->Set(value) : this->Reset(value);
84 inline constexpr Timpl &
Reset(Tvalue_type value)
86 this->data &= ~(1ULL << Timpl::DecayValueType(value));
87 return static_cast<Timpl&
>(*this);
95 inline constexpr Timpl &
Reset(
const Timpl &other)
97 this->data &= ~other.data;
98 return static_cast<Timpl&
>(*this);
106 inline constexpr Timpl &
Flip(Tvalue_type value)
108 if (this->Test(value)) {
109 return this->Reset(value);
111 return this->Set(value);
120 inline constexpr Timpl &
Flip(
const Timpl &other)
122 this->data ^= other.data;
123 return static_cast<Timpl&
>(*this);
131 inline constexpr bool Test(Tvalue_type value)
const
133 return (this->data & (1ULL << Timpl::DecayValueType(value))) != 0;
141 inline constexpr bool All(
const Timpl &other)
const
143 return (this->data & other.data) == other.data;
150 inline constexpr bool All()
const
152 return this->data == Tmask;
160 inline constexpr bool Any(
const Timpl &other)
const
162 return (this->data & other.data) != 0;
169 inline constexpr bool Any()
const
171 return this->data != 0;
178 inline constexpr bool None()
const
180 return this->data == 0;
183 inline constexpr Timpl operator |(
const Timpl &other)
const
185 return Timpl{
static_cast<Tstorage
>(this->data | other.data)};
188 inline constexpr Timpl operator &(
const Timpl &other)
const
190 return Timpl{
static_cast<Tstorage
>(this->data & other.data)};
197 inline constexpr Tstorage
base() const noexcept
208 return (this->base() & Tmask) == this->base();
Functions related to bit mathematics.
Base for bit set wrapper.
constexpr Timpl & Set(Tvalue_type value, bool set)
Assign the value-th bit.
constexpr bool All(const Timpl &other) const
Test if all of the values are set.
constexpr Timpl & Flip(const Timpl &other)
Flip values from another bitset.
Tstorage data
Bitmask of values.
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
constexpr Tstorage base() const noexcept
Retrieve the raw value behind this bit set.
constexpr bool None() const
Test if none of the values are set.
constexpr bool Any() const
Test if any of the values are set.
constexpr Timpl & Set(const Timpl &other)
Set values from another bitset.
constexpr bool IsValid() const
Test that the raw value of this bit set is valid.
constexpr Timpl & Reset(const Timpl &other)
Reset values from another bitset.
constexpr Timpl & Flip(Tvalue_type value)
Flip the value-th bit.
Tvalue_type ValueType
Value type of this BaseBitSet.
constexpr Timpl & Set()
Set all bits.
Tstorage BaseType
Storage type of this BaseBitSet, be ConvertibleThroughBase.
constexpr bool Any(const Timpl &other) const
Test if any of the given values are set.
constexpr Timpl & Set(Tvalue_type value)
Set the value-th bit.
constexpr bool All() const
Test if all of the values are set.
constexpr Timpl & Reset(Tvalue_type value)
Reset the value-th bit.
Iterable ensemble of each set bit in a value.