swap (tuple)
描述 (Description)
它交换了两个元组的内容。
声明 (Declaration)
以下是std :: swap(元组)的声明
C++98
template <class... Types>
void swap (tuple<Types...>& x, tuple<Types...>& y) noexcept;
C++11
template <class... Types>
void swap (tuple<Types...>& x, tuple<Types...>& y) noexcept;
参数 (Parameters)
x,y - 这些是元组对象。
返回值 (Return Value)
没有
异常 (Exceptions)
No-throw guarantee - 此成员函数永远不会抛出异常。
数据竞争 (Data races)
两个对象x和y的成员都被修改。
例子 (Example)
在下面的示例中为std :: swap(元组)。
#include <iostream>
#include <tuple>
int main () {
std::tuple<int,char> a (100,'a');
std::tuple<int,char> b (200,'b');
swap(a,b);
std::cout << "a contains: " << std::get<0>(a) << " and " << std::get<1>(a) << '\n';
return 0;
}
输出应该是这样的 -
a contains: 200 and b