This documentation is archived and is not being maintained.

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


The index of the designated element.


The type of the first pair elemment.


The type of the second pair elemment.


The pair to select from.

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.


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

Header: <utility>

Namespace: std