[ tuple ]

The class template tuple<> is a generalization of the STL pair, which can hold N elements of types T1, T2, .. TN.

Constructor:


#include <tr1/tuple>
using std::tr1::tuple;

tuple<int,int> abc(1,2);

Template function make_tuple:


#include <tr1/functional>
using std::tr1::ref; using std::tr1::cref;

tuple<int,int> x (make_tuple(1,2));

int x, y;

make_tuple(ref(x), cref(y));

Template function tie:


#include <tr1/functional>
using std::tr1::tie;

tie(x,y);  // create a tuple<int &, int &>

int i = 0;
int j = 0;
tuple<int &,int &> ij = tie(i,j);

std::tr1::get<0>(ij) = 1;
std::tr1::get<1>(ij) = 2;
                
...
using std::tr1::ignore;

tie(i, ignore) = make_tuple(1,2);

Template function get:


using std::tr1::get;

get<0>(abc) = 1;
get<1>(abc) = 2;

Metafunction tuple_size:


using std::tr1::tuple_size;
typedef tuple<int,int> myTuple;

tuple_size<myTuple>::value;

Metafunction tuple_element:


using std::tr1::tuple_element;
typedef tuple<int,int> myTuple;

tuple_element<0,myTuple>::type
tuple_element<1,myTuple>::type

Lexicographical comparisons:


        == != < <= > >=



Comments