在线文档教程
C++
应用 | Utilities

std::make_tuple

STD:使[医]元组

Defined in header
template< class... Types > tuple<VTypes...> make_tuple( Types&&... args (since C++11) (until C++14)
template< class... Types > constexpr tuple<VTypes...> make_tuple( Types&&... args (since C++14)

创建元组对象,从参数类型推断目标类型。

每人Ti在Types...,对应类型Vi在Vtypes...是std::decay<Ti>::type除非...的适用std::decay结果std::reference_wrapper<X>为某种类型X,在这种情况下,推导的类型是X&...

参数

args-zero or more arguments to construct the tuple from

返回值

阿std::tuple对象中包含给定值的std::tuple<VTypes...>(std::forward<Types>(t)...).

可能的实施

模板<class T>结构展开[医]使用type=T;};模板<class T>结构展开[医]REWILE<std::引用[医]包装器<T>>{使用type=T};模板<class T>使用特殊[医]衰变[医]t=type Name展开[医]重构包装<type Name std::衰变<T>*类型>::类型;模板<class...。类型>自动制造[医]元组%28类型&...args%29{返回std::tuple<Specible[医]衰变[医]T型<Types>...%28%d::前进<Types>%28 args%29...%29;}

*。

二次

#include <iostream> #include <tuple> #include <functional> std::tuple<int, int> f() // this function returns multiple values { int x = 5; return std::make_tuple(x, 7 // return {x,7}; in C++17 } int main() { // heterogeneous tuple construction int n = 1; auto t = std::make_tuple(10, "Test", 3.14, std::ref(n), n n = 7; std::cout << "The value of t is " << "(" << std::get<0>(t) << ", " << std::get<1>(t) << ", " << std::get<2>(t) << ", " << std::get<3>(t) << ", " << std::get<4>(t) << ")\n"; // function returning multiple values int a, b; std::tie(a, b) = f( std::cout << a << " " << b << "\n"; }

二次

产出:

二次

The value of t is (10, Test, 3.14, 7, 1) 5 7

二次

另见

tiecreates a tuple of lvalue references or unpacks a tuple into individual objects (function template)
forward_as_tuplecreates a tuple of rvalue references (function template)
tuple_catcreates a tuple by concatenating any number of tuples (function template)
apply (C++17)calls a function with a tuple of arguments (function template)

© cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

http://en.cppreference.com/w/cpp/实用程序/tuple/make[医]元组