void swap(tuple& rhs) noexcept(see below); // (1) C++11
constexpr void swap(tuple& rhs) noexcept(see below); // (1) C++20
概要
他のtuple
オブジェクトと中身を入れ替える。
要件
tuple
の全ての要素型がswap
可能であること。
効果
自身のインスタンスの全ての要素を、rhs
の全ての要素と入れ替える
戻り値
なし
例外
tuple
の全ての要素型が、例外を投げないswap
を持っている場合、この関数は例外を投げない
例
#include <string>
#include <tuple>
#include <cassert>
int main()
{
std::tuple<int, char, std::string> a(1, 'a', "hello");
std::tuple<int, char, std::string> b(2, 'b', "good-bye");
a.swap(b);
assert(a == std::make_tuple(2, 'b', "good-bye"));
assert(b == std::make_tuple(1, 'a', "hello"));
}
出力
バージョン
言語
- C++11
処理系
- Clang:
- GCC: 4.6.1
- ICC:
- Visual C++: