std::get(std::pair)

From Cppreference

Jump to: navigation, search
template< size_t N, class T1, class T2 >

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

    get( pair<T1, T2>& p );
(1) (C++11 feature)
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 );
(2) (C++11 feature)
template< size_t N, class T1, class T2 >

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

    get( std::pair<T1,T2>&& p );
(3) (C++11 feature)

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

Contents

[edit] Parameters

p - pair whose contents to extract

[edit] 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

[edit] Exceptions

1-3)
noexcept specification:  
noexcept

  (C++11 feature)

[edit] 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) << ')' << std::endl;
}

Output:

(1, 3.14)


[edit] See also