Namespaces
Variants

cpp/container/vector bool/flip: Difference between revisions

From cppreference.com
Fruderica (talk | contribs)
P1004R2
Space Mission (talk | contribs)
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}}
{{dcl begin}}
{{headervector||
{{dcl header | vector}}
{{dcl rev multi |
| dcl1=
void flip();
void flip();
| since2=c++20 | dcl2=
constexpr void flip();
}}
}}
{{dcl end}}


Toggles each {{c|bool}} in the vector (replaces with its opposite value).
Toggles each {{c|bool}} (replaces with its opposite value) .


===Parameters===
======
(none)


===Return value===
(none)
 
()


===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

#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>) [edit]
toggles the values of bits
(public member function of std::bitset<N>) [edit]