std::bitset<N>::flip

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

# 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

DRApplied toBehavior as publishedCorrect behavior
LWG 2250C++98the behavior was undefined if pos doesnot correspond to a valid bit positionalways throws anexception in this case

# See also