For bitsets, some special constructors are defined. There is no special copy constructor, assignment operator, and destructor defined. Thus, bitsets are assigned and copied with the default operations that copy bitwise.
| Operation | Effect |
|---|
size_t size() const | Returns the number of bits |
size_t count() const | Returns the number of set bits (bits with value 1) |
bool any() const | Returns if any bit is set |
bool none() const | Returns if no bit is set |
bool test (size_t pos) const | Returns if the bit at position pos is set (throws out_of_range if pos > size()) |
bool operator==(const bitset<bits>& bits) const | Returns if all bits of *this and bits have the same value |
bool operator!=(const bitset<bits>& bits) const | Returns if any bits of *this and bits have a different value |
| Operation | Effect |
|---|
| bitset< N >& set() | Sets all bits to true, returns the modified bitset |
bitset< N >& set(size_t pos) | Sets the bit at position pos to true, returns the modified bitset (throws out_of_range if pos > size()) |
bitset< N >& set(size_t pos, int val) | Sets the bit at position pos according to val, returns the modified bitset. If val is equal to 0, the bit is set to false; any other value sets the bit to true (throws out_of _range if idx > size()) |
| bitset< N >& reset() | Resets all bits to false (assigns 0 to all bits) and returns the modified bitset |
bitset< N >& reset(size_t pos) | Resets the bit at position pos to false, returns the modified bitset (throws out_of_range if pos > size()) |
| bitset< N >& flip() | Toggles all bits (sets unset bits and vice versa), returns the modified bitset |
bitset< N >& flip(size_t pos) | Toggles the bit at position pos, returns the modified bitset (throws out_of_range if pos > size()) |
bitset< N >& operator^= (const bitset< N >& bits) | The bitwise exclusive-or operator; toggles the value of all bits that are set in bits and leaves all other bits unchanged; returns the modified bitset |
bitset< N >& operator|= (const bitset< N >& bits) | The bitwise or operator; sets all bits that are set in bits and leaves all other bits unchanged; returns the modified bitset |
bitset< N >& operator&= (const bitset< N >& bits) | The bitwise and operator; resets all bits that are not set in bits and leaves all other bits unchanged; returns the modified bitset |
bitset< N >& operator<<= (size_t num) | Shifts all bits by num positions to the left; returns the modified bitset; the first num bits are set to false |
bitset< N >& operator>>= (size_t num) | Shifts all bits by num positions to the right; returns the modified bitset; the last num bits are set to false |
| Operation | Effect |
|---|
bitset< N > operator~() const | Returns a new bitset that has all bits toggled with respect to *this |
bitset< N > operator<< (size_t num) const | Returns a new bitset that has all bits shifted to the left by num position |
bitset< N > operator>> (size_t num) const | Returns a new bitset that has all bits shifted to the right by num position |
bitset< N > operator& (const bitset< N >& b1, const bitset <N>& b2) | Returns the bitwise computing of operator and of b1 and b2; returns a new bitset that has only those bits set in b1 and in b2 |
bitset< N > operator| (const bitset< N >& b1, const bitset <N>& b2) | Returns the bitwise computing of operator or of b1 and b2; returns a new bitset that has only those bits set in b1 or in b2 |
bitset< N > operator^ (const bitset< N >& b1, const bitset <N>& b2) | Returns the bitwise computing of operator exclusive-or of b1 and b2; returns a new bitset that has only those bits set in b1 and not set in b2 or vice versa |