62template<
typename TInterface, TInterface TEnd, TInterface TBegin= 0>
67 static_assert( !(TBegin > TEnd),
"First Idx greater or equal than last index + 1" );
70 template<
typename TBitSetCM,
bool isReverse>
class TBidiIterator;
103 constexpr static int wordIdx(TInterface b)
noexcept
109 constexpr static int bitIdx (TInterface b)
noexcept
112 &&
int(b) <
int(TEnd),
113 "ALIB/BITS",
"Given bit index out of bounds: {} <= {} < {} ",
156 template<
typename TBitSetCM>
161 template<
typename T,
bool isReverse>
friend class TBidiIterator;
173 constexpr Reference(TBitSetCM& set, TInterface b) noexcept
191 constexpr TInterface
Bit() const noexcept
192 {
return TInterface(
bit); }
212 constexpr operator bool() noexcept
242 constexpr TBitSet(
const std::nullptr_t&)
noexcept {}
272 template <
typename... T>
285 template <
typename... T>
287 TBitSet&
Set( TInterface firstBit, T&&... furtherBits )
noexcept
290 if constexpr (
sizeof...(furtherBits) > 0)
299 template <
typename... T>
304 if constexpr (
sizeof...(furtherBits) > 0)
305 Reset(furtherBits...);
313 template <
typename... T>
318 if constexpr (
sizeof...(furtherBits) > 0)
319 Flip(furtherBits...);
336 bool Test( TInterface bit )
noexcept
410 template<
bool TRequires=QtyWords==1>
requires TRequires
constexpr TWord&
Export() noexcept {
return words[ 0]; }
411 template<
bool TRequires=QtyWords==1>
requires TRequires
const constexpr TWord Export() const noexcept {
return words[ 0]; }
412 template<
bool TRequires=QtyWords!=1>
requires TRequires
constexpr TWord&
Export(
int wordIdx)
noexcept {
415 template<
bool TRequires=QtyWords!=1>
requires TRequires
const constexpr TWord Export(
int wordIdx)
const noexcept {
438 template<
bool TRequires=QtyWords==1>
442 template<
bool TRequires=QtyWords!=1>
459 if(
words[w] != rhs.words[w] )
498 "Negative value {} for TBitSet shift operation given.", cnt )
510 for(
int w=
QtyWords -1; w >= 0; --w )
511 target.words[w]= w - offW >= 0 ?
words[w - offW]
515 for(
int w=
QtyWords -1; w >= 0; --w )
516 target.words[w]= w >= offW ? (
TWord(
words[w - offW] << offB)
531 "Negative value {} for TBitSet shift operation given.", cnt )
586 {
return Reference<TBitSet>(*
this, bit); }
592 const Reference<const TBitSet>
operator[](
int bit)
const noexcept
593 {
return Reference<const TBitSet>(*
this, bit); }
611 template<
typename TBitSetCM,
bool isReverse>
633 ref.bit= TInterface(
int(
ref.bit) + 1);
636 while(
int(
ref.bit) <
int(TEnd))
648 if(
int(
ref.bit) >
int(TEnd))
649 ref.bit= TInterface(TEnd);
654 ref.bit= TInterface(
int(
ref.bit) + trailingZeros - bIdx);
666 ref.bit= TInterface(
int(
ref.bit) - 1);
669 while(
int(
ref.bit) >=
int(TBegin))
682 ref.bit= TInterface(
int(
ref.bit) - bIdx -1);
683 if(
int(
ref.bit) <
int(TBegin) -1)
684 ref.bit= TInterface(
int(TBegin) - 1);
689 ref.bit= TInterface(
int(
ref.bit)
702 :
ref(bitSet, startBit)
710 if constexpr (!isReverse)
return up();
737 return !(*
this == other);
753 if constexpr (isReverse)
return up();
772 {
return ref.bit < other.
ref.bit; }
779 {
return ref.bit <= other.
ref.bit; }
786 {
return ref.bit > other.
ref.bit; }
793 {
return ref.bit >= other.
ref.bit; }
874DOX_MARKER([DOX_MANUAL_ALIASES_BITSET])
876template<
int TEnd,
int TBegin= 0,
typename TInterface=
int>
878DOX_MARKER([DOX_MANUAL_ALIASES_BITSET])
899template<
typename TInterface, TInterface TEnd, TInterface TBegin>
907 result.
Import( lhs.Export() & rhs.Export() );
909 for (
int w = 0; w < alib::lang::TBitSet<TInterface,TEnd,TBegin>::QtyWords; ++w)
910 result.
Import( lhs.Export(w) & rhs.Export(w), w );
925template<
typename TInterface, TInterface TEnd, TInterface TBegin>
933 result.
Import( lhs.Export() | rhs.Export() );
935 for (
int w = 0; w < alib::lang::TBitSet<TInterface,TEnd,TBegin>::QtyWords; ++w)
936 result.
Import( lhs.Export(w) | rhs.Export(w), w );
951template<
typename TInterface, TInterface TEnd, TInterface TBegin>
959 result.
Import( lhs.Export() ^ rhs.Export() );
961 for (
int w = 0; w < alib::lang::TBitSet<TInterface,TEnd,TBegin>::QtyWords; ++w)
962 result.
Import( lhs.Export(w) ^ rhs.Export(w), w );
Reference & operator=(const Reference &other) noexcept=default
constexpr Reference(TBitSetCM &set, TInterface b) noexcept
constexpr class TBitSet & TBitSet() noexcept
~Reference() noexcept
Destructor. (Is declared constexpr with C++23.)
constexpr Reference & Flip() noexcept
constexpr TInterface Bit() const noexcept
constexpr const class TBitSet & TBitSet() const noexcept
constexpr Reference & operator=(bool val) noexcept
constexpr bool operator==(const Reference &rhs) const noexcept=default
constexpr bool operator~() noexcept
constexpr Reference(const Reference &) noexcept=default
Defaulted copy constructor.
TInterface value_type
Implementation of std::iterator_traits.
TBidiIterator operator--(int)
TBidiIterator operator++(int)
Reference< TBitSetCM > & reference
Implementation of std::iterator_traits.
bool operator>=(TBidiIterator other) const
bool operator!=(const TBidiIterator &other) const
bool operator>(TBidiIterator other) const
void pointer
Implementation of std::iterator_traits.
bool operator<=(TBidiIterator other) const
TBidiIterator & operator--()
TBidiIterator & operator++()
TBidiIterator(TBitSetCM &bitSet, TInterface startBit)
bool operator<(TBidiIterator other) const
bool operator==(const TBidiIterator &other) const
int difference_type
Implementation of std::iterator_traits.
std::bidirectional_iterator_tag iterator_category
Implementation of std::iterator_traits.
ConstReverseIterator rend() const
constexpr bool All() const noexcept
constexpr TBitSet(TWord preset) noexcept
constexpr TBitSet & Flip() noexcept
Flips all bits from 0 to 1 and vice versa.
static constexpr TWord mask(int wIdx) noexcept
constexpr TBitSet & operator&=(const TBitSet &rhs) noexcept
constexpr void shiftRight(int cnt, TBitSet &target) const noexcept
constexpr TBitSet & Reset(TInterface firstBit, T &&... furtherBits) noexcept
constexpr TBitSet & operator|=(const TBitSet &rhs) noexcept
constexpr TBitSet() noexcept
Default constructor initializing all bits to not set.
TBidiIterator< TBitSet, false > Iterator
constexpr int Count() const noexcept
constexpr TBitSet & Set(TInterface bit, bool val) noexcept
ReverseIterator rbegin(int skip=0)
constexpr TBitSet & Set(TInterface firstBit, T &&... furtherBits) noexcept
constexpr TBitSet & Reset() noexcept
Sets all bits to 0.
constexpr bool operator==(const TBitSet &rhs) const noexcept
constexpr TWord & word(TInterface b) noexcept
constexpr TBitSet & operator^=(const TBitSet &rhs) noexcept
constexpr TBitSet(bool preset) noexcept
TBidiIterator< TBitSet, true > ReverseIterator
constexpr TBitSet operator>>(int cnt) const noexcept
ConstIterator cbegin(int skip=0) const
static constexpr int bitIdx(TInterface b) noexcept
static constexpr int QtyWords
ConstReverseIterator rbegin(int skip=0) const
constexpr bool Test(TInterface bit) noexcept
TBidiIterator< const TBitSet, true > ConstReverseIterator
std::conditional_t<(Capacity > bitsof(long)), unsigned long long, std::conditional_t<(Capacity > bitsof(int)), unsigned long, std::conditional_t<(Capacity > bitsof(short)), unsigned int, std::conditional_t<(Capacity > bitsof(char)), unsigned short, unsigned char > > > > TWord
constexpr const TWord & Export(int wordIdx) const noexcept
static constexpr TWord mask1101(TInterface b) noexcept
constexpr const TWord & word(TInterface b) const noexcept
constexpr TBitSet operator~() const noexcept
constexpr void Import(TWord val, int wordIdx) noexcept
static constexpr TWord mask0010(TInterface b) noexcept
constexpr const Reference< const TBitSet > operator[](int bit) const noexcept
ConstReverseIterator crbegin(int skip=0) const
constexpr TBitSet & Flip(TInterface firstBit, T &&... furtherBits) noexcept
constexpr Reference< TBitSet > operator[](TInterface bit) noexcept
constexpr TBitSet & Set() noexcept
Sets all bits to 1.
static constexpr int Capacity
Iterator begin(int skip=0)
constexpr bool Any() const noexcept
constexpr TBitSet(const std::nullptr_t &) noexcept
constexpr TWord & Export(int wordIdx) noexcept
ConstIterator cend() const
ConstIterator begin(int skip=0) const
constexpr TBitSet & operator<<=(int cnt) noexcept
TWord words[QtyWords ? QtyWords :1]
constexpr TBitSet & operator>>=(int cnt) noexcept
TBidiIterator< const TBitSet, false > ConstIterator
ConstIterator end() const
constexpr bool None() const noexcept
ConstReverseIterator crend() const
constexpr TBitSet operator<<(int cnt) const noexcept
static constexpr int wordIdx(TInterface b) noexcept
constexpr void shiftLeft(int cnt, TBitSet &target) const noexcept
#define ALIB_ASSERT_ERROR(cond, domain,...)
platform_specific integer
ALIB_EXPORT constexpr alib::lang::TBitSet< TInterface, TEnd, TBegin > operator&(const alib::lang::TBitSet< TInterface, TEnd, TBegin > &lhs, const alib::lang::TBitSet< TInterface, TEnd, TBegin > &rhs) noexcept
constexpr int CLZ(TIntegral value)
ALIB_EXPORT constexpr alib::lang::TBitSet< TInterface, TEnd, TBegin > operator^(const alib::lang::TBitSet< TInterface, TEnd, TBegin > &lhs, const alib::lang::TBitSet< TInterface, TEnd, TBegin > &rhs) noexcept
constexpr TIntegral UpperMask()
constexpr int CTZ(TIntegral value)
constexpr TIntegral LowerMask()
ALIB_EXPORT constexpr alib::lang::TBitSet< TInterface, TEnd, TBegin > operator|(const alib::lang::TBitSet< TInterface, TEnd, TBegin > &lhs, const alib::lang::TBitSet< TInterface, TEnd, TBegin > &rhs) noexcept
constexpr int BitCount(TIntegral value)
lang::TBitSet< int, TEnd, TBegin > BitSet
Type alias in namespace alib.