<tuple>

class template
<tuple>

std::tuple_element

unspecialized
template <size_t I, class T> class tuple_element;
generic cv-specializations
template <size_t I, class T> class tuple_element<const T>;template <size_t I, class T> class tuple_element<volatile T>;template <size_t I, class T> class tuple_element<const volatile T>;
tuple specialization
template <size_t I, class... Types>  class tuple_element< I, tuple<Types...> >;
Tuple element type
Class designed to access the type of the Ith element in a tuple.

It is a simple class with a single member type, tuple_element::type, defined as an alias of the type of the Ith element in a tuple of type T.

The class is itself undefined for the generic type T, but it is specialized for tuple instantiations in the <tuple> header, and for tuple-like types array and pair in their respective headers.

For const and/or volatile-qualified tuples, the class is specialized so that its type member has itself that same qualification.

Template parameters

I
Order number of the element within the tuple (zero-based).
This shall be lower than the actual number of elements in the tuple.
size_t is an unsigned integral type.
T
Type for which the type of the tuple element is to be 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 types

member typedefinition
typeThe Ith type in the tuple object

Example

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

int main ()
{
  auto mytuple = std::make_tuple (10,'a');

  std::tuple_element<0,decltype(mytuple)>::type first = std::get<0>(mytuple);
  std::tuple_element<1,decltype(mytuple)>::type second = std::get<1>(mytuple);

  std::cout << "mytuple contains: " << first << " and " << second << '\n';

  return 0;
}

Output:
mytuple contains: 10 and a


See also