共用方式為


get Function <utility>

Gets an element from a pair object.

template<int Idx, class T1, class T2>  
    RI& get(pair<T1, T2>& pr);
template<int Idx, class T1, class T2>
    const RI& get(const pair<T1, T2>& pr);

Parameters

  • Idx
    The index of the designated element.

  • T1
    The type of the first pair elemment.

  • T2
    The type of the second pair elemment.

  • pr
    The pair to select from.

Remarks

The template functions each return a reference to an element of its pair argument. If the value of Idx is 0 the functions return pr.first and if the value of Idx is 1 the functions return pr.second. The type RI is the type of the returned element.

Example

 

// std_tr1__utility__get.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; 
 
    return (0); 
    } 
 
 0 1

Requirements

Header: <utility>

Namespace: std

See Also

Reference

tuple_element Class <utility>

tuple_size Class <utility>