std::vector<bool,Allocator>::flip - cppreference.com (original) (raw)

| | | | | ------------ | | ----------------------- | | void flip(); | | (constexpr since C++20) |

Toggles each bool (replaces with its opposite value) in the vector.

[edit] Example

#include #include   void print(const std::vector& vb) { for (const bool b : vb) std::cout << b; std::cout << '\n'; }   int main() { std::vector v{0, 1, 0, 1}; print(v); v.flip(); print(v); }

Output:

[edit] 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) [edit] |