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

> C++ Atlas: `cppatlas.com/w/cpp/container/vector_bool/flip` | Source: https://en.cppreference.com/w/cpp/container/vector_bool/flip | Domain: Containers | Standards: C++20

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

## Official Specification Summary (cppreference)

```cpp
// Defined in header <vector>
void flip(); // (constexpr since C++20)
```

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

### Example

```cpp
#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);
}
```

Output:

```text
0101
1010
```

### See also

- [`operator[]`](https://en.cppreference.com/w/cpp/container/vector/operator_at): access specified element (public member function of `std::vector<T,Allocator>`)
- [`flip`](https://en.cppreference.com/w/cpp/utility/bitset/flip): toggles the values of bits (public member function of `std::bitset<N>`)

---
Attribution: content from https://en.cppreference.com/w/cpp/container/vector_bool/flip (cppreference.com), licensed under CC-BY-SA 3.0 and GFDL. Modified: converted to markdown, study notes added. Offline snapshot of 9 February 2025.