class template

std::tuple_element

<tuple>
template <size_t I, class T> class tuple_element;
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.

For const and/or volatile-qualified tuples, the type has itself that same qualification.

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.


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 is exists, such as a tuple, and tuple-like classes array and pair.

Member types

member typedefinition
typeThe Ith type in the tuple

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// tuple_element
#include <iostream>
#include <tuple>

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: ";
  std::cout << first << " and " << second;
  std::cout << std::endl;

  return 0;
}


Output:
mytuple contains: 10 and a

See also