std::bitset<N>::flip
Min standard notice:
Flips bits, i.e. changes true values to false and false values to true. Equivalent to a logical NOT operation on part or all of the bitset.
# Declarations
bitset& flip();
(noexcept since C++11) (constexpr since C++23)
bitset& flip( std::size_t pos );
(constexpr since C++23)
# Parameters
pos: the position of the bit to flip
# Return value
*this
# Example
#include <bitset>
#include <iostream>
int main()
{
std::bitset<4> flops;
std::cout << flops << '\n'
<< flops.flip(0) << '\n'
<< flops.flip(2) << '\n'
<< flops.flip() << '\n';
}
# Defect reports
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 2250 | C++98 | the behavior was undefined if pos doesnot correspond to a valid bit position | always throws anexception in this case |