We recommend using Visual Studio 2017

tuple_element Class <array>

 

The latest version of this topic can be found at Visual Studio 2017 Documentation.

Wraps the type of an array element.

// CLASS tuple_element (find element by index)  
template <size_t Index, class Tuple>  
struct tuple_element;  
 
template <size_t Index, class T, size_t Size>  
struct tuple_element<Index, array<T, Size>>  

// tuple_element for const 
template <size_t Index, class Tuple>  
struct tuple_element<Index, const Tuple>;  
 
// tuple_element for volatile  
template <size_t Index, class Tuple>  
struct tuple_element<Index, volatile Tuple>;  
 
// tuple_element for const volatile  
template <size_t Index, class Tuple>  
struct tuple_element<Index, const volatile Tuple>;  
 
template <size_t Index, class Tuple>  
using tuple_element_t = typename tuple_element<Index, Tuple>::type;  

Index
The element position.

T
The type of an element.

N
The size of the array.

This template class is a specialization of the template class tuple_element Class for arrays. This class provides an interface to an array as a tuple of N elements, each of which has the same type. Each specialization has a nested typedef type that is a synonym for the type of the Index element of the array, with any const-volatile qualifications preserved.

  
#include <array>   
#include <iostream>   
  
using namespace std;  
typedef array<int, 4> MyArray;  
  
int main()  
{  
    MyArray c0 { 0, 1, 2, 3 };  
  
    for (const auto& e : c0)  
    {  
        cout << " " << e;  
    }  
    cout << endl;  
  
    // display first element " 0"   
    tuple_element<0, MyArray>::type val = c0.front();  
    cout << " " << val << endl;  
}  
  
/*  
Output:  
0 1 2 3  
0  
*/  
  

Header: <array>

Namespace: std

<array>
<tuple>
tuple_element Class

Show: