function template
<utility>
std::make_pairtemplate <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
Construct pair object
Constructs a pair object with its first element set to x and its second element set to y.The template types can be implicitly deduced from the arguments passed to make_pair.
pair objects can be constructed from other pair objects containing different types, if the respective types are implicitly convertible.
The behavior of this function template is the same as if defined as:
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) );
}
The function returns:
1
pair<V1,V2>(std::forward<T1>(x),std::forward<T2>(y))
Where the types
V1and
V2are the
decayequivalents of
T1and
T2, respectively (except for
reference_wrappertypes, for which the corresponding reference type is used instead).
If T1 and/or T2 are rvalue references, the objects are moved and x and/or y are left in an undefined but valid state.
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;
}
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4