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

std::tuple_cat

Defined in header <tuple>

template< class... Tuples > std::tuple<CTypes...> tuple_cat(Tuples&&... args);

(since C++11) (until C++14)

template< class... Tuples > constexpr std::tuple<CTypes...> tuple_cat(Tuples&&... args);

(since C++14)

构造一个元组,该元组是args...

参数

args

-

zero or more tuples to concatenate

返回值

std::tuple对象,该对象由所有参数元组的所有元素组成。std::get<i>(std::forward<Ti>(arg))对于每个单独的元素。

二次

代码语言:javascript
复制
#include <iostream>
#include <tuple>
#include <string>
 
// helper function to print a tuple of any size
template<class Tuple, std::size_t N>
struct TuplePrinter {
    static void print(const Tuple& t) 
    {
        TuplePrinter<Tuple, N-1>::print(t);
        std::cout << ", " << std::get<N-1>(t);
    }
};
 
template<class Tuple>
struct TuplePrinter<Tuple, 1> {
    static void print(const Tuple& t) 
    {
        std::cout << std::get<0>(t);
    }
};
 
template<class... Args>
void print(const std::tuple<Args...>& t) 
{
    std::cout << "(";
    TuplePrinter<decltype(t), sizeof...(Args)>::print(t);
    std::cout << ")\n";
}
// end helper function
 
int main()
{
    std::tuple<int, std::string, float> t1(10, "Test", 3.14);
    int n = 7;
    auto t2 = std::tuple_cat(t1, std::make_pair("Foo", "bar"), t1, std::tie(n));
    n = 10;
    print(t2);
}

二次

产出:

二次

代码语言:javascript
复制
(10, Test, 3.14, Foo, bar, 10, Test, 3.14, 10)

二次

另见

make_tuple

creates a tuple object of the type defined by the argument types (function template)

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)

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

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

扫码关注腾讯云开发者

领取腾讯云代金券