首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::make_tuple

Defined in header <tuple>

?

?

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)

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

每人TiTypes...,对应类型ViVtypes...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;}

*。

二次

代码语言:javascript
复制
#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";
}

二次

产出:

二次

代码语言:javascript
复制
The value of t is (10, Test, 3.14, 7, 1)
5 7

二次

另见

tie

creates a tuple of lvalue references or unpacks a tuple into individual objects (function template)

forward_as_tuple

creates a tuple of rvalue references (function template)

tuple_cat

creates a tuple by concatenating any number of tuples (function template)

apply (C++17)

calls a function with a tuple of arguments (function template)

代码语言:txt
复制
 ? cppreference.com

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

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com