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);
40 inline constexpr Timpl &
Set() {
…}
51 inline constexpr Timpl &
Set(Tvalue_type value)
53 this->data |= (1ULL << Timpl::DecayValueType(value));
54 return static_cast<Timpl&
>(*this);
51 inline constexpr Timpl &
Set(Tvalue_type value) {
…}
62 inline constexpr Timpl &
Set(
const Timpl &other)
64 this->data |= other.data;
65 return static_cast<Timpl&
>(*this);
62 inline constexpr Timpl &
Set(
const Timpl &other) {
…}
74 inline constexpr Timpl &
Set(Tvalue_type value,
bool set)
76 return set ? this->Set(value) : this->Reset(value);
74 inline constexpr Timpl &
Set(Tvalue_type value,
bool set) {
…}
86 return static_cast<Timpl &
>(*this);
94 inline constexpr Timpl &
Reset(Tvalue_type value)
96 this->data &= ~(1ULL << Timpl::DecayValueType(value));
97 return static_cast<Timpl&
>(*this);
94 inline constexpr Timpl &
Reset(Tvalue_type value) {
…}
105 inline constexpr Timpl &
Reset(
const Timpl &other)
107 this->data &= ~other.data;
108 return static_cast<Timpl&
>(*this);
105 inline constexpr Timpl &
Reset(
const Timpl &other) {
…}
116 inline constexpr Timpl &
Flip(Tvalue_type value)
118 if (this->Test(value)) {
119 return this->Reset(value);
121 return this->Set(value);
116 inline constexpr Timpl &
Flip(Tvalue_type value) {
…}
130 inline constexpr Timpl &
Flip(
const Timpl &other)
132 this->data ^= other.data;
133 return static_cast<Timpl&
>(*this);
130 inline constexpr Timpl &
Flip(
const Timpl &other) {
…}
141 inline constexpr bool Test(Tvalue_type value)
const
143 return (this->data & (1ULL << Timpl::DecayValueType(value))) != 0;
141 inline constexpr bool Test(Tvalue_type value)
const {
…}
151 inline constexpr bool All(
const Timpl &other)
const
153 return (this->data & other.data) == other.data;
151 inline constexpr bool All(
const Timpl &other)
const {
…}
160 inline constexpr bool All()
const
162 return this->data == Tmask;
160 inline constexpr bool All()
const {
…}
170 inline constexpr bool Any(
const Timpl &other)
const
172 return (this->data & other.data) != 0;
170 inline constexpr bool Any(
const Timpl &other)
const {
…}
179 inline constexpr bool Any()
const
181 return this->data != 0;
179 inline constexpr bool Any()
const {
…}
188 inline constexpr bool None()
const
190 return this->data == 0;
188 inline constexpr bool None()
const {
…}
193 inline constexpr Timpl &operator|=(
const Timpl &other)
195 this->data |= other.data;
196 return static_cast<Timpl &
>(*this);
199 inline constexpr Timpl operator|(
const Timpl &other)
const
201 return Timpl{
static_cast<Tstorage
>(this->data | other.data)};
204 inline constexpr Timpl &operator&=(
const Timpl &other)
206 this->data &= other.data;
207 return static_cast<Timpl &
>(*this);
210 inline constexpr Timpl operator&(
const Timpl &other)
const
212 return Timpl{
static_cast<Tstorage
>(this->data & other.data)};
219 inline constexpr Tstorage
base() const noexcept
219 inline constexpr Tstorage
base() const noexcept {
…}
230 return (this->base() & Tmask) == this->base();
249 for (
auto i : *
this) {
250 if (n == 0)
return i;
Functions related to bit mathematics.
constexpr uint CountBits(T value)
Counts the number of set bits in a variable.
Base for bit set wrapper.
uint Count() const
Count the number of set bits.
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 Timpl & Reset()
Reset all bits.
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.
std::optional< Tvalue_type > GetNthSetBit(uint n) const
Get the value of the Nth set bit.
Iterable ensemble of each set bit in a value.