Member types 
    * 1.4  Example 
    * 1.5  Defect reports 
    * 1.6  See also 

  
---  
  
##  Inherited from [ std::  integral_constant ](/w/cpp/types/integral_constant
"cpp/types/integral constant")

###  Member constants

value  [static]  |  the constant value 2   
(public static member constant)  
---|---  
  
###  Member functions

operator std::size_t  |  converts the object to  [ std::  size_t  ](http://en.cppreference.com/w/cpp/types/size_t) , returns  value    
(public member function)  
---|---  
operator()  (C++14)  |  returns  value    
(public member function)  
  
###  Member types

Type  |  Definition   
---|---  
` value_type ` |  [ std::  size_t  ](http://en.cppreference.com/w/cpp/types/size_t)  
` type ` |  [ std::  integral_constant  ](http://en.cppreference.com/w/cpp/types/integral_constant) < [ std::  size_t  ](http://en.cppreference.com/w/cpp/types/size_t) , value  >  
  
###  [ [ edit
](/mwiki/index.php?title=cpp/utility/pair/tuple_size&action=edit&section=1
"Edit section: Example") ]  Example

Run this code

    
    
    #include <iostream>
    #include <tuple>
    #include <utility>
     
    template<class T>
    void test([[maybe_unused]]T t)
    {
        [[maybe_unused]]
        int a[[std::tuple_size](http://en.cppreference.com/w/cpp/utility/tuple_size)<T>::value]; // can be used at compile time
        [std::cout](http://en.cppreference.com/w/cpp/io/cout) << [std::tuple_size](http://en.cppreference.com/w/cpp/utility/tuple_size)<T>::value << '\n'; // or at run time
    }
     
    int main()
    {
        test([std::make_tuple](http://en.cppreference.com/w/cpp/utility/tuple/make_tuple)(1, 2, 3.14));
        test([std::make_pair](http://en.cppreference.com/w/cpp/utility/pair/make_pair)(1, 3.14));
    }

Output:

    
    
    3
    2

###  [ [ edit
](/mwiki/index.php?title=cpp/utility/pair/tuple_size&action=edit&section=2
"Edit section: Defect reports") ]  Defect reports

The following behavior-changing defect reports were applied retroactively to
previously published C++ standards.

DR  |  Applied to  |  Behavior as published  |  Correct behavior   
---|---|---|---  
[ LWG 2313 ](https://cplusplus.github.io/LWG/issue2313) |  C++11  |  specializations for ` pair ` were not required to be derived from ` integral_constant ` |  required   
  
###  [ [ edit
](/mwiki/index.php?title=cpp/utility/pair/tuple_size&action=edit&section=3
"Edit section: See also") ]  See also

[ Structured binding ](/w/cpp/language/structured_binding "cpp/language/structured binding") (C++17)  |  binds the specified names to sub-objects or tuple elements of the initializer  [ [edit] ](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/language/dsc_structured_binding&action=edit)  
---|---  
[ tuple_size  ](/w/cpp/utility/tuple_size "cpp/utility/tuple size") (C++11)  |  obtains the number of elements of a tuple-like type   
(class template)  [ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/utility/dsc_tuple_size&action=edit)  
[ std::tuple_size  <std::array> ](/w/cpp/container/array/tuple_size "cpp/container/array/tuple size") (C++11)  |  obtains the size of an ` array `   
(class template specialization)  [ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/container/array/dsc_tuple_size&action=edit)  
[ std::tuple_size  <std::tuple> ](/w/cpp/utility/tuple/tuple_size "cpp/utility/tuple/tuple size") (C++11)  |  obtains the size of ` tuple ` at compile time   
(class template specialization)  [ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/utility/tuple/dsc_tuple_size&action=edit)  
[ std::tuple_size  <std::ranges::subrange> ](/w/cpp/ranges/subrange/tuple_size "cpp/ranges/subrange/tuple size") (C++20)  |  obtains the number of components of a  [ std::ranges::subrange ](/w/cpp/ranges/subrange "cpp/ranges/subrange")   
(class template specialization)  [ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/ranges/subrange/ds