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<T
1, T
2>
hold two elements: one of type T
1 and one of type T
2. The tuple
template extends this by taking an arbitrary number of type arguments. Objects of type tuple<T
1, T
2, …, T
N>
hold N elements of types T
1, T
2, …, T
N, 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 the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.