Namespaces
Variants
Views
Actions

std::tuple_element<std::tuple>

From cppreference.com
< cpp‎ | utility‎ | tuple
Revision as of 11:53, 2 November 2012 by P12bot (Talk | contribs)

Template:ddcl list begin <tr class="t-dsc-header">

<td>
Defined in header <tuple>
</td>

<td></td> <td></td> <tr class="t-dcl ">

<td >
template< std::size_t I, class T >
class tuple_element; /* undefined */
</td>

<td > (1) </td> <td > (since C++11) </td> </tr> <tr class="t-dcl ">

<td >
template< std::size_t I, class... Types >
class tuple_element< I, tuple<Types...> >;
</td>

<td > (2) </td> <td > (since C++11) </td> </tr> <tr class="t-dcl ">

<td >
template< std::size_t I, class T >

class tuple_element< I, const T > {
  typedef typename
      std::add_const<typename std::tuple_element<I, T>::type>::type type;

};
</td>

<td > (3) </td> <td > (since C++11) </td> </tr> <tr class="t-dcl ">

<td >
template< std::size_t I, class T >

class tuple_element< I, volatile T > {
  typedef typename
      std::add_volatile<typename std::tuple_element<I, T>::type>::type type;

};
</td>

<td > (4) </td> <td > (since C++11) </td> </tr> <tr class="t-dcl ">

<td >
template< size_t I, class T >

class tuple_element< I, const volatile T > {
  typedef typename
      std::add_cv<typename std::tuple_element<I, T>::type>::type type;

};
</td>

<td > (5) </td> <td > (since C++11) </td> </tr> Template:ddcl list end

Provides compile-type indexed access to the types of the elements of the tuple.

Contents

Member types

Member type Definition
type the type of Ith element of the tuple, where I is in [0, sizeof...(Types))

Possible implementation

template< std::size_t I, class T >
struct tuple_element;
 
// recursive case
template<std::size_t I, class Head, class... Tail >
struct tuple_element<I, std::tuple<Head, Tail...>>
    : std::tuple_element<I-1, std::tuple<Tail...>> { };
 
// base case
template< class Head, class... Tail >
struct tuple_element<0, std::tuple<Head, Tail...>> {
   typedef Head type;
};

Example

See also

Template:cpp/container/array/dcl list tuple element
obtains the type of the elements of pair
(class template specialization) [edit]