目录

tuple::swap

描述 (Description)

它通过tpl的内容交换元组对象的内容,tpl是同一类型的另一个元组。

声明 (Declaration)

以下是std :: tuple :: swap的声明。

C++98

	
void swap (tuple& tpl) noexcept

C++11

void swap (tuple& tpl) noexcept

参数 (Parameters)

tpl - 它是同一类型的另一个元组对象。

返回值 (Return Value)

没有

异常 (Exceptions)

No-throw guarantee - 此成员函数永远不会抛出异常。

数据竞争 (Data races)

两个元组对象的成员都被修改。

例子 (Example)

在下面的示例中为std :: tuple :: swap。

#include <iostream>
#include <tuple>
int main () {
   std::tuple<int,char> a (50,'a');
   std::tuple<int,char> b (200,'b');
   a.swap(b);
   std::cout << "a contains: " << std::get<0>(a);
   std::cout << " and " << std::get<1>(a) << '\n';
   return 0;
}

输出应该是这样的 -

a contains: 200 and b
↑回到顶部↑
WIKI教程 @2018