cpp/container/vector bool/flip: Difference between revisions
From cppreference.com
P1004R2 |
m fmt. Besides, it would be convenient if over time std::vector<bool> gained most of the operations that std::bitset and boost::dynamic_bitset have... |
||
| (4 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
{{cpp/container/vector_bool/title | flip}} | {{cpp/container/vector_bool/title|flip}} | ||
{{cpp/container/vector_bool/navbar}} | {{cpp/container/vector_bool/navbar}} | ||
{{ | {{headervector|| | ||
| | |||
void flip(); | void flip(); | ||
}} | }} | ||
Toggles each {{c|bool}} | Toggles each {{c|bool}} (replaces with its opposite value) . | ||
=== | ====== | ||
( | |||
() | |||
===See also=== | ===See also=== | ||
{{dsc begin}} | {{dsc begin}} | ||
{{dsc inc | cpp/container/dsc operator_at | vector}} | {{dsc inc|cpp/container/dsc operator_at|vector}} | ||
{{dsc inc | cpp/utility/bitset/dsc flip}} | {{dsc inc|cpp/utility/bitset/dsc flip}} | ||
{{dsc end}} | {{dsc end}} | ||
{{langlinks|de|es|fr|it|ja|pt|ru|zh}} | {{langlinks|de|es|fr|it|ja|pt|ru|zh}} | ||
Latest revision as of 22:46, 10 December 2024
| Defined in header <vector>
|
||
void flip();
|
(constexpr since C++20) | |
Toggles each bool (replaces with its opposite value) in the vector.
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>)
|