std::make_pair
Z cppreference.com
<tbody>
</tbody>
<tbody class="t-dcl-rev ">
</tbody><tbody>
</tbody>
| Zdefiniowane w nagłówku <utility>
|
||
template< class T1, class T2 > std::pair<T1,T2> make_pair( T1 t, T2 u ); |
(do C++11) | |
template< class T1, class T2 > std::pair<V1,V2> make_pair( T1&& t, T2&& u ); |
(od C++11) | |
Tworzy obiekt std::pair, dedukując docelowy typ z typu argumentów.
| Ta sekcja jest niedokończona.
Powód: wymaga tłumaczenia |
|
The deduced types V1 and V2 are |
(od C++11) |
Parametry
| t, u | - | wartości, z których zostaje konstruowana para |
Zwracana wartość
Obiekt pary std::pair zawierający podane wartości.
Przykład
#include <iostream>
#include <utility>
#include <functional>
int main()
{
int n = 1;
int a[5] = {1, 2, 3, 4, 5};
// build a pair from two ints
auto p1 = std::make_pair(n, a[1]);
std::cout << "The value of p1 is "
<< "(" << p1.first << ", " << p1.second << ")\n";
// build a pair from a reference to int and an array (decayed to pointer)
auto p2 = std::make_pair(std::ref(n), a);
n = 7;
std::cout << "The value of p2 is "
<< "(" << p2.first << ", " << *(p2.second + 2) << ")\n";
}
Wynik:
The value of p1 is (1, 2)
The value of p2 is (7, 3)