boost::dynamic_bitset::reference
A proxy class to simulate lvalues of bit type.
Synopsis
Declared in <boost/dynamic_bitset/dynamic_bitset.hpp>
class reference;
Description
This class exists only as a helper class for dynamic_bitset's operator[]. The following list describes the valid operations on the reference type. Assume that b is an instance of dynamic_bitset, i, j are of size_type and in the range [0, b.size())]. Also, note that when we write b[ i ] we mean an object of type reference that was initialized from b[ i ]. The variable x is a bool.
-
(bool)b[ i ]
Returns the i‐th bit of b.
-
(bool)~ b[ i ]
Returns the opposite of the i‐th bit of b.
-
b[ i ].flip()
Flips the i‐th bit of b and returns b[ i ].
-
x = b[ i ]
Assigns the i‐th bit of b to x.
-
b[ i ]= x
Sets the i‐th bit of b to the value of x and returns b[ i ].
-
b[ i ]= b[ j ]
Sets the i‐th bit of b to the value of the j‐th bit of b and returns b[ i ].
-
b[ i ]|= x
Does an OR of the i‐th bit of b with the value of x and returns b[ i ].
-
b[ i ]&= x
Does an AND of the i‐th bit of b with the value of x and returns b[ i ].
-
b[ i ]ˆ= x
Does a XOR of the i‐th bit of b with the value of x and returns b[ i ].
-
b[ i ]‐= x
If x is true, clears the i‐th bit of b. Returns `b[ i ]`.
-
b[ i ]|= b[ j ]
Does an OR of the i‐th bit of b with the j‐th bit of b and returns b[ i ].
-
b[ i ]&= b[ j ]
Does an AND of the i‐th bit of b with the j‐th bit of b and returns b[ i ].
-
b[ i ]ˆ= b[ j ]
Does a XOR of the i‐th bit of b with the j‐th bit of b and returns b[ i ].
-
b[ i ]‐= b[ j ]
If the j‐th bit of b is set, clears the i‐th bit of b. Returns b[ i ].
-
swap( b[ i ], b[ j ])
Exchanges the values of the i‐th and the j‐th bit of b.
The assignment from bool works also on a `const reference`. Thanks to this, iterator` models `std::output_iterator and std::permutable, so it can be used with the algorithms of std::ranges which assign or swap elements, such as std::ranges::fill() and std::ranges::reverse(). Classic algorithms such as std::iter_swap(), std::reverse() and std::sort() swap elements with an unqualified call to swap(), so, in practice, they work too (formally, iterator is not a LegacyForwardIterator).
Note that a copy of a reference refers to the same bit as the original. So, std::swap( r1, r2 ), where r1 and r2 are lvalues of type reference, doesn't exchange the two bits: it sets both to the value of r2. Call swap() unqualified (after using std::swap;, if needed) instead.
Member Functions
Name |
Description |
|
Copy constructor. |
Assignment operators |
|
See the class description. |
|
|
Deleted address‐of operator. |
See the class description. |
|
See the class description. |
|
See the class description. |
|
See the class description. |
|
See the class description. |
|
See the class description. |
Friends
Name |
Description |
Exchanges the values of the bits which |
|
The |
Created with MrDocs