tuple_size Class <utility>

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at Visual Studio 2017 Documentation. Wraps pair element count.

template <class Tuple>
struct tuple_size;

template <class T1, class T2>
struct tuple_size<pair<T1, T2>>   : integral_constant<size_t, 2>

// 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>;

Parameters

T1
The type of the first pair element.

T2
The type of the second pair element.

The 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 2.

#include <utility>   
#include <iostream>   
  
using namespace std;  
  
typedef pair<int, double> MyPair;  
  
int main()  
{  
    MyPair c0(0, 1.1);  
  
    // display contents " 0 1.1"   
    cout << " " << get<0>(c0);  
    cout << " " << get<1>(c0) << endl;  
  
    // display size " 2"   
    cout << " " << tuple_size<MyPair>::value << endl;  
  
}  
  
/*  
Output:  
0 1.1  
2  
*/  

Header: <utility>

Namespace: std

<utility>
get
tuple_element Class

Show: