standard library
types:

[ std::tuple_element  <std::tuple> ](/w/cpp/utility/tuple/tuple_element "cpp/utility/tuple/tuple element") (C++11)  |  obtains the type of the specified element   
(class template specialization)  [ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/utility/tuple/dsc_tuple_element&action=edit)  
---|---  
[ std::tuple_element  <std::pair> ](/w/cpp/utility/pair/tuple_element "cpp/utility/pair/tuple element") (C++11)  |  obtains the type of the elements of ` pair `   
(class template specialization)  [ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/utility/pair/dsc_tuple_element&action=edit)  
[ std::tuple_element  <std::array> ](/w/cpp/container/array/tuple_element "cpp/container/array/tuple element") (C++11)  |  obtains the type of the elements of ` array `   
(class template specialization)  [ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/container/array/dsc_tuple_element&action=edit)  
[ std::tuple_element  <std::ranges::subrange> ](/w/cpp/ranges/subrange/tuple_element "cpp/ranges/subrange/tuple element") (C++20)  |  obtains the type of the iterator or the sentinel of a  [ std::ranges::subrange ](/w/cpp/ranges/subrange "cpp/ranges/subrange")   
(class template specialization)  [ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/ranges/subrange/dsc_tuple_element&action=edit)  
  
Users may specialize ` std::tuple_element ` for program-defined types to make
them tuple-like.

In normal cases where the ` get ` functions returns reference members or
reference to subobjects, only specializations for cv-unqualified types are
needed to be customized.

###  [ [ edit
](/mwiki/index.php?title=cpp/utility/tuple_element&action=edit&section=2 "Edit
section: Member types") ]  Member types

Member type  |  Definition   
---|---  
type  |  for a standard specialization, the type of ` I ` th  element of the [ tuple-like ](/w/cpp/utility/tuple/tuple-like "cpp/utility/tuple/tuple-like") type ` T ` , where ` I ` is in ` [ ` ​  0  ​  ` , ` [ std::  tuple_size  ](http://en.cppreference.com/w/cpp/utility/tuple_size) < T  > ::  value  ` ) `  
  
###  [ [ edit
](/mwiki/index.php?title=cpp/utility/tuple_element&action=edit&section=3 "Edit
section: Helper types") ]  Helper types

Defined in header ` [ <tuple> ](/w/cpp/header/tuple "cpp/header/tuple") ` |  |   
---|---|---  
template  < [ std::  size_t  ](http://en.cppreference.com/w/cpp/types/size_t)
I,  class  T  >  
using  tuple_element_t  =  typename  tuple_element  < I, T  > ::  type  ;  |  |  (since C++14)   
|  |   
  
###  [ [ edit
](/mwiki/index.php?title=cpp/utility/tuple_element&action=edit&section=4 "Edit
section: Notes") ]  Notes

[ Feature-test ](/w/cpp/utility/feature_test "cpp/utility/feature test") macro  |  Value  |  Std  |  Feature   
---|---|---|---  
[ ` __cpp_lib_tuple_element_t ` ](/w/cpp/feature_test#cpp_lib_tuple_element_t "cpp/feature test") |  201402L  |  (C++14)  |  ` std::tuple_element_t `  
  
###  [ [ edit
](/mwiki/index.php?title=cpp/utility/tuple_element&action=edit&section=5 "Edit
section: Example") ]  Example

Run this code

    
    
    #include <array>
    #include <cstddef>
    #include <iostream>
    #include <ranges>
    #include <tuple>
    #include <type_traits>
    #include <utility>
     
    template<typename T1, typename T2, typename T3>
    struct Triple
    {
        T1 t1;
        T2 t2;
        T3 t3;
    };
     
    // A specialization of std::tuple_element for program-defined type Triple:
    template<[std::size_t](http://en.cppreference.com/w/cpp/types/size_t) I, typename T1, typename T2, typename T3>
        struct std::tuple_element<I, Triple<T1, T2, T3>>
        { static_assert(false, "Invalid index"); }; 
    template<typename T1, typename T2, typename T3>
        struct std::tuple_element<0, Triple<T1, T2, T3>> { using type = T1; };
    template<typename T1, typename T2, typename T3>
        struct std::tuple_element<1, Triple<