Visual Computing Library
|
The BitSet class allows to treat an integral type as an array of booleans of a guaranteed size. More...
#include <vclib/space/core/bit_set.h>
Public Member Functions | |
BitSet ()=default | |
Empty constructor. All the Bits of the BitSet are set to false. | |
template<NonBoolIntegralOrEnum I> | |
BitSet (std::initializer_list< I > l) | |
Constructor from list of integral (or enum) values that represent the indices of the true bits, allowing braces initialization. | |
template<typename B > requires std::same_as<bool, B> | |
BitSet (std::initializer_list< B > l) | |
Constructor from a list of boolean values, allowing braces initialization. | |
constexpr std::size_t | size () const |
Returns the number of bits of the BitSet. | |
bool | operator[] (uint i) const |
Returns the i-th bit value of the BitSet. | |
BitProxy< T > | operator[] (uint i) |
Returns a reference of the i-th bit value of the BitSet. | |
bool | at (uint i) const |
Returns the i-th bit value of the BitSet, with bounds checking. | |
BitProxy< T > | at (uint i) |
Returns a reference of the i-th bit value of the BitSet, with bounds checking. | |
bool | all () const |
Returns true if all the bits of the BitSet are set to true. | |
bool | any () const |
Returns true if any of the bits of the BitSet are set to true. | |
bool | none () const |
Returns true if none of the bits of the BitSet is set to true. | |
BitSet< T > | set () |
Sets all the bits to true. | |
BitSet< T > | set (bool b, uint i) |
Sets the bit at position i to b. | |
BitSet< T > | reset () |
Sets all the bits to false. | |
BitSet< T > | reset (uint i) |
Sets the bit at position i to false. | |
BitSet< T > | flip () |
Flips all the bits of the BitSet. | |
BitSet< T > | flip (uint i) |
Flips the bit at position i. | |
T | underlying () const |
Returns the underlying integral value of the BitSet. | |
BitSet< T > | operator& (const BitSet< T > &other) const |
Returns a BitSet that is the result of the bitwise AND between this BitSet and another BitSet. | |
BitSet< T > | operator| (const BitSet< T > &other) const |
Returns a BitSet that is the result of the bitwise OR between this BitSet and another BitSet. | |
BitSet< T > | operator^ (const BitSet< T > &other) const |
Returns a BitSet that is the result of the bitwise XOR between this BitSet and another BitSet. | |
BitSet< T > | operator~ () const |
Returns a BitSet that is the result of the bitwise NOT of this BitSet. | |
BitSet< T > & | operator&= (const BitSet< T > &other) |
Compound assignment operator that performs the bitwise AND between this BitSet and another BitSet. | |
BitSet< T > & | operator|= (const BitSet< T > &other) |
Compound assignment operator that performs the bitwise OR between this BitSet and another BitSet. | |
BitSet< T > & | operator^= (const BitSet< T > &other) |
Compound assignment operator that performs the bitwise XOR between this BitSet and another BitSet. | |
void | serialize (std::ostream &os) const |
Serializes the BitSet to the given output stream. | |
void | deserialize (std::istream &is) |
Deserializes the BitSet from the given input stream. | |
auto | operator<=> (const BitSet< T > &) const =default |
Static Public Attributes | |
static constexpr std::size_t | SIZE = sizeof(T) * 8 |
The number of the bits of the BitSet. | |
Private Member Functions | |
BitSet (T bits) | |
Private Attributes | |
T | mBits = static_cast<T>(0) |
Friends | |
template<typename U > | |
std::ostream & | operator<< (std::ostream &os, const BitSet< U > &bs) |
The BitSet class allows to treat an integral type as an array of booleans of a guaranteed size.
This class is necessary w.r.t. the std::bitset because the realization of the std::bitset class is implementation defined, and the standard does not constraint the size of the bitset itself.
This class guarantess that the sizeof(BitSet<T>) is equal to sizeof(T).
T | The type to use as a storage for the bits. It must satisfy the std::integral concept. |
|
inline |
Constructor from list of integral (or enum) values that represent the indices of the true bits, allowing braces initialization.
Creates a BitSet by setting to true the bits at the indices specified in the list. All the other bits are set to false. Each value of the list must be less than the number of bits of the BitSet.
[in] | l | the list of bit positions to set to true. |
|
inline |
|
inline |
|
inline |
|
inline |
Returns a reference of the i-th bit value of the BitSet, with bounds checking.
[in] | i | the position of the bit |
std::out_of_range | if i is >= BitSet<T>::SIZE |
|
inline |
Returns the i-th bit value of the BitSet, with bounds checking.
[in] | i | the position of the bit |
std::out_of_range | if i is >= BitSet<T>::SIZE |
|
inline |
Deserializes the BitSet from the given input stream.
[in] | is | The input stream. |
|
inline |
Flips all the bits of the BitSet.
*this
|
inline |
Flips the bit at position i.
[in] | i | the position of the bit |
*this
|
inline |
|
inline |
|
inline |
|
inline |
Returns a reference of the i-th bit value of the BitSet.
[in] | i | the position of the bit |
|
inline |
Returns the i-th bit value of the BitSet.
[in] | i | the position of the bit |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Sets all the bits to false.
*this
|
inline |
Sets the bit at position i to false.
[in] | i | the position of the bit |
*this
|
inline |
Serializes the BitSet to the given output stream.
[in] | os | The output stream. |
|
inline |
Sets all the bits to true.
*this
|
inline |
Sets the bit at position i to b.
[in] | b | the boolena value to assign to the bit |
[in] | i | the position of the bit |
*this
|
inlineconstexpr |
|
inline |