std::make_tuple

来自cppreference.com
< cpp‎ | utility‎ | tuple

定义于头文件 <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
(函数模板) [编辑]