template <class T1, class T2> pair<T1,T2> make_pair (T1 x, T2 y);
template <class T1, class T2> pair<V1,V2> make_pair (T1&& x, T2&& y); // see below for definition of V1 and V2
1
2
3
4
5
template <class T1,class T2>
pair<T1,T2> make_pair (T1 x, T2 y)
{
return ( pair<T1,T2>(x,y) );
}
1
pair<V1,V2>(std::forward<T1>(x),std::forward<T2>(y))
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// make_pair example
#include <utility> // std::pair
#include <iostream> // std::cout
int main () {
std::pair <int,int> foo;
std::pair <int,int> bar;
foo = std::make_pair (10,20);
bar = std::make_pair (10.5,'A'); // ok: implicit conversion from pair<double,char>
std::cout << "foo: " << foo.first << ", " << foo.second << '\n';
std::cout << "bar: " << bar.first << ", " << bar.second << '\n';
return 0;
}
foo: 10, 20 bar: 10, 65