共用方式為


tuple_size Class <utility>

Wraps pair element count.

template<class T1, class T2>  
    class tuple_size<pair<T1, T2> > {
    static const unsigned value = 2;
    };

Parameters

  • T1
    The type of the first pair elemment.

  • T2
    The type of the second pair elemment.

Remarks

The template is a specialization of the template class tuple_size Class <tuple>. It has a member value that is an integral constant expression whose value is 2.

Example

 

// std_tr1__utility__tuple_size.cpp 
// compile with: /EHsc 
#include <utility> 
#include <iostream> 
 
typedef std::pair<int, double> Mypair; 
int main() 
    { 
    Mypair c0(0, 1); 
 
// display contents " 0 1" 
    std::cout << " " << std::get<0>(c0); 
    std::cout << " " << std::get<1>(c0); 
    std::cout << std::endl; 
 
// display size " 2" 
    std::cout << " " << std::tuple_size<Mypair>::value; 
    std::cout << std::endl; 
 
    return (0); 
    } 
 
 0 1
 2

Requirements

Header: <utility>

Namespace: std

See Also

Reference

get Function <utility>

tuple_element Class <utility>

Other Resources

<utility> Members