std::make_tuple
来自cppreference.com
![]() |
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
在头文件 <tuple> 中定义
|
||
template< class... Types > tuple<VTypes...> make_tuple( Types&&... args ); |
(C++11 起) | |
Creates a tuple object, deducing the target type from the types of arguments. The deduced types are std::decay<Ti>::type (transformed as if passed to a function by value) unless application of std::decay results in std::reference_wrapper<X> for some type X
, in which case the deduced type is is X&
.
[编辑] 参数
args | - | 零个或多个参数来构造的元组
原文: zero or more arguments to construct the tuple from |
[编辑] 返回值
A std::tuple object containing the given values.
[编辑] 示例
#include <iostream> #include <tuple> #include <functional> int main() { auto t1 = std::make_tuple(10, "Test", 3.14); std::cout << "The value of t1 is " << "(" << std::get<0>(t1) << ", " << std::get<1>(t1) << ", " << std::get<2>(t1) << ")\n"; int n = 1; auto t2 = std::make_tuple(std::ref(n), n); n = 7; std::cout << "The value of t2 is " << "(" << std::get<0>(t2) << ", " << std::get<1>(t2) << ")\n"; }
输出:
The value of t1 is (10, Test, 3.14) The value of t2 is (7, 1)
创建一个tuple 的左值引用或将一个元组拆开成多个个体对象 (函数模板) | |
创建一个 tuple 的右值引用原文: creates a tuple of rvalue references(函数模板) | |
通过连接任意数量的元组来创建一个tuple (函数模板) |