std::pair<T1,T2>::swap
提供: cppreference.com
void swap(pair& other)noexcept(/* see below */); | (C++11以上) (C++20未満) | |
constexprvoid swap(pair& other)noexcept(/* see below */); | (C++20以上) | |
first
を other.first
と、 second
を other.second
と入れ替えます。
目次 |
[編集]引数
other | - | 入れ替える値のペア |
[編集]戻り値
(なし)
[編集]例外
noexcept 指定: noexcept( noexcept(swap(first, other.first))&& 上の式において、識別子 | (C++17未満) |
noexcept 指定: noexcept( std::is_nothrow_swappable_v<first_type>&& | (C++17以上) |
[編集]例
Run this code
#include <iostream>#include <utility>#include <string>int main(){std::pair<int, std::string> p1, p2; p1 =std::make_pair(10, "test"); p2.swap(p1);std::cout<<"("<< p2.first<<", "<< p2.second<<")\n";}
出力:
(10, test)
[編集]欠陥報告
以下の動作変更欠陥報告は以前に発行された C++ 標準に遡って適用されました。
DR | 適用先 | 発行時の動作 | 正しい動作 |
---|---|---|---|
LWG 2456 | C++11 | the noexcept specification is ill-formed | made to work |
[編集]関連項目
2つのオブジェクトの値を入れ替えます (関数テンプレート) |