Chapter 1. Tuples

You cannot conceive of the many without the one.

ParmenidesPLATO

The class template tuple is a generalization of the standard C++ library class template pair. The pair template takes two type arguments; objects of type pair<T1, T2> hold two elements: one of type T1 and one of type T2. The tuple template extends this by taking an arbitrary number of type arguments. Objects of type tuple<T1, T2, …, TN> hold N elements of types T1, T2, …, TN, respectively.[1]

Example 1.1. Tuple Declarations (tuples/typedefs.cpp)

#include <tuple>using std::tr1::tuple;tuple<> none;                      // holds no elementstuple<int> one;                    // holds one element, of type intint i; double d;tuple<int&, const double&>    two(i, d);                      //  ...

Get The C++ Standard Library Extensions A Tutorial and Reference now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.