std::tuple<Types...>::swap
提供: cppreference.com
ヘッダ <tuple> で定義 | ||
void swap( tuple& other )noexcept(/* see below */); | (C++11以上) (C++20未満) | |
constexprvoid swap( tuple& other )noexcept(/* see below */); | (C++20以上) | |
*this 内の要素と other
内のそれに対応する要素それぞれに対して swap
を呼びます (swap
は std::swap かもしれませんし、 ADL によって見つかるものかもしれません)。
目次 |
[編集]引数
other | - | 入れ替える値のタプル |
[編集]戻り値
(なし)
[編集]例外
noexcept 指定: noexcept( noexcept(swap(std::declval<T0&>>(), std::declval<T0&>()))&& 上の式において、識別子 | (C++17未満) |
noexcept 指定: noexcept( std::is_nothrow_swappable_v<T0>&& | (C++17以上) |
[編集]例
Run this code
#include <iostream>#include <tuple>#include <string> int main(){std::tuple<int, std::string, float> p1, p2; p1 =std::make_tuple(10, "test", 3.14); p2.swap(p1);std::cout<<"("<< std::get<0>(p2)<<", "<< std::get<1>(p2)<<", "<< std::get<2>(p2)<<")\n";}
出力:
(10, test, 3.14)
[編集]欠陥報告
以下の動作変更欠陥報告は以前に発行された C++ 標準に遡って適用されました。
DR | 適用先 | 発行時の動作 | 正しい動作 |
---|---|---|---|
LWG 2456 | C++11 | the noexcept specification is ill-formed | made to work |