10#ifndef BASE_BITSET_TYPE_HPP
11#define BASE_BITSET_TYPE_HPP
21template <typename Timpl, typename Tvalue_type, typename Tstorage, Tstorage Tmask = std::numeric_limits<Tstorage>::max()>
26 static constexpr Tstorage
MASK = Tmask;
37 constexpr auto operator <=>(
const BaseBitSet &)
const noexcept =
default;
43 constexpr Timpl &
Set()
46 return static_cast<Timpl&
>(*this);
55 template <
typename Treturn_type = Timpl>
requires std::is_base_of_v<BaseBitSet<Timpl, Tvalue_type, Tstorage, Tmask>, Treturn_type>
56 constexpr Treturn_type &
Set(Tvalue_type value)
58 this->
data |= (1ULL << Timpl::DecayValueType(value));
59 return static_cast<Treturn_type &
>(*this);
67 constexpr Timpl &
Set(
const Timpl &other)
69 this->
data |= other.data;
70 return static_cast<Timpl&
>(*this);
79 constexpr Timpl &
Set(Tvalue_type value,
bool set)
81 return set ? this->
Set(value) : this->
Reset(value);
91 return static_cast<Timpl &
>(*this);
99 constexpr Timpl &
Reset(Tvalue_type value)
101 this->
data &= ~(1ULL << Timpl::DecayValueType(value));
102 return static_cast<Timpl&
>(*this);
110 constexpr Timpl &
Reset(
const Timpl &other)
112 this->
data &= ~other.data;
113 return static_cast<Timpl&
>(*this);
123 return static_cast<Timpl &
>(*this);
131 constexpr Timpl &
Flip(Tvalue_type value)
133 if (this->
Test(value)) {
134 return this->
Reset(value);
136 return this->
Set(value);
145 constexpr Timpl &
Flip(
const Timpl &other)
147 this->
data ^= other.data;
148 return static_cast<Timpl&
>(*this);
156 constexpr bool Test(Tvalue_type value)
const
158 return (this->
data & (1ULL << Timpl::DecayValueType(value))) != 0;
166 constexpr bool All(
const Timpl &other)
const
168 return (this->
data & other.data) == other.data;
175 constexpr bool All()
const
177 return this->
data == Tmask;
185 constexpr bool Any(
const Timpl &other)
const
187 return (this->
data & other.data) != 0;
194 constexpr bool Any()
const
196 return this->
data != 0;
205 return this->
data == 0;
208 constexpr Timpl &operator|=(
const Timpl &other)
210 this->data |= other.data;
211 return static_cast<Timpl &
>(*this);
214 constexpr Timpl
operator|(
const Timpl &other)
const
216 return Timpl{
static_cast<Tstorage
>(this->data | other.data)};
219 constexpr Timpl &operator&=(
const Timpl &other)
221 this->data &= other.data;
222 return static_cast<Timpl &
>(*this);
225 constexpr Timpl operator&(
const Timpl &other)
const
227 return Timpl{
static_cast<Tstorage
>(this->data & other.data)};
234 constexpr Tstorage
base() const noexcept
245 return (this->
base() & Tmask) == this->
base();
264 for (
auto i : *
this) {
265 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.
auto end() const
Returns an iterator to the end of the set bits.
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.
constexpr bool Test(Tenum value) const
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 & Flip()
Flip all bits.
constexpr EnumBitSet< Tenum, Tstorage, Tend_value > & Reset()
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.
constexpr BaseBitSet()
Create an empty bitset.
Tvalue_type ValueType
Value type of this BaseBitSet.
constexpr Timpl & Set()
Set all bits.
Tstorage BaseType
Storage type of this BaseBitSet, be ConvertibleThroughBase.
auto begin() const
Returns an iterator to begin of the set bits.
constexpr bool Any(const Timpl &other) const
Test if any of the given values are set.
static constexpr Tstorage MASK
constexpr bool All() const
Test if all of the values are set.
constexpr Timpl & Reset(Tvalue_type value)
Reset the value-th bit.
constexpr BaseBitSet(Tstorage data)
Create a bitset with a given bits that are within the mask of valid values.
constexpr Treturn_type & Set(Tvalue_type value)
Set the value-th bit.
std::optional< Tvalue_type > GetNthSetBit(uint n) const
Get the value of the Nth set bit.
constexpr VarType operator|(VarFileType file, VarMemType mem)
Transitional helper function to combine a file and memory storage configuration.
Iterable ensemble of each set bit in a value.