std::vector<bool,Allocator>:: flip
From cppreference.net
<
cpp
|
container
|
vector bool
C++
Containers library
|
(C++17)
|
||||
| Sequence | ||||
|
(C++11)
|
||||
|
(C++26)
|
||||
|
(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 types | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Member functions | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Non-member functions | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Helper classes | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
(C++11)
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Deduction guides (C++17) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
定义于头文件
<vector>
|
||
|
void
flip
(
)
;
|
(自 C++20 起为 constexpr) | |
翻转 vector 中的每个 bool 值(替换为其相反值)。
示例
运行此代码
#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); }
输出:
0101 1010
参见
|
访问指定元素
(
std::vector<T,Allocator>
的公开成员函数)
|
|
|
翻转位的值
(
std::bitset<N>
的公开成员函数)
|