std::tuple_cat
来自cppreference.com
|
|
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
| 在头文件 <tuple> 中定义
|
||
| template< class... Tuples > tuple<CTypes...> tuple_cat(Tuples&&... args); |
(C++11 起) | |
构造一个元组,这是一个串联的所有元组
args.原文:
Constructs a tuple that is a concatenation of all tuples in
args.[编辑] 参数
| args | - | 零个或多个元组连接起来
|
[编辑] 返回值
从
std::tuple每个元素的所有参数的元组的所有元素组成一个std::get<i>(std::forward<Ti>(arg))对象.原文:
A
std::tuple object composed of all elements of all argument tuples constructed from std::get<i>(std::forward<Ti>(arg)) for each individual element.[编辑] 示例
#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); }
输出:
(10, Test, 3.14, Foo, bar, 10, Test, 3.14, 10)
| 创建一个 tuple对象的参数类型定义的类型原文: creates a tuple object of the type defined by the argument types(函数模板) | |
创建一个tuple的左值引用或将一个元组拆开成多个个体对象 (函数模板) | |
| 创建一个 tuple的右值引用原文: creates a tuple of rvalue references(函数模板) | |