std::tuple_element<std::array>
From cppreference.com
 
 
 
 
 
 C++ 
 Feature test macros (C++20)
 Concepts library (C++20)
 Metaprogramming library (C++11)
 Ranges library (C++20)
 Filesystem library (C++17)
 Concurrency support library (C++11)
 Execution control library (C++26)
Containers library 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
(C++17)
(C++11)
(C++26)
(C++26)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++23)
(C++23)
(C++23)
(C++23)
(C++20)
(C++23)
 Tables
std::array 
 
 
 
  
 
 
(until C++20)(until C++20)(until C++20)(until C++20)(until C++20)
tuple_element<std::array>
 Deduction guides (C++17)
Defined in header 
 
 
<array> 
 template< std::size_t I, class T, std::size_t N >
struct tuple_element< I, std::array <T, N> >;
 
 (since C++11) 
struct tuple_element< I, std::array <T, N> >;
Provides compile-time indexed access to the type of the elements of the array using tuple-like interface.
[edit] Member types
 Member type
 Definition
 type
 the type of elements of the array
[edit] Possible implementation
template<std::size_t I, class T> struct tuple_element; template<std::size_t I, class T, std::size_t N> struct tuple_element<I, std::array <T,N>> { using type = T; };
[edit] Example
Run this code
#include <array> #include <tuple> #include <type_traits> int main() { // define array and get the type of the element at position 0 std::array <int, 10> data{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; using T = std::tuple_element <0, decltype(data)>::type; // int static_assert(std::is_same_v <T, int>); const auto const_data = data; using CT = std::tuple_element <0, decltype(const_data)>::type; // const int // the result of tuple_element depends on the cv-qualification of the tuple-like type static_assert(!std::is_same_v <T, CT>); static_assert(std::is_same_v <CT, const int>); }
[edit] See also
 Structured binding (C++17)
 binds the specified names to sub-objects or tuple elements of the initializer[edit]