std::vector<bool,Allocator>::flip

Header: <vector>

Toggles each bool (replaces with its opposite value) in the vector.

# Declarations

void flip();

(constexpr since C++20)

# Example

#include <iostream>
#include <vector>
 
void print(const std::vector<bool>& vb)
{
    for (const bool b : vb)
        std::cout << b;
    std::cout << '\n';
}
 
int main()
{
    std::vector<bool> v{0, 1, 0, 1};
    print(v);
    v.flip();
    print(v);
}

# See also