Espaces de noms
Variantes
Affichages
Actions

std::make_pair

De cppreference.com
< cpp‎ | utility‎ | pair

 
 
 
std::pair
Les fonctions membres
Original:
Member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
pair::pair
pair::operator=
pair::swap
Tiers fonctions
Original:
Non-member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
make_pair
operator=
operator!=
operator<
operator<=
operator>
operator>=
std::swap
get (C++11)
Classes d'aide
Original:
Helper classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
tuple_size (C++11)
tuple_element (C++11)
 
Defined 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 );
(avant C++11)

(depuis C++11)
Crée un objet std::pair, en déduire le type de cible à partir des types d'arguments .
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.
Les types sont déduites std::decay<T1>::type et std::decay<T2>::type (les transformations de type habituel appliqué sur les arguments des fonctions passés par valeur) à moins que l'application des résultats de std::decay std::reference_wrapper<X> pour un certain type X, dans ce cas, le type est déduit est X&. (depuis 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&. (depuis C++11)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[modifier] Paramètres

t, u -
les valeurs de construire à partir de la paire
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.

[modifier] Retourne la valeur

un objet std::pair contenant les valeurs indiquées .
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.

[modifier] Exemple

#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";
}

Résultat :

The value of p1 is (1, 2)
The value of p2 is (7, 2)