Difference between revisions of "cpp/container/vector bool/flip"
From cppreference.com
< cpp | container | vector bool
m (fmt) |
Andreas Krug (Talk | contribs) m (fmt) |
||
(One intermediate revision by one user not shown) | |||
Line 11: | Line 11: | ||
{{dcl end}} | {{dcl end}} | ||
− | Toggles each {{c|bool}} in the vector (replaces with its opposite value). | + | Toggles each {{c|bool}} in the {{rlp|/|vector}} (replaces with its opposite value). |
===Parameters=== | ===Parameters=== | ||
Line 34: | Line 34: | ||
int main() | int main() | ||
{ | { | ||
− | std::vector<bool> v { 0, 1, 0, 1 }; | + | std::vector<bool> v{0, 1, 0, 1}; |
print(v); | print(v); | ||
v.flip(); | v.flip(); | ||
Line 43: | Line 43: | ||
1010 | 1010 | ||
}} | }} | ||
+ | |||
===See also=== | ===See also=== | ||
{{dsc begin}} | {{dsc begin}} |
Latest revision as of 00:59, 28 September 2023
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).
Contents |
[edit] Parameters
(none)
[edit] Return value
(none)
[edit] 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
[edit] 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> )
|