std::vector<bool,Allocator>::swap
提供: cppreference.com
< cpp | container | vector bool
ヘッダ <vector> で定義
|
||
static void swap(reference x, reference y); |
(C++20未満) | |
constexpr static void swap(reference x, reference y); |
(C++20以上) | |
x
と y
の内容を入れ替えます。
目次 |
[編集] 引数
x | - | y と入れ替える std::vector<bool>::reference の値
|
y | - | x と入れ替える std::vector<bool>::reference の値
|
[編集] 戻り値
(なし)
[編集] 計算量
一定。
[編集] 例
Run this code
#include <vector> #include <iostream> int main() { std::vector<bool> vb1{ 1,0 }; for (auto e : vb1) { std::cout << e << " "; } std::cout << '\n'; vb1.swap(vb1[0], vb1[1]); for (auto e : vb1) { std::cout << e << " "; } }
出力:
1 0 0 1
[編集] 関連項目
1個の bool への参照を表すプロキシクラス (クラス) | |
(C++11) |
内容を入れ替えます ( std::vector<T,Allocator> のパブリックメンバ関数)
|
std::swap アルゴリズムの特殊化 (関数テンプレート) |