Spec-Zone.ru › C++

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

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

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

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

See also

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

© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/cpp/container/vector_bool/flip

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API