名前空間
変種
操作

std::vector<bool,Allocator>::swap

提供: cppreference.com
 
 
 
 
ヘッダ <vector> で定義
static void swap(reference x, reference y);
(C++20未満)
constexpr static void swap(reference x, reference y);
(C++20以上)

xy の内容を入れ替えます。

目次

[編集] 引数

x - y と入れ替える std::vector<bool>::reference の値
y - x と入れ替える std::vector<bool>::reference の値

[編集] 戻り値

(なし)

[編集] 計算量

一定。

[編集]

#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>のパブリックメンバ関数) [edit]
std::swap アルゴリズムの特殊化
(関数テンプレート) [edit]