This class is an improved replica of std::bitset
and hence stores and exposes a set of bits. The differences (advantages) of this class to the standard type are:
char
, short
, int
, long
and long long
. If even larger bitsets are requested, the size becomes a multiple of the size of long long
.int
to a custom type which is statically castable to int
, by providing specifying template parameter TInterface accordingly. This avoids the need for statically casting the index type with every invocation of an interface method.0
and in this case avoids the need for subtraction of the (fixed) start value of a range with every invocation of an interface method.std::bitset<N>::to_ulong() / to_ullong()
, the standard type allows the export of the internal value only to 64-bit values (on common platforms). If the higher bits are to be exported, the bitset has to be shifted, which is inefficient and destructive (a copy has to be taken).In respect to performance, this type equals a typical implementation std::bitset
.
int
.TInterface | The interface type to denote bit position values. This type has to be statically castable to and constructible from int . |
TEnd | The last index of the interface type plus 1 . |
TBegin | The first index of the interface type. (Defaults to 0 .) |
Definition at line 70 of file bitset.hpp.
#include <bitset.hpp>
Inner Type Index: | |
class | Reference |
class | TBidiIterator |
Public Type Index: | |
using | ConstIterator = TBidiIterator<const TBitSet, false> |
using | ConstReverseIterator = TBidiIterator<const TBitSet, true> |
using | Iterator = TBidiIterator<TBitSet, false> |
using | ReverseIterator = TBidiIterator<TBitSet, true> |
using | TWord |
Public Static Field Index: | |
static constexpr int | Capacity |
static constexpr int | QtyWords |
Public Method Index: | |
constexpr | TBitSet () noexcept |
constexpr | TBitSet (bool preset) noexcept |
constexpr | TBitSet (const TOmitInitialization &) noexcept |
constexpr | TBitSet (TWord preset) noexcept |
constexpr bool | All () const noexcept |
constexpr bool | Any () const noexcept |
Iterator | begin (int skip=0) |
ConstIterator | begin (int skip=0) const |
ConstIterator | cbegin (int skip=0) const |
ConstIterator | cend () const |
constexpr int | Count () const noexcept |
ConstReverseIterator | crbegin (int skip=0) const |
ConstReverseIterator | crend () const |
Iterator | end () |
ConstIterator | end () const |
constexpr const TWord & | Export (int wordIdx) const noexcept |
constexpr TWord & | Export (int wordIdx) noexcept |
constexpr TBitSet & | Flip () noexcept |
template<typename... T> | |
constexpr TBitSet & | Flip (TInterface bit, T &&... args) noexcept |
constexpr TWord & | Import (TWord val, int wordIdx) noexcept |
constexpr bool | None () const noexcept |
constexpr bool | operator!= (const TBitSet &rhs) const noexcept |
constexpr TBitSet & | operator&= (const TBitSet &rhs) noexcept |
constexpr TBitSet | operator<< (int cnt) const noexcept |
constexpr TBitSet & | operator<<= (int cnt) noexcept |
constexpr bool | operator== (const TBitSet &rhs) const noexcept |
constexpr TBitSet | operator>> (int cnt) const noexcept |
constexpr TBitSet & | operator>>= (int cnt) noexcept |
constexpr const Reference< const TBitSet > | operator[] (int bit) const noexcept |
constexpr Reference< TBitSet > | operator[] (TInterface bit) noexcept |
constexpr TBitSet & | operator^= (const TBitSet &rhs) noexcept |
constexpr TBitSet & | operator|= (const TBitSet &rhs) noexcept |
constexpr TBitSet | operator~ () const noexcept |
ReverseIterator | rbegin (int skip=0) |
ConstReverseIterator | rbegin (int skip=0) const |
ReverseIterator | rend () |
ConstReverseIterator | rend () const |
constexpr TBitSet & | Reset () noexcept |
template<typename... T> | |
constexpr TBitSet & | Reset (TInterface bit, T &&... args) noexcept |
constexpr TBitSet & | Set () noexcept |
template<typename... T> | |
constexpr TBitSet & | Set (TInterface bit, bool val) noexcept |
template<typename... T> | |
constexpr TBitSet & | Set (TInterface bit, T &&... args) noexcept |
constexpr bool | Test (TInterface bit) noexcept |
using ConstIterator = TBidiIterator<const TBitSet, false> |
The constant iterator type.
Definition at line 833 of file bitset.hpp.
using ConstReverseIterator = TBidiIterator<const TBitSet, true> |
Same as ConstIterator, but working from the end to the start of the TBitSet.
Definition at line 836 of file bitset.hpp.
using Iterator = TBidiIterator<TBitSet, false> |
Iterator type, implementing the standard library concept of RandomAccessIterator .
Definition at line 827 of file bitset.hpp.
using ReverseIterator = TBidiIterator<TBitSet, true> |
Same as Iterator, but working from the end to the start of the TBitSet.
Definition at line 830 of file bitset.hpp.
using TWord |
The type that is used to store the bits in. TMP code chooses the smallest fitting integral. If Capacity exceeds type long long
, an array of long long
, field QtyWords will become greater than 1
.
Definition at line 91 of file bitset.hpp.
|
staticconstexpr |
The number of bits in the range resulting from template parameters TBegin and TEnd .
Definition at line 85 of file bitset.hpp.
|
staticconstexpr |
The size of the TWord array containing the bits
Definition at line 99 of file bitset.hpp.
|
protected |
The array of integrals containing the bits needed. The unused upper bits in the last word are always kept 0
.
Definition at line 105 of file bitset.hpp.
|
inlineconstexprnoexcept |
Default constructor initializing all bits to not set.
Definition at line 249 of file bitset.hpp.
|
inlineconstexprnoexcept |
Constructor taking a dummy object. This constructor omits any value initialization and has to be called by providing TOmitInitialization()
as the argument.
Definition at line 258 of file bitset.hpp.
|
inlineconstexprnoexcept |
Constructor which takes an external TWord which initializes the first word. If constexpr
field QtyWords is greater than 1
, the other bits are set to 0
and can be set using method Import or of-course using other interface methods.
preset | The preset value for the bits. |
Definition at line 264 of file bitset.hpp.
|
inlineconstexprnoexcept |
Constructor which takes an external TWord which initializes the first word. If constexpr
field QtyWords is greater than 1
, the other bits are set to 0
and can be set using method Import or of-course using other interface methods.
preset | The preset value for the bits. |
Definition at line 275 of file bitset.hpp.
|
inlineconstexprnoexcept |
Tests if any bit is set.
true
if all bits are set, false
otherwise. Definition at line 372 of file bitset.hpp.
|
inlineconstexprnoexcept |
Tests if any bit is set.
true
if at least one bit is set, false
otherwise. Definition at line 383 of file bitset.hpp.
|
inline |
Returns an iterator pointing to the first (lowest) bit set.
skip | Defaults to 0 . If set, denotes the amount of bits which are not examined at the beginning of the iteration. Must not be negative. |
Definition at line 842 of file bitset.hpp.
|
inline |
Returns a const iterator pointing to the first (lowest) bit set.
skip | Defaults to 0 . If set, denotes the amount of bits which are not examined at the beginning of the iteration. Must not be negative. |
Definition at line 862 of file bitset.hpp.
|
inlinestaticconstexprprotectednoexcept |
Helper to determine the bit index in the actual word.
b | The absolute index. |
Definition at line 117 of file bitset.hpp.
|
inline |
Returns a const iterator pointing to the first (lowest) bit set.
skip | Defaults to 0 . If set, denotes the amount of bits which are not examined at the beginning of the iteration. Must not be negative. |
Definition at line 868 of file bitset.hpp.
|
inline |
Returns a const iterator pointing to the non-existing bit behind the highest one.
Definition at line 876 of file bitset.hpp.
|
inlineconstexprnoexcept |
Returns the number of bits set to true
in this set.
Definition at line 361 of file bitset.hpp.
|
inline |
Returns a const reverse iterator pointing to the last (highest) bit set.
skip | Defaults to 0 . If set, denotes the amount of bits which are not examined at the beginning of the iteration. Must not be negative. |
Definition at line 892 of file bitset.hpp.
|
inline |
Returns a const iterator pointing to the non-existing bit before the lowest one.
Definition at line 896 of file bitset.hpp.
|
inline |
Returns an iterator pointing to the non-existing bit behind the highest one.
Definition at line 846 of file bitset.hpp.
|
inline |
Returns a const iterator pointing to the non-existing bit behind the highest one.
Definition at line 872 of file bitset.hpp.
|
inlineconstexprnoexcept |
Const version of Export.
wordIdx | The subset of bits to receive. ATTENTION: See non-constant variant Export on this parameter! |
Definition at line 425 of file bitset.hpp.
|
inlineconstexprnoexcept |
Exports the internal integral(s) holding the bits.
sizeof(long long) * 8
. In that case, field QtyWords provides the number of words that are exportable.0
adresses bits 0..63, 1
bits 64..127 and so forth.wordIdx | The subset of bits to receive. |
Definition at line 416 of file bitset.hpp.
|
inlineconstexprnoexcept |
Flips all bits from 0
to 1
and vice versa.
Definition at line 345 of file bitset.hpp.
|
inlineconstexprnoexcept |
Flips one or more bits from 0
to 1
and vice versa.
bit | The index of the bit to flip. |
args | An optional continued list of indices of bits to flip. |
this
object. Definition at line 331 of file bitset.hpp.
|
inlineconstexprnoexcept |
Imports the data from (a) given integral(s).
sizeof(long long) * 8
. In that case, field QtyWords provides the number of words that are importable.0
adresses bits 0..63, 1
bits 64..127 and so forth.val | The value to import. |
wordIdx | The subset of bits to overwrite. |
Definition at line 453 of file bitset.hpp.
|
inlinestaticconstexprprotectednoexcept |
Returns a bitmask with all used bits set.
wIdx | The index of the word in array words. |
-1
, and a mask that covers the remaining bits if wIdx targets the last word. Definition at line 139 of file bitset.hpp.
|
inlinestaticconstexprprotectednoexcept |
Returns a bitmask with only the given bit set.
b | The index of the bit to set. |
Definition at line 149 of file bitset.hpp.
|
inlinestaticconstexprprotectednoexcept |
Returns a bitmask with only the given bit unset.
b | The index of the bit to unset. |
Definition at line 154 of file bitset.hpp.
|
inlineconstexprnoexcept |
Tests if not any bit is set.
false
if at least one bit is set, true
otherwise. Definition at line 394 of file bitset.hpp.
|
inlineconstexprnoexcept |
Compares this bitset with another bitset of equal size.
(Available with C++ versions below 20. Afterwards synthesized.
rhs | The other TBitSet to compare this with. |
false
if all bits are equal, true
otherwise. Definition at line 489 of file bitset.hpp.
|
inlineconstexprnoexcept |
Sets the bits to the result of binary AND on corresponding pairs of bits of this
and other.
rhs | The other TBitSet to compare this with. |
this
object. Definition at line 495 of file bitset.hpp.
|
inlineconstexprnoexcept |
Returns a temporary copy of this with a shift to the left (towards higher index positions).
cnt | The number of positions to shift. |
Definition at line 586 of file bitset.hpp.
|
inlineconstexprnoexcept |
Shifts the bits of this object to the left left (towards higher index positions).
cnt | The number of positions to shift. |
Definition at line 592 of file bitset.hpp.
|
inlineconstexprnoexcept |
Compares this bitset with another bitset of equal size.
rhs | The other TBitSet to compare this with. |
true
if all bits are equal, false
otherwise. Definition at line 476 of file bitset.hpp.
|
inlineconstexprnoexcept |
Returns a temporary copy of this with a shift to the right (towards lower index positions).
cnt | The number of positions to shift. |
Definition at line 598 of file bitset.hpp.
|
inlineconstexprnoexcept |
Shifts the bits of this object to the left right (towards lower index positions).
cnt | The number of positions to shift. |
Definition at line 604 of file bitset.hpp.
|
inlineconstexprnoexcept |
Returns a const
reference to a specific bit.
bit | The bit to create a reference for. |
Definition at line 618 of file bitset.hpp.
|
inlineconstexprnoexcept |
Returns a reference to a specific bit.
bit | The bit to create a reference for. |
Definition at line 611 of file bitset.hpp.
|
inlineconstexprnoexcept |
Sets the bits to the result of binary XOR on corresponding pairs of bits of this
and other.
rhs | The other TBitSet to compare this with. |
this
object. Definition at line 505 of file bitset.hpp.
|
inlineconstexprnoexcept |
Sets the bits to the result of binary OR on corresponding pairs of bits of this
and other.
rhs | The other TBitSet to compare this with. |
this
object. Definition at line 500 of file bitset.hpp.
|
inlineconstexprnoexcept |
Returns a temporary copy of this
with all bits flipped (binary NOT)..
Definition at line 509 of file bitset.hpp.
|
inline |
Returns a reverse iterator pointing to the last (highest) bit set.
skip | Defaults to 0 . If set, denotes the amount of bits which are not examined at the beginning of the iteration. Must not be negative. |
Definition at line 852 of file bitset.hpp.
|
inline |
Returns a const reverse iterator pointing to the last (highest) bit set.
skip | Defaults to 0 . If set, denotes the amount of bits which are not examined at the beginning of the iteration. Must not be negative. |
Definition at line 882 of file bitset.hpp.
|
inline |
Returns an iterator pointing to the non-existing bit before the lowest one.
Definition at line 856 of file bitset.hpp.
|
inline |
Returns a const iterator pointing to the non-existing bit before the lowest one.
Definition at line 886 of file bitset.hpp.
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
Sets one or more bits to 0
.
bit | The index of the bit to clear. |
args | An optional continued list of indices of bits to clear. |
this
object. Definition at line 317 of file bitset.hpp.
|
inlineconstexprnoexcept |
Sets all bits to 1
.
Definition at line 341 of file bitset.hpp.
|
inlineconstexprnoexcept |
Sets the bit to 1
.
bit | The index of the bit to set. |
val | true or false to set or clear bit bit . |
this
object. Definition at line 290 of file bitset.hpp.
|
inlineconstexprnoexcept |
Sets one or more bits to 1
.
bit | The index of the bit to set. |
args | An optional continued list of indices of bits to set. |
this
object. Definition at line 303 of file bitset.hpp.
|
inlineconstexprprotectednoexcept |
Stores a shifted result in target . This protected method is accessible via operator<<()
(which creates and returns a temporary target) and operator<<=()
, which passes this
to parameter target .
cnt | The number of positions to shift. |
target | The target object. |
Definition at line 523 of file bitset.hpp.
|
inlineconstexprprotectednoexcept |
Stores a shifted result in target . This protected method is accessible via operator>>()
(which creates and returns a temporary target) and operator>>=()
, which passes this
to parameter target .
cnt | The number of positions to shift. |
target | The target object. |
Definition at line 555 of file bitset.hpp.
|
inlineconstexprnoexcept |
Returns true
if the bit is set, false
otherwise.
bit | Denotes the bit to test. |
Definition at line 352 of file bitset.hpp.
|
inlineconstexprprotectednoexcept |
Helper receive a const
reference word from the array of words.
b | The bit to address index. |
Definition at line 133 of file bitset.hpp.
|
inlineconstexprprotectednoexcept |
Helper receive the word from the array of words.
b | The bit to address index. |
Definition at line 128 of file bitset.hpp.
|
inlinestaticconstexprprotectednoexcept |
Helper to determine the bit index in the actual word.
b | The absolute index. |
Definition at line 111 of file bitset.hpp.