std::tuple<Types...>::swap
提供: cppreference.com
<tbody>
</tbody>
<tbody class="t-dcl-rev ">
</tbody><tbody>
</tbody>
| ヘッダ <tuple> で定義
|
||
void swap( tuple& other ) noexcept(/* see below */); |
(C++11以上) (C++20未満) |
|
constexpr void 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&>())) && noexcept(swap(std::declval<T1&>>(), std::declval<T1&>())) && noexcept(swap(std::declval<T2&>>(), std::declval<T2&>())) && ... )上の式において、識別子 |
(C++17未満) |
|
noexcept 指定:
noexcept( std::is_nothrow_swappable_v<T0> && std::is_nothrow_swappable_v<T1> && std::is_nothrow_swappable_v<T2> && ... ) |
(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 |