We recommend using Visual Studio 2017

tuple_size Class <array>

 

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

Wraps the size of an array.

template <class Tuple>  
struct tuple_size;  
 
// struct to determine number of elements in array  
template <class T, size_t Size>  
struct tuple_size<array<T, Size>>  
: integral_constant<size_t, Size>;  
 
// size of const tuple  
template <class Tuple>  
struct tuple_size<const Tuple>;  
 
// size of volatile tuple  
template <class Tuple>  
struct tuple_size<volatile Tuple>;  
 
// size of const volatile tuple  
template <class Tuple>  
struct tuple_size<const volatile Tuple>;  

T
The type of an element.

Size
The size of the array.

This template is a specialization of the template class tuple_size Class. It has a member value that is an integral constant expression whose value is N, which is the size of the array.

#include <array>   
#include <iostream>   
  
using namespace std;  
  
typedef array<int, 4> MyArray;  
  
int main()  
{  
    MyArray c0 { 0, 1, 2, 3 };  
  
    // display contents " 0 1 2 3"   
    for (const auto& e : c0)  
    {  
        cout << e;  
    }  
    cout << endl;  
  
    // display size " 4"   
    cout << " " << tuple_size<MyArray>::value << endl;  
}  
/*  
Output:  
0123  
4  
*/  
  

Header: <array>

Namespace: std

<array>
<tuple>
tuple_size Class

Show: