Namespaces
Variants
Actions

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

From cppreference.com
 
C++
 
Containers library
 
std::vector<bool>
Defined in header <vector>
void flip();
(constexpr since C++20)

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

[edit] 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);
}

Output:

0101
1010

[edit] See also

access specified element
(public member function of std::vector<T,Allocator>) [edit]
toggles the values of bits
(public member function of std::bitset<N>) [edit]

Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant