std::make_pair
Aus cppreference.com
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
<metanoindex/>
<tbody> </tbody>| definiert in Header <utility>
|
||
template< class T1, class T2 > std::pair<T1,T2> make_pair( T1 t, T2 u ); template< class T1, class T2 > std::pair<V1,V2> make_pair( T1&& t, T2&& u ); |
(bis C + +11) (seit C++11) |
|
Erstellt eine
std::pair Objekt, Ableitung der Zieltyp von den Typen von Argumenten .Original:
Creates a
std::pair object, deducing the target type from the types of arguments.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Die abgeleiteten Typen sind
std::decay<T1>::type und std::decay<T2>::type (die üblichen Typs Transformationen auf Argumente von Funktionen Wert übergeben aufgebracht), sofern Anwendung std::decay führt std::reference_wrapper<X> für irgendeine Art X, in welchem Fall die abgeleitete Typ ist X& wird. (seit C++11)Original:
The deduced types are
std::decay<T1>::type and std::decay<T2>::type (the usual type transformations applied to arguments of functions passed by value) unless application of std::decay results in std::reference_wrapper<X> for some type X, in which case the deduced type is is X&. (seit C++11)The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Parameter
| t, u | - | die Werte, um das Paar aus zu bauen
Original: the values to construct the pair from The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
Rückgabewert
ein
std::pair Objekt mit den angegebenen Werten .Original:
an
std::pair object containing the given values.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Beispiel
#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+1) << ")\n";
}
Output:
The value of p1 is (1, 2)
The value of p2 is (7, 2)