Namespaces
Variants
Views
Actions

std::get(std::pair)

From cppreference.com
< cpp‎ | utility‎ | pair
Revision as of 15:41, 24 January 2013 by Nate (Talk | contribs)

Template:ddcl list begin <tr class="t-dcl ">

<td >
template< size_t N, class T1, class T2 >

typename std::tuple_element<I, std::pair<T1,T2> >::type&

    get( pair<T1, T2>& p );
</td>

<td > (1) </td> <td > (since C++11) </td> </tr> <tr class="t-dcl ">

<td >
template< size_t N, class T1, class T2 >

const typename std::tuple_element<I, std::pair<T1,T2> >::type&

    get( const pair<T1,T2>& p );
</td>

<td > (2) </td> <td > (since C++11) </td> </tr> <tr class="t-dcl ">

<td >
template< size_t N, class T1, class T2 >

typename std::tuple_element<I, std::pair<T1,T2> >::type&&

    get( std::pair<T1,T2>&& p );
</td>

<td > (3) </td> <td > (since C++11) </td> </tr> Template:ddcl list end

Extracts a element from the pair using tuple-like interface.

Contents

Parameters

p - pair whose contents to extract

Return value

1-2) Returns p.first if N==0 and p.second if N==1.

3) Returns std::forward<T1&&>(p.first) if N==0 and std::forward<T2&&>(p.second) if N==1

Exceptions

1-3)
noexcept specification:  
noexcept
  

Example

#include <iostream>
#include <utility>
 
int main()
{
    auto p = std::make_pair(1, 3.14);
    std::cout << '(' << std::get<0>(p) << ", " << std::get<1>(p) << ")\n";
}

Output:

(1, 3.14)


See also

Template:cpp/container/array/dcl list get
tuple accesses specified element
(function template) [edit]