[ Web Proxy ]
URL:
Viewing: https://ru.cppreference.com/cpp/utility/pair/make_pair [Back]  [Original]

std::make_pair cppreference.com
cppreference.com

std::make_pair

cppreference.com
 
C++
(C++20)
(C++20)
(C++11)
(C++20)
/
(C++11)
(C++11)
(C++11)
(C++17)
 
 
 
<tbody> </tbody> <tbody class="t-dcl-rev "> </tbody><tbody> </tbody>
template< class T1, class T2 > std::pair<T1, T2> make_pair( T1 t, T2 u );
( C++11)
template< class T1, class T2 > std::pair<V1, V2> make_pair( T1&& t, T2&& u );
( C++11)
( C++14)
template< class T1, class T2 > constexpr std::pair<V1, V2> make_pair( T1&& t, T2&& u );
( C++14)

std::pair, .

V1 V2 std::decay<T1>::type std::decay<T2>::type ( , , ), std::decay std::reference_wrapper<X> X, X&.

( C++11)

t, u , pair

std::pair, .

#include <iostream>
#include <utility>
#include <functional>

int main()
{
    int n = 1;
    int a[5] = {1, 2, 3, 4, 5};

    //  pair   
    auto p1 = std::make_pair(n, a[1]);
    std::cout << " p1  "
              << "(" << p1.first << ", " << p1.second << ")\n";

    //  pair    int   (  )
    auto p2 = std::make_pair(std::ref(n), a);
    n = 7;
    std::cout << " p2  "
              << "(" << p2.first << ", " << *(p2.second + 2) << ")\n";
}

:

 p1  (1, 2)
 p2  (7, 3)

C++:

LWG 181 C++98 - ,

Web Proxy Viewer  |  New URL  |  Original Page