dynamic_bitset 1.3.0
Simple Useful Libraries: C++17/20 header-only dynamic bitset
Loading...
Searching...
No Matches
sul Namespace Reference

Simple Useful Libraries. More...

Classes

class  dynamic_bitset
 Dynamic bitset. More...
 

Functions

template<typename integral_type , typename = std::enable_if_t<std::is_integral_v<integral_type>>>
 dynamic_bitset (integral_type) -> dynamic_bitset<>
 
template<typename Block , typename Allocator >
constexpr bool operator!= (const dynamic_bitset< Block, Allocator > &lhs, const dynamic_bitset< Block, Allocator > &rhs)
 Test if two sul::dynamic_bitset content are different.
 
template<typename Block , typename Allocator >
constexpr bool operator<= (const dynamic_bitset< Block, Allocator > &lhs, const dynamic_bitset< Block, Allocator > &rhs)
 Test if lhs is "less than or equal to" rhs. The comparison of the two sul::dynamic_bitset is first on numbers their content represent and then on their size.
 
template<typename Block , typename Allocator >
constexpr bool operator> (const dynamic_bitset< Block, Allocator > &lhs, const dynamic_bitset< Block, Allocator > &rhs)
 Test if lhs is "greater than" rhs. The comparison of the two sul::dynamic_bitset is first on numbers their content represent and then on their size.
 
template<typename Block , typename Allocator >
constexpr bool operator>= (const dynamic_bitset< Block, Allocator > &lhs, const dynamic_bitset< Block, Allocator > &rhs)
 Test if lhs is "greater than or equal to" rhs. The comparison of the two sul::dynamic_bitset is first on numbers their content represent and then on their size.
 
template<typename Block , typename Allocator >
constexpr dynamic_bitset< Block, Allocatoroperator& (const dynamic_bitset< Block, Allocator > &lhs, const dynamic_bitset< Block, Allocator > &rhs)
 Performs binary AND on corresponding pairs of bits of lhs and rhs.
 
template<typename Block , typename Allocator >
constexpr dynamic_bitset< Block, Allocatoroperator| (const dynamic_bitset< Block, Allocator > &lhs, const dynamic_bitset< Block, Allocator > &rhs)
 Performs binary OR on corresponding pairs of bits of lhs and rhs.
 
template<typename Block , typename Allocator >
constexpr dynamic_bitset< Block, Allocatoroperator^ (const dynamic_bitset< Block, Allocator > &lhs, const dynamic_bitset< Block, Allocator > &rhs)
 Performs binary XOR on corresponding pairs of bits of lhs and rhs.
 
template<typename Block , typename Allocator >
constexpr dynamic_bitset< Block, Allocatoroperator- (const dynamic_bitset< Block, Allocator > &lhs, const dynamic_bitset< Block, Allocator > &rhs)
 Performs binary difference between bits of lhs and rhs.
 
template<typename _CharT , typename _Traits , typename Block , typename Allocator >
constexpr std::basic_ostream< _CharT, _Traits > & operator<< (std::basic_ostream< _CharT, _Traits > &os, const dynamic_bitset< Block, Allocator > &bitset)
 Insert a string representation of this sul::dynamic_bitset to a character stream.
 
template<typename _CharT , typename _Traits , typename Block , typename Allocator >
constexpr std::basic_istream< _CharT, _Traits > & operator>> (std::basic_istream< _CharT, _Traits > &is, dynamic_bitset< Block, Allocator > &bitset)
 Extract a sul::dynamic_bitset from a character stream using its string representation.
 
template<typename Block , typename Allocator >
constexpr void swap (dynamic_bitset< Block, Allocator > &bitset1, dynamic_bitset< Block, Allocator > &bitset2)
 Exchange the content of bitset1 and bitset2.
 
template<typename Block_ , typename Allocator_ >
constexpr bool operator== (const dynamic_bitset< Block_, Allocator_ > &lhs, const dynamic_bitset< Block_, Allocator_ > &rhs)
 
template<typename Block_ , typename Allocator_ >
constexpr bool operator< (const dynamic_bitset< Block_, Allocator_ > &lhs, const dynamic_bitset< Block_, Allocator_ > &rhs)
 

Detailed Description

Simple Useful Libraries.

Since
1.0.0

Function Documentation

◆ operator!=()

Test if two sul::dynamic_bitset content are different.

Defined as:

return !(lhs == rhs);
Dynamic bitset.
Definition dynamic_bitset.hpp:172

see sul::dynamic_bitset::operator==() for more informations.

Parameters
[in]lhsThe left hand side sul::dynamic_bitset of the operator
[in]rhsThe right hand side sul::dynamic_bitset of the operator
Template Parameters
BlockBlock type used by lhs and rhs for storing the bits
AllocatorAllocator type used by lhs and rhs for memory management
Returns
true if they does not contain the same bits, false otherwise
Complexity
Linear in the size of the sul::dynamic_bitset.
Since
1.0.0

◆ operator&()

Performs binary AND on corresponding pairs of bits of lhs and rhs.

Defined as:

see sul::dynamic_bitset::operator&=() for more informations.

Parameters
[in]lhsThe left hand side sul::dynamic_bitset of the operator
[in]rhsThe right hand side sul::dynamic_bitset of the operator
Template Parameters
BlockBlock type used by lhs and rhs for storing the bits
AllocatorAllocator type used by lhs and rhs for memory management
Returns
A sul::dynamic_bitset with each bit being the result of a binary AND between the corresponding pair of bits of lhs and rhs
Precondition
lhs.size() == rhs.size()
constexpr size_type size() const noexcept
Give the number of bits of the sul::dynamic_bitset.
Definition dynamic_bitset.hpp:2817
Complexity
Linear in the size of the sul::dynamic_bitset.
Since
1.0.0

◆ operator-()

Performs binary difference between bits of lhs and rhs.

Defined as:

see sul::dynamic_bitset::operator-=() for more informations.

Parameters
[in]lhsThe left hand side sul::dynamic_bitset of the operator
[in]rhsThe right hand side sul::dynamic_bitset of the operator
Template Parameters
BlockBlock type used by lhs and rhs for storing the bits
AllocatorAllocator type used by lhs and rhs for memory management
Returns
A sul::dynamic_bitset with each bit being the result of the binary difference between the corresponding bits of lhs and rhs
Precondition
lhs.size() == rhs.size()
Complexity
Linear in the size of the sul::dynamic_bitset.
Since
1.0.0

◆ operator<()

The size comparison is necessary for the comparison operators to keep their properties. For example without the size comparison the "<=" operator (defined for "A <= B" by "!(B < A)") would no longer be antisymmetric (if A <= B and B <= A, then A == B) because operator==() compare the sul::dynamic_bitset as a container and not a number. For example with bitsets A(0011) and B(011), without the size comparison B < A would be false, A <= B would be true, B <= A would be true, but A == B would be false, breaking the antisymmetric property of the operator. Thus, to respect the properties of the operators, the size is used as a secondary criteria for the comparison of sul::dynamic_bitset which content represent the same number. Therefore, for the previous example with bitsets A(0011) and B(011), B < A is true, A <= B is false, B <= A is true and A == B is false.

If comparing bitsets A and B with the content of A representing the number a, and the content of B representing the number b, this operator would work as follow:

if(a == b)
{
return A.size() < B.size();
}
else
{
return a < b;
}
Remarks
The empty sul::dynamic_bitset is the "lowest" of all bitset and for 0-only bitsets comparison, the shortest is the lowest.
Parameters
[in]lhsThe left hand side sul::dynamic_bitset of the operator
[in]rhsThe right hand side sul::dynamic_bitset of the operator
Template Parameters
Block_Block type used by lhs and rhs for storing the bits
Allocator_Allocator type used by lhs and rhs for memory management
Returns
true if lhs is "less than" rhs
Complexity
Linear in the size of the sul::dynamic_bitset.
Since
1.0.0

◆ operator<<()

constexpr std::basic_ostream< _CharT, _Traits > & sul::operator<< ( std::basic_ostream< _CharT, _Traits > & os,
const dynamic_bitset< Block, Allocator > & bitset )
constexpr

Insert a string representation of this sul::dynamic_bitset to a character stream.

The string representation written is the same as if generated with sul::dynamic_bitset::to_string() with default parameter, using '1' for true bits and '0' for false bits.

Parameters
osCharacter stream to write to
[in]bitsetsul::dynamic_bitset to write
Template Parameters
_CharTCharacter type of the character stream
_TraitsTraits class specifying the operations on the character type of the character stream
BlockBlock type used by bitset for storing the bits
AllocatorAllocator type used by bitset for memory management
Returns
os
Complexity
Linear in the size of the sul::dynamic_bitset.
Since
1.0.0

◆ operator<=()

Test if lhs is "less than or equal to" rhs. The comparison of the two sul::dynamic_bitset is first on numbers their content represent and then on their size.

Defined as:

return !(rhs < lhs);

see sul::dynamic_bitset::operator<() for more informations.

Parameters
[in]lhsThe left hand side sul::dynamic_bitset of the operator
[in]rhsThe right hand side sul::dynamic_bitset of the operator
Template Parameters
BlockBlock type used by lhs and rhs for storing the bits
AllocatorAllocator type used by lhs and rhs for memory management
Returns
true if lhs is "less than or equal to" rhs
Complexity
Linear in the size of the sul::dynamic_bitset.
Since
1.0.0

◆ operator==()

Parameters
[in]lhsThe left hand side sul::dynamic_bitset of the operator
[in]rhsThe right hand side sul::dynamic_bitset of the operator
Template Parameters
Block_Block type used by lhs and rhs for storing the bits
Allocator_Allocator type used by lhs and rhs for memory management
Returns
true if they contain the same bits, false otherwise
Complexity
Linear in the size of the sul::dynamic_bitset.
Since
1.0.0

◆ operator>()

Test if lhs is "greater than" rhs. The comparison of the two sul::dynamic_bitset is first on numbers their content represent and then on their size.

Defined as:

return rhs < lhs;

see sul::dynamic_bitset::operator<() for more informations.

Parameters
[in]lhsThe left hand side sul::dynamic_bitset of the operator
[in]rhsThe right hand side sul::dynamic_bitset of the operator
Template Parameters
BlockBlock type used by lhs and rhs for storing the bits
AllocatorAllocator type used by lhs and rhs for memory management
Returns
true if lhs is "greater than" rhs
Complexity
Linear in the size of the sul::dynamic_bitset.
Since
1.0.0

◆ operator>=()

Test if lhs is "greater than or equal to" rhs. The comparison of the two sul::dynamic_bitset is first on numbers their content represent and then on their size.

Defined as:

return !(lhs < rhs);

see sul::dynamic_bitset::operator<() for more informations.

Parameters
[in]lhsThe left hand side sul::dynamic_bitset of the operator
[in]rhsThe right hand side sul::dynamic_bitset of the operator
Template Parameters
BlockBlock type used by lhs and rhs for storing the bits
AllocatorAllocator type used by lhs and rhs for memory management
Returns
true if lhs is "greater than or equal to" rhs
Complexity
Linear in the size of the sul::dynamic_bitset.
Since
1.0.0

◆ operator>>()

constexpr std::basic_istream< _CharT, _Traits > & sul::operator>> ( std::basic_istream< _CharT, _Traits > & is,
dynamic_bitset< Block, Allocator > & bitset )
constexpr

Extract a sul::dynamic_bitset from a character stream using its string representation.

The string representation expected is the same as if generated with sul::dynamic_bitset::to_string() with default parameter, using '1' for true bits and '0' for false bits. On success the content of bitset is cleared before writing to it. The extraction starts by skipping leading whitespace then take the characters one by one and stop if is.good() return false or the next character is neither _CharT('0') nor _CharT('1').

Parameters
isCharacter stream to read from
bitsetsul::dynamic_bitset to write to
Template Parameters
_CharTCharacter type of the character stream
_TraitsTraits class specifying the operations on the character type of the character stream
BlockBlock type used by bitset for storing the bits
AllocatorAllocator type used by bitset for memory management
Returns
is
Complexity
Linear in the size of the sul::dynamic_bitset.
Since
1.0.0

◆ operator^()

Performs binary XOR on corresponding pairs of bits of lhs and rhs.

Defined as:

see sul::dynamic_bitset::operator^=() for more informations.

Parameters
[in]lhsThe left hand side sul::dynamic_bitset of the operator
[in]rhsThe right hand side sul::dynamic_bitset of the operator
Template Parameters
BlockBlock type used by lhs and rhs for storing the bits
AllocatorAllocator type used by lhs and rhs for memory management
Returns
A sul::dynamic_bitset with each bit being the result of a binary XOR between the corresponding pair of bits of lhs and rhs
Precondition
lhs.size() == rhs.size()
Complexity
Linear in the size of the sul::dynamic_bitset.
Since
1.0.0

◆ operator|()

Performs binary OR on corresponding pairs of bits of lhs and rhs.

Defined as:

see sul::dynamic_bitset::operator|=() for more informations.

Parameters
[in]lhsThe left hand side sul::dynamic_bitset of the operator
[in]rhsThe right hand side sul::dynamic_bitset of the operator
Template Parameters
BlockBlock type used by lhs and rhs for storing the bits
AllocatorAllocator type used by lhs and rhs for memory management
Returns
A sul::dynamic_bitset with each bit being the result of a binary OR between the corresponding pair of bits of lhs and rhs
Precondition
lhs.size() == rhs.size()
Complexity
Linear in the size of the sul::dynamic_bitset.
Since
1.0.0

◆ swap()

constexpr void sul::swap ( dynamic_bitset< Block, Allocator > & bitset1,
dynamic_bitset< Block, Allocator > & bitset2 )
constexpr

Exchange the content of bitset1 and bitset2.

Defined as:

constexpr void swap(dynamic_bitset< Block, Allocator > &other)
Exchanges the bits of this sul::dynamic_bitset with those of other.
Definition dynamic_bitset.hpp:2955

see sul::dynamic_bitset::swap() for more informations.

Parameters
bitset1sul::dynamic_bitset to be swapped
bitset2sul::dynamic_bitset to be swapped
Template Parameters
BlockBlock type used by bitset for storing the bits
AllocatorAllocator type used by bitset for memory management
Complexity
Constant.
Since
1.0.0