Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
get Function <utility>
Collapse the table of content
Expand the table of content

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

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.

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

Community Additions

ADD
Show:
© 2015 Microsoft