目录

make_tuple

描述 (Description)

它构造了一个适当元组类型的对象,以包含args中指定的元素。

声明 (Declaration)

以下是std :: make_tuple的声明。

C++98

	
template<class... Types>
   tuple<VTypes...> make_tuple (Types&&... args);

C++11

template<class... Types>
   tuple<VTypes...> make_tuple (Types&&... args);

参数 (Parameters)

args - 它包含构造的元组应包含的元素列表。

返回值 (Return Value)

它返回一个适当类型的元组对象来保存args。

异常 (Exceptions)

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

数据竞争 (Data races)

如果Types中的任何类型是支持移动语义的类型的右值引用,则会修改其相应的参数。

例子 (Example)

在下面的示例中为std :: make_tuple。

#include <iostream>
#include <tuple>
#include <functional>
int main() {
   auto first = std::make_tuple (10,'a');
   const int a = 0; int b[3];
   auto second = std::make_tuple (a,b);
   auto third = std::make_tuple (std::ref(a),"abc");
   std::cout << "third contains: " << std::get<0>(third);
   std::cout << " and " << std::get<1>(third);
   std::cout << std::endl;
   return 0;
}

输出应该是这样的 -

third contains: 0 and abc
↑回到顶部↑
WIKI教程 @2018