<tuple>

class template
<tuple>

std::tuple_size

unspecialized
template <class T> class tuple_size;
generic cv-specializations
template <class T> class tuple_size<const T>;template <class T> class tuple_size<volatile T>;template <class T> class tuple_size<const volatile T>;
tuple specialization
template <class... Types>  struct tuple_size<tuple<Types...> >;
Tuple size traits
Class template designed to access the number of elements in a tuple (as a constexpr).

The class is itself undefined for the generic type T, but a specialization for tuple instantiations is defined in the <tuple> header as:
1
2
template <class... Types>
struct tuple_size<tuple<Types...> > : integral_constant<size_t, sizeof...(Types)> {};

A specialization for this class template also exists for the tuple-like types array and pair in their respective headers, also having a value member defined to the appropriate constexpr value.

For const and/or volatile-qualified tuples and tuple-like objects, the class is specialized so that its value member is itself non cv-qualified (size_t for tuples).

Template parameters

T
Type for which the tuple size is obtained.
This shall be a class for which a specialization of this class exists, such as a tuple, and tuple-like classes array and pair.

Member constants

member constantdefinition
valueThe number of elements in the tuple or tuple-like object.
This is a constexpr value of the unsigned integral type size_t.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
// tuple_size
#include <iostream>     // std::cout
#include <tuple>        // std::tuple, std::tuple_size

int main ()
{
  std::tuple<int,char,double> mytuple (10,'a',3.14);

  std::cout << "mytuple has ";
  std::cout << std::tuple_size<decltype(mytuple)>::value;
  std::cout << " elements." << '\n';

  return 0;
}

Output:
mytuple has 3 elements


See also