ALib C++ Library
Library Version: 2412 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
bitset.hpp
Go to the documentation of this file.
1//==================================================================================================
2/// \file
3/// This header file is part of the \aliblong. It does not belong to an \alibmod and is
4/// included in any \alibdist.
5///
6/// \emoji :copyright: 2013-2024 A-Worx GmbH, Germany.
7/// Published under \ref mainpage_license "Boost Software License".
8//==================================================================================================
9#ifndef HPP_ALIB_LANG_BITSET
10#define HPP_ALIB_LANG_BITSET 1
11#pragma once
12#include "alib/lang/bits.hpp"
13
15namespace alib { namespace lang {
16
17//==================================================================================================
18/// This class is an improved replica of <c>std::bitset</c> and hence stores and exposes a set of
19/// bits. The differences (advantages) of this class to the standard type are:
20/// - The class provides an efficient bidirectional iterator, which uses intrinsics
21/// (on supported platforms, via functions \alib{lang;CLZ} and \alib{lang;CTZ}) to search the
22/// next bit set without looping over unset bits.
23/// - The size of this type's instances is adjusted to the next fitting integral size, namely
24/// <c>char</c>, <c>short</c>, <c>int</c>, <c>long</c> and <c>long long</c>.
25/// If even larger bitsets are requested, the size becomes a multiple of the size of
26/// <c>long long</c>.
27/// - The type denoting a bit-index used in the interface methods can optionally be altered from
28/// <c>int</c> to a custom type which is statically castable to <c>int</c>, by providing
29/// specifying template parameter \p{TInterface} accordingly. This avoids the need for
30/// statically casting the index type with every invocation of an interface method.<br>
31/// The main motivation for providing this was to allow to
32/// \ref alib_enums_iter_bitset "address bits with enumeration elements".
33/// - Instead of one template parameter defining the fixed size of the bitset, two parameters
34/// \p{TBegin} and \p{TEnd} are provided. This allows defining bitsets of a range
35/// of indices that do not start with <c>0</c> and in this case avoids the need for subtraction of
36/// the (fixed) start value of a range with every invocation of an interface method.
37/// - Methods #Set and #Reset allow to pass several bit indices at once using a comma-separated list.
38/// - With methods <c>std::bitset<N>::to_ulong() / to_ullong()</c>, the standard type allows
39/// the export of the internal value only to 64-bit values (on common platforms).
40/// If the higher bits are to be exported, the bitset has to be shifted, which is inefficient
41/// and destructive (a copy has to be taken).<br>
42/// This implementation provides method #Export, which - dependent on the size of the bitset -
43/// offers an additional index to address any higher word. Furthermore, for smaller bitsets
44/// the export method returns a fitting smaller integral.
45/// - Explicit uninitialized construction is possíble with
46/// \alib{lang;TBitSet::TBitSet(const std::nullptr_t&)}, which
47/// avoids code and run-time penalty, in cases where the bits are to be initialized at a later
48/// stage.
49///
50/// In respect to performance, this type equals a typical implementation <c>std::bitset</c>.
51///
52/// @see
53/// - Type definition \alib{enums;EnumBitSet}, which defines a bitset over
54/// \ref alib_enums_iter "ALib Iterable Enums" based on this type.<br>
55/// - For a quick tutorial on the use of this type (in nice combination with C++ enumerations),
56/// see chapter \ref alib_enums_iter_bitset "3.5 Using Class TBitSet with Iterable Enums" of the
57/// Programmer's Manual of module \alib_enums_nl.
58/// - Type definition \ref alib::BitSet "BitSet" in namespace \ref alib, which defines a set with
59/// interface-type <c>int</c>.
60/// - Class \alib{bitbuffer;BitBuffer}, which implements a sort of stream buffer to store
61/// bits in dynamic memory.
62///
63/// @tparam TInterface The interface type to denote bit position values. This type has to be
64/// statically castable to and constructible from <c>int</c>.
65/// @tparam TEnd The last index of the interface type plus <c>1</c>.
66/// @tparam TBegin The first index of the interface type. (Defaults to <c>0</c>.)
67//==================================================================================================
68template< typename TInterface, TInterface TEnd, TInterface TBegin= 0>
70{
71 protected:
72 #if !DOXYGEN
74 static_assert( !(TBegin > TEnd), "First Idx greater or equal than last index + 1" );
75 #endif
76 // forward declaration
77 template<typename TBitSetCM, bool isReverse> class TBidiIterator;
78
79 // -------------------------------------- members ------------------------------------------
80
81 public:
82 /// The number of bits in the range resulting from template parameters \p{TBegin}
83 /// and \p{TEnd}.
84 static constexpr int Capacity= static_cast<int>( TEnd )
85 - static_cast<int>( TBegin );
86
87 /// The type that is used to store the bits in. TMP code chooses the smallest fitting integral.
88 /// If #Capacity exceeds type <c>long long</c>, an array of <c>long long</c>, field #QtyWords
89 /// will become greater than \c 1.
90 using TWord= ATMP_IF_T_F( (Capacity > bitsof(long) ), unsigned long long,
91 ATMP_IF_T_F( (Capacity > bitsof(int) ), unsigned long ,
92 ATMP_IF_T_F( (Capacity > bitsof(short) ), unsigned int ,
93 ATMP_IF_T_F( (Capacity > bitsof(char) ), unsigned short ,
94 unsigned char ))));
95
96 public:
97 /// The size of the #TWord array containing the bits
98 static constexpr int QtyWords= Capacity / bitsof(TWord)
99 + ( (Capacity % bitsof(TWord)) != 0 ? 1 : 0 );
100
101 protected:
102 /// The array of integrals containing the bits needed. The unused upper bits in the last word
103 /// are always kept <c>0</c>.
105
106 // -------------------------------------- helpers ------------------------------------------
107 /// Helper to determine the bit index in the actual word.
108 /// @param b The absolute index.
109 /// @return The word index.
110 constexpr static int wordIdx(TInterface b) noexcept
111 { return (static_cast<int>(b) - static_cast<int>(TBegin)) / bitsof(TWord); }
112
113 /// Helper to determine the bit index in the actual word.
114 /// @param b The absolute index.
115 /// @return The relative index.
116 constexpr static int bitIdx (TInterface b) noexcept
117 {
118 ALIB_ASSERT_ERROR( static_cast<int>(b) >= static_cast<int>(TBegin)
119 && static_cast<int>(b) < static_cast<int>(TEnd),
120 "ALIB/BITS", "Given bit index out of bounds: ", static_cast<int>(b) )
121 return (static_cast<int>(b) - static_cast<int>(TBegin)) % bitsof(TWord);
122 }
123
124 /// Helper receive the word from the array of words.
125 /// @param b The bit to address index.
126 /// @return A reference to the word.
127 constexpr TWord& word (TInterface b) noexcept { return words[wordIdx(b)]; }
128
129 /// Helper receive a \c const reference word from the array of words.
130 /// @param b The bit to address index.
131 /// @return A reference to the word.
132 constexpr const TWord& word (TInterface b) const noexcept { return words[wordIdx(b)]; }
133
134 /// Returns a bitmask with all used bits set.
135 /// @param wIdx The index of the word in array #words.
136 /// @return A bitmask with all bits set for indices smaller than #QtyWords <c>-1</c>,
137 /// and a mask that covers the remaining bits if \p{wIdx} targets the last word.
138 constexpr static TWord mask (int wIdx) noexcept
139 {
140 return wIdx < QtyWords- 1 || (Capacity % bitsof(TWord)) == 0
141 ? TWord(~TWord(0))
143 }
144
145 /// Returns a bitmask with only the given bit set.
146 /// @param b The index of the bit to set.
147 /// @return A bitmask with one bit set.
148 constexpr static TWord mask0010(TInterface b) noexcept { return TWord(TWord(1) << bitIdx(b)); }
149
150 /// Returns a bitmask with only the given bit unset.
151 /// @param b The index of the bit to unset.
152 /// @return A bitmask with all but one bit set.
153 constexpr static TWord mask1101(TInterface b) noexcept { return ~mask0010(b); }
154
155 public:
156 ////////////////////////////////////////////////////////////////////////////////////////////////
157 /// A publicly accessible nested class, used as a proxy object to allow users to interact with
158 /// individual bits of a bitset.
159 /// The primary use of this type is to provide a \e lvalue that can be returned from operator[].
160 /// @tparam TBitSetCM A constant or mutable \b TBitSet.
161 ////////////////////////////////////////////////////////////////////////////////////////////////
162 template<typename TBitSetCM>
164 {
165 protected:
166 #if !DOXYGEN
167 template<typename T, bool isReverse> friend class TBidiIterator;
168 #endif
169
170 TInterface bit; ///< The bit number in #bitSet this reference addresses.
171 TBitSetCM* bitSet; ///< The \b TBitSet this reference addresses.
172
173 public:
174 /// Constructor.
175 /// \note In contrast to the constructor of <c>std::bitset::reference</c>,
176 /// this constructor is public to allow easy external construction.<br>
177 /// @param set The parent \b TBitSet.
178 /// @param b The bit to represent in the TBitSet.
179 constexpr Reference(TBitSetCM& set, TInterface b) noexcept
180 : bit(b), bitSet(&set) {}
181
182 /// Defaulted copy constructor.
183 constexpr Reference(const Reference&) noexcept= default;
184
185 /// Destructor. (Is declared \c constexpr with C++23.)
186 ALIB_CPP_23(constexpr)
187 ~Reference() noexcept {}
188
189 /// Copy assignment operator. (Defaulted, as otherwise implicitly deleted due to
190 /// user-provided destructor.)
191 /// @param other The object to copy.
192 /// @return A reference to \c this.
193 Reference& operator= (const Reference& other) noexcept = default;
194
195 /// Returns the represented bit number.
196 /// @return The bit that this object refers to.
197 constexpr TInterface Bit() const noexcept
198 { return TInterface(bit); }
199
200 /// Returns the underlying bitset.
201 /// @return The \b TBitSet that this object refers to.
202 constexpr class TBitSet& TBitSet() noexcept
203 { return bitSet; }
204
205 /// Returns the underlying bitset.
206 /// @return The \b TBitSet that this object refers to.
207 constexpr const class TBitSet& TBitSet() const noexcept
208 { return bitSet; }
209
210 /// Sets or resets the represented bit.
211 /// @param val The value to assign to the represented bit.
212 /// @return A reference to \c this.
213 constexpr Reference& operator=(bool val) noexcept
214 { bitSet->Set(bit, val); return *this; }
215
216 /// Implicit conversion to bool.
217 /// @return The value of the represented bit.
218 constexpr operator bool() noexcept
219 { return bitSet->Test(bit); }
220
221 /// Does not manipulate the bit, but returns its negated value.
222 /// @return The negated value of the represented bit.
223 constexpr bool operator~() noexcept
224 { return !bitSet->Test(bit); }
225
226 /// Flips the represented bit.
227 /// @return A reference to \c this.
228 constexpr Reference& Flip() noexcept
229 { bitSet->Flip(bit); return *this; }
230
231 #if ALIB_CPP_STANDARD >= 20 || DOXYGEN
232 /// Compares this object to another.
233 /// @param rhs The right hand side of the comparison.
234 /// @return \c true if the objects reference the same bit in the same bitset, \c false
235 /// otherwise
236 constexpr bool operator== (const Reference& rhs) const noexcept = default;
237 #else
238 constexpr bool operator== (const Reference& rhs) const noexcept
239 {
240 return bit == rhs.bit
241 && bitSet == rhs.bitSet;
242 }
243 #endif
244 }; // inner class Reference
245
246 // ------------------------------------ constructors ---------------------------------------
247 /// Default constructor initializing all bits to not set.
248 constexpr TBitSet() noexcept
249 {
250 Reset();
251 }
252
253 // ------------------------------------ constructors ---------------------------------------
254 /// Constructor taking a tag-type. This constructor omits any value initialization and
255 /// <b>has to be called by providing <c>nullptr</c></b> as the argument.
256 constexpr TBitSet(const std::nullptr_t&) noexcept {}
257
258 /// Constructor which takes an external #TWord which initializes the first word. If \c constexpr
259 /// field #QtyWords is greater than \c 1, the other bits are set to \c 0 and can be set using
260 /// method #Import or of course using other interface methods.
261 /// @param preset The preset value for the bits.
262 constexpr TBitSet( TWord preset ) noexcept
263 {
264 words[0]= preset & mask(0);
265 for (int w = 1; w < QtyWords; ++w)
266 words[w]= 0;
267 }
268
269 /// Constructor which takes an external #TWord which initializes the first word. If \c constexpr
270 /// field #QtyWords is greater than \c 1, the other bits are set to \c 0 and can be set using
271 /// method #Import or of course using other interface methods.
272 /// @param preset The preset value for the bits.
273 constexpr TBitSet( bool preset ) noexcept
274 {
275 for (int w = 0; w < QtyWords; ++w)
276 words[w]= preset ? TWord(~(TWord(0))) & mask(w)
277 : TWord(0);
278 }
279
280
281 // ----------------------------------- set / reset -----------------------------------------
282 /// Sets the \p{bit} to <c>1</c>.
283 /// @param bit The index of the bit to set.
284 /// @param val \c true or \c false to set or clear bit \p{bit}.
285 /// @return A reference to \c this object.
286 template <typename... T>
287 constexpr
288 TBitSet& Set( TInterface bit, bool val ) noexcept
289 {
290 if( val ) Set(bit);
291 else Reset(bit);
292 return *this;
293 }
294
295 /// Sets one or more bits to <c>1</c>.
296 /// @param firstBit The index of the first bit to set.
297 /// @param furtherBits An optional continued list of bit-indices.
298 /// @return A reference to \c this object.
299 template <typename... T>
300 constexpr
301 TBitSet& Set( TInterface firstBit, T&&... furtherBits ) noexcept
302 {
303 word(firstBit)|= mask0010(firstBit);
304 if constexpr (sizeof...(furtherBits) > 0)
305 Set(furtherBits...);
306 return *this;
307 }
308
309 /// Sets one or more bits to <c>0</c>.
310 /// @param firstBit The index of the first bit to clear.
311 /// @param furtherBits An optional continued list of bit-indices.
312 /// @return A reference to \c this object.
313 template <typename... T>
314 constexpr
315 TBitSet& Reset( TInterface firstBit, T&&... furtherBits ) noexcept
316 {
317 word(firstBit)&= mask1101(firstBit);
318 if constexpr (sizeof...(furtherBits) > 0)
319 Reset(furtherBits...);
320 return *this;
321 }
322
323 /// Flips one or more bits from <c>0</c> to <c>1</c> and vice versa.
324 /// @param firstBit The index of the bit to flip.
325 /// @param furtherBits An optional continued list of indices of bits to flip.
326 /// @return A reference to \c this object.
327 template <typename... T>
328 constexpr
329 TBitSet& Flip( TInterface firstBit, T&&... furtherBits ) noexcept
330 {
331 word(firstBit)^= mask0010(firstBit);
332 if constexpr (sizeof...(furtherBits) > 0)
333 Flip(furtherBits...);
334 return *this;
335 }
336
337
338 /// Sets all bits to <c>1</c>. @return A reference to this object.
339 constexpr TBitSet& Set() noexcept { for (int w = 0; w < QtyWords; ++w) words[w]= mask(w); return *this; }
340 /// Sets all bits to <c>0</c>. @return A reference to this object.
341 constexpr TBitSet& Reset() noexcept { for (int w = 0; w < QtyWords; ++w) words[w]= 0; return *this; }
342 /// Flips all bits from <c>0</c> to <c>1</c> and vice versa. @return A reference to this object.
343 constexpr TBitSet& Flip() noexcept { for (int w = 0; w < QtyWords; ++w) words[w]^= mask(w); return *this; }
344
345 // -------------------------------------- test ---------------------------------------------
346 /// Returns \c true if the \p{bit} is set, \c false otherwise.
347 /// @param bit Denotes the bit to test.
348 /// @return The state of the \p{bit}.
349 constexpr
350 bool Test( TInterface bit ) noexcept
351 {
352 return 0 != (word(bit) & mask0010(bit)) ;
353 }
354
355 // ---------------------------------- count/all/any/none -----------------------------------
356 /// Returns the number of bits set to \c true in this set.
357 /// @return The number of bits counted.
358 constexpr
359 int Count() const noexcept
360 {
361 int result= 0;
362 for (int w = 0; w < QtyWords; ++w)
363 result+= BitCount(words[w]);
364 return result;
365 }
366
367 /// Tests if any bit is set.
368 /// @return \c true if all bits are set, \c false otherwise.
369 constexpr
370 bool All() const noexcept
371 {
372 for (int w = 0; w < QtyWords; ++w)
373 if(words[w] != mask(w) )
374 return false;
375 return true;
376 }
377
378 /// Tests if any bit is set.
379 /// @return \c true if at least one bit is set, \c false otherwise.
380 constexpr
381 bool Any() const noexcept
382 {
383 for (int w = 0; w < QtyWords; ++w)
384 if(words[w] != 0 )
385 return true;
386 return false;
387 }
388
389 /// Tests if not any bit is set.
390 /// @return \c false if at least one bit is set, \c true otherwise.
391 constexpr
392 bool None() const noexcept
393 {
394 return !Any();
395 }
396
397 // --------------------------------- import/export -----------------------------------------
398#if DOXYGEN
399 /// Exports the internal integral(s) holding the bits.
400 ///
401 /// \attention
402 /// Other than this documentation suggests, parameter \p{wordIdx} is only available if
403 /// the bitset size (defined by template parameters \p{TBegin} and \p{TEnd})
404 /// exceeds the number of bits in the widest possible #TWord-type, hence the size
405 /// of <c>sizeof(long long) * 8</c>. In that case, field #QtyWords provides the number of
406 /// words that are exportable.<br>
407 /// This maxiumum word size is 64-bit on common platforms. Here, \c 0 adresses bits 0..63,
408 /// \c 1 bits 64..127 and so forth.
409 ///
410 /// @param wordIdx The subset of bits to receive.
411 /// @return A reference to the inner word.
412 constexpr
413 TWord& Export(int wordIdx) noexcept
414 {}
415
416 /// Const version of #Export.
417 /// @param wordIdx The subset of bits to receive.<br>
418 /// \b ATTENTION: See non-constant variant #Export on this parameter!
419 /// @return A reference to the inner word.
420 constexpr
421 const TWord& Export(int wordIdx) const noexcept
422 {}
423#else
424 template<int TEnableif=QtyWords> typename std::enable_if<TEnableif==1, TWord&>::type Export() noexcept { return words[ 0]; }
425 template<int TEnableif=QtyWords> typename std::enable_if<TEnableif==1,const TWord >::type Export() const noexcept { return words[ 0]; }
426 template<int TEnableif=QtyWords> typename std::enable_if<TEnableif!=1, TWord&>::type Export(int wordIdx) noexcept {
427 ALIB_ASSERT_ERROR( wordIdx >= 0 && wordIdx < QtyWords, "ALIB/BITS", "Index out of bounds.") return words[wordIdx]; }
428 template<int TEnableif=QtyWords> typename std::enable_if<TEnableif!=1,const TWord >::type Export(int wordIdx) const noexcept {
429 ALIB_ASSERT_ERROR( wordIdx >= 0 && wordIdx < QtyWords, "ALIB/BITS", "Index out of bounds.") return words[wordIdx]; }
430#endif
431
432#if DOXYGEN
433 /// Imports the data from (a) given integral(s).
434 ///
435 /// \attention
436 /// Other than this documentation suggests, parameter \p{wordIdx} is only available if
437 /// the bitset size (defined by template parameters \p{TBegin} and \p{TEnd})
438 /// exceeds the number of bits in the widest possible #TWord-type, hence the size
439 /// of <c>sizeof(long long) * 8</c>. In that case, field #QtyWords provides the number of
440 /// words that are importable.<br>
441 /// This maxiumum word size is 64-bit on common platforms. Here, \c 0 adresses bits 0..63,
442 /// \c 1 bits 64..127 and so forth.
443 ///
444 /// @param val The value to import.
445 /// @param wordIdx The subset of bits to overwrite.
446 /// @return A reference to the inner word.
447 constexpr
448 TWord& Import(TWord val, int wordIdx) noexcept
449 {}
450#else
451 template<int TEnableif=QtyWords>
452 typename std::enable_if<TEnableif==1,void>::type
453 Import(TWord val ) noexcept
454 {
455 words[ 0]= val & mask(0);
456 }
457 template<int TEnableif=QtyWords>
458 typename std::enable_if<TEnableif!=1,void>::type
459 Import(TWord val, int wordIdx) noexcept
460 {
461 ALIB_ASSERT_ERROR( wordIdx >= 0 && wordIdx < QtyWords, "ALIB/BITS",
462 "Index out of bounds." )
463 words[wordIdx]= val &= mask(wordIdx);
464 }
465#endif
466
467 // ---------------------------------- operators ------------------------------------------
468 /// Compares this bitset with another bitset of equal size.
469 /// @param rhs The other \b TBitSet to compare this with.
470 /// @return \c true if all bits are equal, \c false otherwise.
471 constexpr bool operator==( const TBitSet& rhs ) const noexcept
472 {
473 for (int w = 0; w < QtyWords; ++w)
474 if(words[w] != rhs.words[w] )
475 return false;
476 return true;
477 }
478
479 #if ALIB_CPP_STANDARD < 20 || DOXYGEN
480 /// Compares this bitset with another bitset of equal size.<br>
481 /// (Available with C++ versions below 20. Afterwards synthesized.
482 /// @param rhs The other \b TBitSet to compare this with.
483 /// @return \c false if all bits are equal, \c true otherwise.
484 constexpr bool operator!=( const TBitSet& rhs ) const noexcept { return !this->operator==(rhs); }
485 #endif
486
487 /// Sets the bits to the result of binary AND on corresponding pairs of bits of \c this and other.
488 /// @param rhs The other \b TBitSet to compare this with.
489 /// @return A reference to \c this object.
490 constexpr TBitSet& operator&=(const TBitSet& rhs) noexcept { for(int w=0;w<QtyWords;++w) words[w]&= rhs.words[w]; return *this; }
491
492 /// Sets the bits to the result of binary OR on corresponding pairs of bits of \c this and other.
493 /// @param rhs The other \b TBitSet to compare this with.
494 /// @return A reference to \c this object.
495 constexpr TBitSet& operator|=(const TBitSet& rhs) noexcept { for(int w=0;w<QtyWords;++w) words[w]|= rhs.words[w]; return *this; }
496
497 /// Sets the bits to the result of binary XOR on corresponding pairs of bits of \c this and other.
498 /// @param rhs The other \b TBitSet to compare this with.
499 /// @return A reference to \c this object.
500 constexpr TBitSet& operator^=(const TBitSet& rhs) noexcept { for(int w=0;w<QtyWords;++w) words[w]^= rhs.words[w]; return *this; }
501
502 /// Returns a temporary copy of \c this with all bits flipped (binary NOT)..
503 /// @return A copy of this with flipped bits.
504 constexpr TBitSet operator~() const noexcept
505 {
506 auto result= *this;
507 for(int w= 0; w<QtyWords ; ++w)
508 result.words[w]= ~words[w] & mask(w);
509 return result;
510 }
511
512 protected:
513 /// Stores a shifted result in \p{target}. This protected method is accessible via
514 /// <c>operator<<()</c> (which creates and returns a temporary target) and <c>operator<<=()</c>,
515 /// which passes \c this to parameter \p{target}.
516 /// @param cnt The number of positions to shift.
517 /// @param target The target object.
518 constexpr void shiftLeft(int cnt, TBitSet& target) const noexcept
519 {
520 ALIB_ASSERT_ERROR( cnt >= 0, "ALIB/BITS", "Negative value for TBitSet shift operation given." )
521 // shift out of bounds?
522 if( cnt >= Capacity)
523 {
524 target.Reset();
525 return;
526 }
527
528 int offW= cnt / bitsof(TWord);
529 int offB= cnt % bitsof(TWord);
530 // no bit hassle
531 if( offB == 0)
532 for( int w= QtyWords -1; w >= 0; --w )
533 target.words[w]= w - offW >= 0 ? words[w - offW]
534 : TWord(0);
535 // with bit shifts
536 else
537 for( int w= QtyWords -1; w >= 0; --w )
538 target.words[w]= w >= offW ? ( TWord(words[w - offW] << offB)
539 | ( w > offW ? words[w-offW-1] >> (bitsof(TWord) - offB)
540 : TWord(0) ) )
541 : TWord(0);
543 }
544
545 /// Stores a shifted result in \p{target}. This protected method is accessible via
546 /// <c>operator>>()</c> (which creates and returns a temporary target) and <c>operator>>=()</c>,
547 /// which passes \c this to parameter \p{target}.
548 /// @param cnt The number of positions to shift.
549 /// @param target The target object.
550 constexpr void shiftRight(int cnt, TBitSet& target) const noexcept
551 {
552 ALIB_ASSERT_ERROR( cnt >= 0, "ALIB/BITS", "Negative value for TBitSet shift operation given." )
553 // shift out of bounds?
554 if( cnt >= Capacity)
555 {
556 target.Reset();
557 return;
558 }
559
560 int offW= cnt / bitsof(TWord);
561 int offB= cnt % bitsof(TWord);
562 // no bit hassle
563 if( offB == 0)
564 for( int w= 0; w < QtyWords; ++w )
565 target.words[w]= w + offW < QtyWords ? words[w + offW]
566 : TWord(0);
567 // with bit shifts
568 else
569 for( int w= 0; w < QtyWords; ++w )
570 target.words[w]= w < QtyWords- offW ? ( TWord(words[w + offW] >> offB)
571 | ( w < QtyWords- offW - 1 ? TWord(words[w+offW+1] << (bitsof(TWord) - offB))
572 : TWord(0) ) )
573 : TWord(0);
575 }
576
577 public:
578 /// Returns a temporary copy of this with a shift to the left (towards higher index positions).
579 /// @param cnt The number of positions to shift.
580 /// @return A copy of this with shifted bits.
581 constexpr TBitSet operator<<(int cnt) const noexcept
582 { TBitSet result= TBitSet(nullptr); shiftLeft(cnt, result); return result; }
583
584 /// Shifts the bits of this object to the left left (towards higher index positions).
585 /// @param cnt The number of positions to shift.
586 /// @return A reference to this object.
587 constexpr TBitSet& operator<<=(int cnt) noexcept
588 { shiftLeft(cnt, *this); return *this; }
589
590 /// Returns a temporary copy of this with a shift to the right (towards lower index positions).
591 /// @param cnt The number of positions to shift.
592 /// @return A copy of this with shifted bits.
593 constexpr TBitSet operator>>(int cnt) const noexcept
594 { TBitSet result= TBitSet(nullptr); shiftRight(cnt, result); return result; }
595
596 /// Shifts the bits of this object to the left right (towards lower index positions).
597 /// @param cnt The number of positions to shift.
598 /// @return A reference to this object.
599 constexpr TBitSet& operator>>=(int cnt) noexcept
600 { shiftRight(cnt, *this); return *this; }
601
602 /// Returns a reference to a specific bit.
603 /// @param bit The bit to create a reference for.
604 /// @return A reference to the bit in this object.
605 constexpr
606 Reference<TBitSet> operator[](TInterface bit) noexcept
607 { return Reference<TBitSet>(*this, bit); }
608
609 /// Returns a \c const reference to a specific bit.
610 /// @param bit The bit to create a reference for.
611 /// @return A reference to the bit in this object.
612 constexpr
613 const Reference<const TBitSet> operator[](int bit) const noexcept
614 { return Reference<const TBitSet>(*this, bit); }
615
617
618 protected:
619 ////////////////////////////////////////////////////////////////////////////////////////////////
620 /// Implementation of \c std::iterator_traits for class \b %TBitSet.
621 /// As the name of the class indicates, this iterator satisfies the C++ standard library
622 /// concept of <em>bidirectional iterators</em>. The template parameters allow this
623 /// type to act as a <c>const</c> or mutable as well as a forward or backward iterator.<br>
624 /// The public available type definitions which specify the template parameters and are
625 /// returned from the various \c begin() and \c end() variants of the outer class are:
626 /// - \alib{lang::TBitSet;Iterator},
627 /// - \alib{lang::TBitSet;ReverseIterator},
628 /// - \alib{lang::TBitSet;ConstIterator}, and
629 /// - \alib{lang::TBitSet;ConstReverseIterator}.
630 ///
631 /// @tparam TBitSetCM A constant or mutable TBitSet.
632 /// @tparam isReverse If set, this iterator is a swaps ++ and -- operators.
633 ////////////////////////////////////////////////////////////////////////////////////////////////
634 template<typename TBitSetCM, bool isReverse>
636 {
637 public:
638 using iterator_category = std::bidirectional_iterator_tag; ///< Implementation of <c>std::iterator_traits</c>.
639 using value_type = TInterface; ///< Implementation of <c>std::iterator_traits</c>.
640 using difference_type = int; ///< Implementation of <c>std::iterator_traits</c>.
641 using pointer = void; ///< Implementation of <c>std::iterator_traits</c>.
642 using reference = Reference<TBitSetCM>&; ///< Implementation of <c>std::iterator_traits</c>.
643
644 protected:
645 /// The bit this iterator currently addresses. This is true for forward and reverse
646 /// iterators. (Because this is not using the <c>std::reverse_iterator<</c> which would
647 /// implement an reverse iterator that points 'before' the current element.
649
650 /// Searches and moves this iterator to the next higher bit is. In case no further bit is
651 /// found, the iterator will points to illegal bit number \p{TBitSet::Capacity}
652 /// @return A reference to this object.
654 {
655 // next bit
656 ref.bit= TInterface(static_cast<int>(ref.bit) + 1);
657
658 // search next bit from here
659 while(static_cast<int>(ref.bit) < static_cast<int>(TEnd))
660 {
661 int bIdx= bitIdx(ref.bit);
662 TWord word= ref.bitSet->word(ref.bit)
663 & UpperMask<TWord>(bIdx);
664 // search
665 int trailingZeros;
666 if( word == 0
667 || ((trailingZeros= CTZ<TWord>( word )) == bitsof(TWord) ) )
668 {
669 // not found in this word
670 ref.bit= TInterface( static_cast<int>(ref.bit) + bitsof(TWord) - bIdx );
671 if( static_cast<int>(ref.bit) > static_cast<int>(TEnd))
672 ref.bit= TInterface(TEnd);
673 continue;
674 }
675
676 // found one
677 ref.bit= TInterface( static_cast<int>(ref.bit) + trailingZeros - bIdx);
678 break;
679 }
680 return *this;
681 }
682
683 /// Searches and moves this iterator to the next lower bit is. In case no lower bit is
684 /// found, the iterator will points to illegal bit number <c>-1</c>.
685 /// @return A reference to this object.
687 {
688 // next bit
689 ref.bit= TInterface(static_cast<int>(ref.bit) - 1);
690
691 // search next bit from here
692 while(static_cast<int>(ref.bit) >= static_cast<int>(TBegin))
693 {
694 int bIdx= bitIdx(ref.bit);
695 TWord word= ref.bitSet->word(ref.bit)
696 & TWord( TWord (~TWord(0)) >> (bitsof(TWord)- bIdx -1) );
697 // a lower mask, but not precisely LowerMask.
698 //...and yes, we need all these castings :-/
699 // search
700 int leadingZeros;
701 if( word == 0
702 || ((leadingZeros= CLZ<TWord>( word )) == bitsof(TWord) ) )
703 {
704 // not found in this word
705 ref.bit= TInterface(static_cast<int>(ref.bit) - bIdx -1);
706 if( static_cast<int>(ref.bit) < static_cast<int>(TBegin) -1)
707 ref.bit= TInterface( static_cast<int>(TBegin) - 1);
708 continue;
709 }
710
711 // found one
712 ref.bit= TInterface( static_cast<int>(ref.bit)
713 + (bitsof(TWord) - (bIdx + 1) ) // first correct to upper bit position
714 - leadingZeros ); // then subtract leading zeros
715 break;
716 }
717 return *this;
718 }
719
720 public:
721 /// Constructor.
722 /// @param bitSet The bit set to use.
723 /// @param startBit The bit number to start with.
724 explicit TBidiIterator( TBitSetCM& bitSet, TInterface startBit )
725 : ref(bitSet, startBit)
726 {}
727
728 //###################### To satisfy concept of InputIterator ######################
729 /// Prefix increment operator.
730 /// @return A reference to this object.
732 {
733 if constexpr (!isReverse) return up();
734 return down();
735 }
736
737 /// Postfix increment operator.
738 /// @return An iterator value that is not increased, yet.
740 {
741 auto result= *this;
742 ++*this;
743 return result;
744 }
745
746 /// Comparison operator.
747 /// @param other The iterator to compare ourselves to.
748 /// @return \c true if this and the given iterator are pointing to the same bit in the same
749 /// set, \c false otherwise.
750 bool operator==(const TBidiIterator& other) const
751 {
752 return ref == other.ref;
753 }
754
755 /// Comparison operator.
756 /// @param other The iterator to compare ourselves to.
757 /// @return \c true if this and given iterator are not equal, \c false otherwise.
758 bool operator!=(const TBidiIterator& other) const
759 {
760 return !(*this == other);
761 }
762
763 /// Retrieves a reference to the internal \alib{lang::TBitSet;Reference} member that this
764 /// iterator uses.
765 /// @return The reference to the bit this iterator is currently addressing.
767 {
768 return ref;
769 }
770
771 //################## To satisfy concept of BidirectionalIterator ##################
772 /// Prefix decrement operator.
773 /// @return A reference to this object.
775 {
776 if constexpr (isReverse) return up();
777 return down();
778 }
779
780 /// Postfix decrement operator.
781 /// @return The iterator value prior the decrement operation.
783 {
784 auto result= *this;
785 --*this;
786 return result;
787 }
788
789 //#### Comparison operators ###
790 /// Compares this iterator with the given one.
791 /// @param other The iterator to compare
792 /// @return \c true if this iterator is \e smaller than \p{other},
793 /// \c false otherwise.
794 bool operator<(TBidiIterator other) const
795 { return ref.bit < other.ref.bit; }
796
797 /// Compares this iterator with the given one.
798 /// @param other The iterator to compare
799 /// @return \c true if this iterator is \e smaller than or equal to \p{other},
800 /// \c false otherwise.
801 bool operator<=(TBidiIterator other) const
802 { return ref.bit <= other.ref.bit; }
803
804 /// Compares this iterator with the given one.
805 /// @param other The iterator to compare
806 /// @return \c true if this iterator is \e greater than \p{other},
807 /// \c false otherwise.
808 bool operator>(TBidiIterator other) const
809 { return ref.bit > other.ref.bit; }
810
811 /// Compares this iterator with the given one.
812 /// @param other The iterator to compare
813 /// @return \c true if this iterator is \e greater than or equal to \p{other},
814 /// \c false otherwise.
815 bool operator>=(TBidiIterator other) const
816 { return ref.bit >= other.ref.bit; }
817 }; // class TBidiIterator
818
819 public:
820 /// Iterator type, implementing the standard library concept of
821 /// \https{RandomAccessIterator,en.cppreference.com/w/cpp/concept/RandomAccessIterator}.
823
824 /// Same as #Iterator, but working from the end to the start of the \b TBitSet.
826
827 /// The constant iterator type.
829
830 /// Same as #ConstIterator, but working from the end to the start of the \b TBitSet.
832
833 /// Returns an iterator pointing to the first (lowest) bit set.
834 /// @param skip Defaults to \c 0. If set, denotes the amount of bits which are not examined
835 /// at the beginning of the iteration. Must not be negative.
836 /// @return The start iterator. In case no bit is set, the same as #end.
837 Iterator begin(int skip= 0) { return ++Iterator(*this, TInterface(TBegin - 1) + skip); }
838
839 /// Returns an iterator pointing to the non-existing bit behind the highest one.
840 /// @return The end iterator.
841 Iterator end() { return Iterator(*this, TInterface(TEnd) ); }
842
843 /// Returns a reverse iterator pointing to the last (highest) bit set.
844 /// @param skip Defaults to \c 0. If set, denotes the amount of bits which are not examined
845 /// at the beginning of the iteration. Must not be negative.
846 /// @return The reverse iteration start.
847 ReverseIterator rbegin(int skip= 0) { return ++ReverseIterator(*this, TInterface(TEnd) - skip ); }
848
849 /// Returns an iterator pointing to the non-existing bit before the lowest one.
850 /// @return The reverse iteratation end.
851 ReverseIterator rend() { return ReverseIterator(*this, TInterface(TBegin-1) ); }
852
853 /// Returns a const iterator pointing to the first (lowest) bit set.
854 /// @param skip Defaults to \c 0. If set, denotes the amount of bits which are not examined
855 /// at the beginning of the iteration. Must not be negative.
856 /// @return The start iterator. In case no bit is set, the same as #end.
857 ConstIterator begin(int skip= 0) const { return ++ConstIterator(*this, TInterface(TBegin-1) + skip ); }
858
859 /// Returns a const iterator pointing to the first (lowest) bit set.
860 /// @param skip Defaults to \c 0. If set, denotes the amount of bits which are not examined
861 /// at the beginning of the iteration. Must not be negative.
862 /// @return The start iterator. In case no bit is set, the same as #end.
863 ConstIterator cbegin(int skip= 0) const { return ++ConstIterator(*this, TInterface(TBegin-1) + skip ); }
864
865 /// Returns a const iterator pointing to the non-existing bit behind the highest one.
866 /// @return The end iterator.
867 ConstIterator end() const { return ConstIterator(*this, TInterface(TEnd) ); }
868
869 /// Returns a const iterator pointing to the non-existing bit behind the highest one.
870 /// @return The end iterator.
871 ConstIterator cend() const { return ConstIterator(*this, TInterface(TEnd) ); }
872
873 /// Returns a const reverse iterator pointing to the last (highest) bit set.
874 /// @param skip Defaults to \c 0. If set, denotes the amount of bits which are not examined
875 /// at the beginning of the iteration. Must not be negative.
876 /// @return The reverse iteration start.
877 ConstReverseIterator rbegin(int skip= 0)const { return ++ConstReverseIterator(*this, TInterface(TEnd - skip) ); }
878
879 /// Returns a const iterator pointing to the non-existing bit before the lowest one.
880 /// @return The reverse iteratation end.
881 ConstReverseIterator rend() const { return ConstReverseIterator(*this, TInterface(TBegin-1) ); }
882
883 /// Returns a const reverse iterator pointing to the last (highest) bit set.
884 /// @param skip Defaults to \c 0. If set, denotes the amount of bits which are not examined
885 /// at the beginning of the iteration. Must not be negative.
886 /// @return The reverse iteration start.
887 ConstReverseIterator crbegin(int skip=0)const { return ++ConstReverseIterator(*this, TInterface(TEnd - skip) ); }
888
889 /// Returns a const iterator pointing to the non-existing bit before the lowest one.
890 /// @return The reverse iteratation end.
891 ConstReverseIterator crend() const { return ConstReverseIterator(*this, TInterface(TBegin-1) ); }
892
893}; // class TBitSet
894
895} // namespace alib[::lang]
896
897DOX_MARKER([DOX_MANUAL_ALIASES_BITSET])
898/// Type alias in namespace \b alib.
899template<int TEnd, int TBegin= 0, typename TInterface= int>
901DOX_MARKER([DOX_MANUAL_ALIASES_BITSET])
902
903} // namespace [alib]
904
905// ------------------------ global operators on class TBitSet ---------------------------------
906// For documentation, these global operators are faked into namespace alib
907#if DOXYGEN
908namespace alib {
909#endif
910
911/// Performs binary AND operation two \b TBitSet objects (of equal size), \p{lhs} and \p{rhs}.
912/// \note This operator function is located in the global namespace. The documentation shows
913/// namespace <em>alib</em>, which is done for the purposes of organizing the manual
914/// index better.
915/// @param lhs The left hand side operand.
916/// @param rhs The right hand side operand.
917/// @tparam TEnd Template parameter of class \b TBitSet. Deduced by the compiler.
918/// @tparam TBegin Template parameter of class \b TBitSet. Deduced by the compiler.
919/// @tparam TInterface Template parameter of class \b TBitSet. Deduced by the compiler.
920/// @return A temporary \b TBitSet containing the result of the operation.
921template<typename TInterface, TInterface TEnd, TInterface TBegin>
925{
929 result.Import( lhs.Export() & rhs.Export() );
930 else
931 for (int w = 0; w < alib::lang::TBitSet<TInterface,TEnd,TBegin>::QtyWords; ++w)
932 result.Import( lhs.Export(w) & rhs.Export(w), w );
933 return result;
934}
935
936/// Performs binary OR operation two \b TBitSet objects (of equal size), \p{lhs} and \p{rhs}.
937/// \note This operator function is located in the global namespace. The documentation shows
938/// namespace <em>alib</em>, which is done for the purposes of organizing the manual
939/// index better.
940/// @param lhs The left hand side operand.
941/// @param rhs The right hand side operand.
942/// @tparam TEnd Template parameter of class \b TBitSet. Deduced by the compiler.
943/// @tparam TBegin Template parameter of class \b TBitSet. Deduced by the compiler.
944/// @tparam TInterface Template parameter of class \b TBitSet. Deduced by the compiler.
945/// @return A temporary \b TBitSet containing the result of the operation.
946template<typename TInterface, TInterface TEnd, TInterface TBegin>
950{
954 result.Import( lhs.Export() | rhs.Export() );
955 else
956 for (int w = 0; w < alib::lang::TBitSet<TInterface,TEnd,TBegin>::QtyWords; ++w)
957 result.Import( lhs.Export(w) | rhs.Export(w), w );
958 return result;
959}
960
961/// Performs binary XOR operation two \b TBitSet objects (of equal size), \p{lhs} and \p{rhs}.
962/// \note This operator function is located in the global namespace. The documentation shows
963/// namespace <em>alib</em>, which is done for the purposes of organizing the manual
964/// index better.
965/// @param lhs The left hand side operand.
966/// @param rhs The right hand side operand.
967/// @tparam TEnd Template parameter of class \b TBitSet. Deduced by the compiler.
968/// @tparam TBegin Template parameter of class \b TBitSet. Deduced by the compiler.
969/// @tparam TInterface Template parameter of class \b TBitSet. Deduced by the compiler.
970/// @return A temporary \b TBitSet containing the result of the operation.
971template<typename TInterface, TInterface TEnd, TInterface TBegin>
975{
979 result.Import( lhs.Export() ^ rhs.Export() );
980 else
981 for (int w = 0; w < alib::lang::TBitSet<TInterface,TEnd,TBegin>::QtyWords; ++w)
982 result.Import( lhs.Export(w) ^ rhs.Export(w), w );
983 return result;
984}
985#if DOXYGEN
986} // namespace [alib]
987#endif
989
990#endif // HPP_ALIB_LANG_BITSET
991
constexpr Reference(TBitSetCM &set, TInterface b) noexcept
Definition bitset.hpp:179
constexpr const class TBitSet & TBitSet() const noexcept
Definition bitset.hpp:207
constexpr bool operator~() noexcept
Definition bitset.hpp:223
constexpr bool operator==(const Reference &rhs) const noexcept=default
TBitSetCM * bitSet
The TBitSet this reference addresses.
Definition bitset.hpp:171
TInterface bit
The bit number in bitSet this reference addresses.
Definition bitset.hpp:170
Reference & operator=(const Reference &other) noexcept=default
constexpr TInterface Bit() const noexcept
Definition bitset.hpp:197
constexpr Reference & Flip() noexcept
Definition bitset.hpp:228
constexpr class TBitSet & TBitSet() noexcept
Definition bitset.hpp:202
constexpr Reference(const Reference &) noexcept=default
Defaulted copy constructor.
constexpr Reference & operator=(bool val) noexcept
Definition bitset.hpp:213
~Reference() noexcept
Destructor. (Is declared constexpr with C++23.)
Definition bitset.hpp:187
int difference_type
Implementation of std::iterator_traits.
Definition bitset.hpp:640
bool operator<=(TBidiIterator other) const
Definition bitset.hpp:801
std::bidirectional_iterator_tag iterator_category
Implementation of std::iterator_traits.
Definition bitset.hpp:638
bool operator<(TBidiIterator other) const
Definition bitset.hpp:794
void pointer
Implementation of std::iterator_traits.
Definition bitset.hpp:641
bool operator==(const TBidiIterator &other) const
Definition bitset.hpp:750
TBidiIterator operator--(int)
Definition bitset.hpp:782
TBidiIterator operator++(int)
Definition bitset.hpp:739
TInterface value_type
Implementation of std::iterator_traits.
Definition bitset.hpp:639
bool operator>(TBidiIterator other) const
Definition bitset.hpp:808
Reference< TBitSetCM > ref
Definition bitset.hpp:648
bool operator>=(TBidiIterator other) const
Definition bitset.hpp:815
TBidiIterator(TBitSetCM &bitSet, TInterface startBit)
Definition bitset.hpp:724
bool operator!=(const TBidiIterator &other) const
Definition bitset.hpp:758
TBidiIterator< const TBitSet, false > ConstIterator
The constant iterator type.
Definition bitset.hpp:828
ConstIterator cend() const
Definition bitset.hpp:871
constexpr bool All() const noexcept
Definition bitset.hpp:370
constexpr TBitSet & operator^=(const TBitSet &rhs) noexcept
Definition bitset.hpp:500
constexpr bool None() const noexcept
Definition bitset.hpp:392
constexpr int Count() const noexcept
Definition bitset.hpp:359
constexpr TBitSet operator>>(int cnt) const noexcept
Definition bitset.hpp:593
TBidiIterator< TBitSet, true > ReverseIterator
Same as Iterator, but working from the end to the start of the TBitSet.
Definition bitset.hpp:825
constexpr bool operator==(const TBitSet &rhs) const noexcept
Definition bitset.hpp:471
constexpr TBitSet & operator>>=(int cnt) noexcept
Definition bitset.hpp:599
TBidiIterator< TBitSet, false > Iterator
Definition bitset.hpp:822
TWord words[QtyWords ? QtyWords :1]
Definition bitset.hpp:104
constexpr TWord & Export(int wordIdx) noexcept
Definition bitset.hpp:413
constexpr TBitSet & Set(TInterface firstBit, T &&... furtherBits) noexcept
Definition bitset.hpp:301
constexpr bool Any() const noexcept
Definition bitset.hpp:381
constexpr TBitSet & Reset(TInterface firstBit, T &&... furtherBits) noexcept
Definition bitset.hpp:315
constexpr TBitSet & Set(TInterface bit, bool val) noexcept
Definition bitset.hpp:288
ConstReverseIterator rend() const
Definition bitset.hpp:881
constexpr TWord & word(TInterface b) noexcept
Definition bitset.hpp:127
constexpr TBitSet & operator<<=(int cnt) noexcept
Definition bitset.hpp:587
TBidiIterator< const TBitSet, true > ConstReverseIterator
Same as ConstIterator, but working from the end to the start of the TBitSet.
Definition bitset.hpp:831
constexpr Reference< TBitSet > operator[](TInterface bit) noexcept
Definition bitset.hpp:606
constexpr TBitSet & Reset() noexcept
Sets all bits to 0.
Definition bitset.hpp:341
Iterator begin(int skip=0)
Definition bitset.hpp:837
ConstReverseIterator rbegin(int skip=0) const
Definition bitset.hpp:877
constexpr TBitSet operator<<(int cnt) const noexcept
Definition bitset.hpp:581
constexpr TBitSet() noexcept
Default constructor initializing all bits to not set.
Definition bitset.hpp:248
constexpr bool Test(TInterface bit) noexcept
Definition bitset.hpp:350
static constexpr TWord mask1101(TInterface b) noexcept
Definition bitset.hpp:153
ConstIterator cbegin(int skip=0) const
Definition bitset.hpp:863
ConstIterator end() const
Definition bitset.hpp:867
ConstIterator begin(int skip=0) const
Definition bitset.hpp:857
constexpr TBitSet(const std::nullptr_t &) noexcept
Definition bitset.hpp:256
constexpr const TWord & word(TInterface b) const noexcept
Definition bitset.hpp:132
ATMP_IF_T_F((Capacity > bitsof(long)), unsigned long long, ATMP_IF_T_F((Capacity > bitsof(int)), unsigned long, ATMP_IF_T_F((Capacity > bitsof(short)), unsigned int, ATMP_IF_T_F((Capacity > bitsof(char)), unsigned short, unsigned char)))) TWord
Definition bitset.hpp:90
static constexpr int QtyWords
The size of the TWord array containing the bits.
Definition bitset.hpp:98
static constexpr int bitIdx(TInterface b) noexcept
Definition bitset.hpp:116
constexpr TBitSet & Flip(TInterface firstBit, T &&... furtherBits) noexcept
Definition bitset.hpp:329
constexpr bool operator!=(const TBitSet &rhs) const noexcept
Definition bitset.hpp:484
constexpr const Reference< const TBitSet > operator[](int bit) const noexcept
Definition bitset.hpp:613
ReverseIterator rbegin(int skip=0)
Definition bitset.hpp:847
static constexpr int Capacity
Definition bitset.hpp:84
ReverseIterator rend()
Definition bitset.hpp:851
constexpr TBitSet & operator|=(const TBitSet &rhs) noexcept
Definition bitset.hpp:495
static constexpr TWord mask0010(TInterface b) noexcept
Definition bitset.hpp:148
constexpr TBitSet & Flip() noexcept
Flips all bits from 0 to 1 and vice versa.
Definition bitset.hpp:343
ConstReverseIterator crbegin(int skip=0) const
Definition bitset.hpp:887
constexpr TWord & Import(TWord val, int wordIdx) noexcept
Definition bitset.hpp:448
constexpr TBitSet & operator&=(const TBitSet &rhs) noexcept
Definition bitset.hpp:490
static constexpr int wordIdx(TInterface b) noexcept
Definition bitset.hpp:110
constexpr const TWord & Export(int wordIdx) const noexcept
Definition bitset.hpp:421
ConstReverseIterator crend() const
Definition bitset.hpp:891
constexpr TBitSet & Set() noexcept
Sets all bits to 1.
Definition bitset.hpp:339
constexpr TBitSet operator~() const noexcept
Definition bitset.hpp:504
constexpr TBitSet(TWord preset) noexcept
Definition bitset.hpp:262
constexpr void shiftLeft(int cnt, TBitSet &target) const noexcept
Definition bitset.hpp:518
constexpr TBitSet(bool preset) noexcept
Definition bitset.hpp:273
constexpr void shiftRight(int cnt, TBitSet &target) const noexcept
Definition bitset.hpp:550
static constexpr TWord mask(int wIdx) noexcept
Definition bitset.hpp:138
#define ATMP_IF_T_F( Cond, T, F)
Definition tmp.hpp:50
#define bitsof(type)
Definition bits.hpp:49
#define ALIB_WARNINGS_RESTORE
Definition alib.hpp:849
#define ALIB_CPP_23(...)
Definition alib.hpp:628
#define ALIB_ASSERT_ERROR(cond,...)
Definition alib.hpp:1271
#define ALIB_WARNINGS_ALLOW_UNSAFE_BUFFER_USAGE
Definition alib.hpp:760
constexpr int BitCount(TIntegral value)
constexpr int CLZ(TIntegral value)
constexpr TIntegral LowerMask()
constexpr int CTZ(TIntegral value)
constexpr TIntegral UpperMask()
Definition alib.cpp:69
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
Definition bitset.hpp:972
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
Definition bitset.hpp:947
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
Definition bitset.hpp:922