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 69 of file bitset.hpp.
#include <bitset.hpp>
Inner Type Index: | |
class | Reference |
class | TBidiIterator |
Public Type Index: | |
using | ConstIterator = TBidiIterator<const TBitSet, false> |
The constant iterator type. | |
using | ConstReverseIterator = TBidiIterator<const TBitSet, true> |
Same as ConstIterator, but working from the end to the start of the TBitSet. | |
using | Iterator = TBidiIterator<TBitSet, false> |
using | ReverseIterator = TBidiIterator<TBitSet, true> |
Same as Iterator, but working from the end to the start of the TBitSet. | |
using | TWord |
Public Static Field Index: | |
static constexpr int | Capacity |
static constexpr int | QtyWords |
The size of the TWord array containing the bits. | |
Public Method Index: | |
constexpr | TBitSet () noexcept |
Default constructor initializing all bits to not set. | |
constexpr | TBitSet (bool preset) noexcept |
constexpr | TBitSet (const std::nullptr_t &) 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 |
Flips all bits from 0 to 1 and vice versa. | |
template<typename... T> | |
constexpr TBitSet & | Flip (TInterface firstBit, T &&... furtherBits) 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 |
Sets all bits to 0 . | |
template<typename... T> | |
constexpr TBitSet & | Reset (TInterface firstBit, T &&... furtherBits) noexcept |
constexpr TBitSet & | Set () noexcept |
Sets all bits to 1 . | |
template<typename... T> | |
constexpr TBitSet & | Set (TInterface bit, bool val) noexcept |
template<typename... T> | |
constexpr TBitSet & | Set (TInterface firstBit, T &&... furtherBits) noexcept |
constexpr bool | Test (TInterface bit) noexcept |
Protected Static Method Index: | |
static constexpr int | bitIdx (TInterface b) noexcept |
static constexpr TWord | mask (int wIdx) noexcept |
static constexpr TWord | mask0010 (TInterface b) noexcept |
static constexpr TWord | mask1101 (TInterface b) noexcept |
static constexpr int | wordIdx (TInterface b) noexcept |
Protected Field Index: | |
TWord | words [QtyWords ? QtyWords :1] |
Protected Method Index: | |
constexpr void | shiftLeft (int cnt, TBitSet &target) const noexcept |
constexpr void | shiftRight (int cnt, TBitSet &target) const noexcept |
constexpr const TWord & | word (TInterface b) const noexcept |
constexpr TWord & | word (TInterface b) noexcept |
using ConstIterator = TBidiIterator<const TBitSet, false> |
The constant iterator type.
Definition at line 828 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 831 of file bitset.hpp.
using Iterator = TBidiIterator<TBitSet, false> |
Iterator type, implementing the standard library concept of RandomAccessIterator .
Definition at line 822 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 825 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 90 of file bitset.hpp.
|
staticconstexpr |
The number of bits in the range resulting from template parameters TBegin and TEnd.
Definition at line 84 of file bitset.hpp.
|
staticconstexpr |
The size of the TWord array containing the bits.
Definition at line 98 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 104 of file bitset.hpp.
|
inlineconstexprnoexcept |
Default constructor initializing all bits to not set.
Definition at line 248 of file bitset.hpp.
|
inlineconstexprnoexcept |
Constructor taking a tag-type. This constructor omits any value initialization and has to be called by providing nullptr
as the argument.
Definition at line 256 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 262 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 273 of file bitset.hpp.
|
inlineconstexprnoexcept |
Tests if any bit is set.
true
if all bits are set, false
otherwise. Definition at line 370 of file bitset.hpp.
|
inlineconstexprnoexcept |
Tests if any bit is set.
true
if at least one bit is set, false
otherwise. Definition at line 381 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 837 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 857 of file bitset.hpp.
|
inlinestaticconstexprprotectednoexcept |
Helper to determine the bit index in the actual word.
b | The absolute index. |
Definition at line 116 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 863 of file bitset.hpp.
|
inline |
Returns a const iterator pointing to the non-existing bit behind the highest one.
Definition at line 871 of file bitset.hpp.
|
inlineconstexprnoexcept |
Returns the number of bits set to true
in this set.
Definition at line 359 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 887 of file bitset.hpp.
|
inline |
Returns a const iterator pointing to the non-existing bit before the lowest one.
Definition at line 891 of file bitset.hpp.
|
inline |
Returns an iterator pointing to the non-existing bit behind the highest one.
Definition at line 841 of file bitset.hpp.
|
inline |
Returns a const iterator pointing to the non-existing bit behind the highest one.
Definition at line 867 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 421 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 413 of file bitset.hpp.
|
inlineconstexprnoexcept |
Flips all bits from 0
to 1
and vice versa.
Definition at line 343 of file bitset.hpp.
|
inlineconstexprnoexcept |
Flips one or more bits from 0
to 1
and vice versa.
firstBit | The index of the bit to flip. |
furtherBits | An optional continued list of indices of bits to flip. |
this
object. Definition at line 329 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 448 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 138 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 148 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 153 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 392 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 484 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 490 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 581 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 587 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 471 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 593 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 599 of file bitset.hpp.
|
inlineconstexprnoexcept |
Returns a const
reference to a specific bit.
bit | The bit to create a reference for. |
Definition at line 613 of file bitset.hpp.
|
inlineconstexprnoexcept |
Returns a reference to a specific bit.
bit | The bit to create a reference for. |
Definition at line 606 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 500 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 495 of file bitset.hpp.
|
inlineconstexprnoexcept |
Returns a temporary copy of this
with all bits flipped (binary NOT)..
Definition at line 504 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 847 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 877 of file bitset.hpp.
|
inline |
Returns an iterator pointing to the non-existing bit before the lowest one.
Definition at line 851 of file bitset.hpp.
|
inline |
Returns a const iterator pointing to the non-existing bit before the lowest one.
Definition at line 881 of file bitset.hpp.
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
Sets one or more bits to 0
.
firstBit | The index of the first bit to clear. |
furtherBits | An optional continued list of bit-indices. |
this
object. Definition at line 315 of file bitset.hpp.
|
inlineconstexprnoexcept |
Sets all bits to 1
.
Definition at line 339 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 288 of file bitset.hpp.
|
inlineconstexprnoexcept |
Sets one or more bits to 1
.
firstBit | The index of the first bit to set. |
furtherBits | An optional continued list of bit-indices. |
this
object. Definition at line 301 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 518 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 550 of file bitset.hpp.
|
inlineconstexprnoexcept |
Returns true
if the bit is set, false
otherwise.
bit | Denotes the bit to test. |
Definition at line 350 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 132 of file bitset.hpp.
|
inlineconstexprprotectednoexcept |
Helper receive the word from the array of words.
b | The bit to address index. |
Definition at line 127 of file bitset.hpp.
|
inlinestaticconstexprprotectednoexcept |
Helper to determine the bit index in the actual word.
b | The absolute index. |
Definition at line 110 of file bitset.hpp.