std::vector<bool,Allocator>:: flip
From cppreference.com
<
cpp
|
container
|
vector bool
C++
Containers library
Sequence | ||||
(C++11)
|
||||
(C++26)
|
||||
(C++11)
|
||||
Associative | ||||
Unordered associative | ||||
(C++11)
|
||||
(C++11)
|
||||
(C++11)
|
||||
(C++11)
|
||||
Adaptors | ||||
(C++23)
|
||||
(C++23)
|
||||
(C++23)
|
||||
(C++23)
|
||||
Views | ||||
(C++20)
|
||||
(C++23)
|
||||
Tables | ||||
Iterator invalidation | ||||
Member function table | ||||
Non-member function table |
std::vector<bool>
Member functions | |||||||||||||||||||||
Element access | |||||||||||||||||||||
Iterators | |||||||||||||||||||||
|
|
||||||||||||||||||||
Capacity | |||||||||||||||||||||
Modifiers | |||||||||||||||||||||
std::vector<bool> specific | |||||||||||||||||||||
vector<bool>::flip
|
|||||||||||||||||||||
Non-member functions | |||||||||||||||||||||
|
|||||||||||||||||||||
Helper classes | |||||||||||||||||||||
(C++11)
|
|||||||||||||||||||||
Deduction guides (C++17) |
Defined in header
<vector>
|
||
void
flip
(
)
;
|
(until C++20) | |
constexpr
void
flip
(
)
;
|
(since C++20) | |
Toggles each bool in the vector (replaces with its opposite value).
Parameters
(none)
Return value
(none)
Example
Run this code
#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
access specified element
(public member function of
std::vector<T,Allocator>
)
|
|
toggles the values of bits
(public member function of
std::bitset<N>
)
|
Retrieved from "
https://en.cppreference.com/mwiki/index.php?title=cpp/container/vector_bool/flip&oldid=159761
"