| 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);
}0101
1010See also
| access specified element (public member function of std::vector<T,Allocator>) | |
| toggles the values of bits (public member function of std::bitset<N>) |
Content from this page on cppreference.com, licensed under CC-BY-SA 3.0 and GFDL. Modified: restyled, site navigation removed, code windows added. Offline snapshot of 9 February 2025.