Skip to content

Latest commit

 

History

History
142 lines (114 loc) · 3.09 KB

File metadata and controls

142 lines (114 loc) · 3.09 KB
title tuple_size Class; | Microsoft Docs
ms.custom
ms.date 11/04/2016
ms.reviewer
ms.suite
ms.technology
cpp-standard-libraries
ms.tgt_pltfrm
ms.topic article
f1_keywords
tuple_size
std::tuple_size
utility/std::tuple_size
dev_langs
C++
helpviewer_keywords
tuple_size Class
ms.assetid 73852fc5-eb68-41f1-8379-465cedc2314a
caps.latest.revision 23
author corob-msft
ms.author corob
manager ghogen
translation.priority.mt
cs-cz
de-de
es-es
fr-fr
it-it
ja-jp
ko-kr
pl-pl
pt-br
ru-ru
tr-tr
zh-cn
zh-tw

tuple_size Class;

Reports the number of elements that a tuple contains.

Syntax

// TEMPLATE STRUCT tuple_size  
template <class Tuple>  
   struct tuple_size;  
  
// number of elements in array  
template <class Elem, size_t Size>  
   struct tuple_size<array<Elem, Size>>  
      : integral_constant<size_t, Size>; 
  
// size of pair
template <class T1, class T2>
   struct tuple_size<pair<T1, T2>> 
      : integral_constant<size_t, 2>

// size of tuple  
template <class... Types>  
   struct tuple_size<tuple<Types...>>  
      : integral_constant<size_t, sizeof...(Types)>;  
  
// 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

Tuple
The type of the tuple.

Elem
The type of the array elements.

Size
The size of the array.

T1
The type of the first member of the pair.

T2
The type of the second member of the pair.

Types
The types of the tuple elements.

Remarks

The template class has a member value that is an integral constant expression whose value is the extent of the tuple type Tuple.

The template specialization for arrays has a member value that is an integral constant expression whose value is Size, which is the size of the array.

The template specialization for pair has a member value that is an integral constant expression whose value is 2.

Example

#include <tuple>   
#include <iostream>  
  
using namespace std;  
  
typedef tuple<int, double, int, double> MyTuple;  
int main()  
{  
    MyTuple c0(0, 1.5, 2, 3.7);  
  
    // display contents " 0 1 2 3"   
    cout << " " << get<0>(c0);  
    cout << " " << get<1>(c0);  
    cout << " " << get<2>(c0);  
    cout << " " << get<3>(c0) << endl;  
  
    // display size " 4"   
    cout << " " << tuple_size<MyTuple>::value << endl;  
}  
 0 1.5 2 3.7  

Requirements

Header: <tuple>
Header: <array> (for array specialization)
Header: <utility> (for pair specialization)

Namespace: std

See Also

<tuple>
tuple
tuple_element Class