C++11 introduces a multivariate array of tuples, which is used to hold arrays of different data.
There are two types of initialization methods:
Tuple () constructor
Make_tuple () Create function
There are several commonly used functions as follows:
Head () Gets the value of the first element
Tail () Gets the value of all remaining elements
Get<n> () Gets the value of the nth element, n must be a constant, cannot iterate through a tuple using a loop
Tuple_element<n, Decltype (tup) >::type Gets the type of the nth element
Tuple_size<decltype (TUP) >::value Gets the number of elements in the tuple tup
In addition about type:
Auto automatic type deduction, which infers the data type of a variable from an initialization expression
Decltype get a type from a variable or an expression
It sounds like a mixed-up look at the code.
#include <map>//Use a tuple to include the header file # include <iostream>using namespace Std;int main () {tuple<int, char, String>tup0 (1, ' A ', "Hello World"); int e1 = Tup0.head ();//1int e2 = Tup0.tail (). Head (); ' A ' unsigned short cnt = Tuple_size (Decltype (TUP0)):: value; Gets the number of elements: 3tuple<char, string> tup1 = Tup0.tail (); Tuple<double, string> tup2 = make_tuple (1.1, "ABC"); auto D0 = get<0> (tup2);//1.1auto D1 = get<1> (tup2); "ABC" cout <<typeid (D0). Name () << endl;//Gets the data type of the element: Doubledecltype (d0) d2 = d0;//The data type of the inverse D0, and uses it to declare a variable D0, Then assign a value of D0return 0;}
Tuple and data type of C++11