std::tuple_cat
来自cppreference.com
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
| Defined in header <tuple>
|
||
| template< class... Tuples > tuple<CTypes...> tuple_cat(Tuples&&... args); |
(C++11 起) | |
构造一个元组,这是一个串联的所有元组
args.Original:
Constructs a tuple that is a concatenation of all tuples in
args.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[编辑] 参数
| args | - | 零个或多个元组连接起来
Original: zero or more tuples to concatenate The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
[编辑] 返回值
从
std::tuple每个元素的所有参数的元组的所有元素组成一个std::get<i>(std::forward<Ti>(arg))对象.Original:
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.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[编辑] 为例
#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); }
Output:
(10, Test, 3.14, Foo, bar, 10, Test, 3.14, 10)
| 创建一个 tuple对象的参数类型定义的类型Original: creates a tuple object of the type defined by the argument typesThe text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (函数模板) | |
| 创建一个 tuple的左值引用或解压缩到单个对象的元组Original: creates a tuple of lvalue references or unpacks a tuple into individual objectsThe text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (函数模板) | |
| 创建一个 tuple的右值引用Original: creates a tuple of rvalue referencesThe text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (函数模板) | |