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