Espaces de noms
Variantes
Affichages
Actions

operator==,!=,<,<=,>,>=(std::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 >
bool operator==( const pair<T1,T2>& lhs, const pair<T1,T2>& rhs );
(1)
template< class T1, class T2 >
bool operator!=( const pair<T1,T2>& lhs, const pair<T1,T2>& rhs );
(2)
template< class T1, class T2 >
bool operator<( const pair<T1,T2>& lhs, const pair<T1,T2>& rhs );
(3)
template< class T1, class T2 >
bool operator<=( const pair<T1,T2>& lhs, const pair<T1,T2>& rhs );
(4)
template< class T1, class T2 >
bool operator>( const pair<T1,T2>& lhs, const pair<T1,T2>& rhs );
(5)
template< class T1, class T2 >
bool operator>=( const pair<T1,T2>& lhs, const pair<T1,T2>& rhs );
(6)
1-2)
Teste si deux éléments de lhs et rhs sont égaux, c'est-à-lhs.first compare avec rhs.first et lhs.second avec rhs.second
Original:
Tests if both elements of lhs and rhs are equal, that is, compares lhs.first with rhs.first and lhs.second with rhs.second
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
3-6)
Compare lhs et rhs lexicographique, c'est-à-compare les premiers éléments et que si elles sont équivalentes, compare les deuxièmes éléments .
Original:
Compares lhs and rhs lexicographically, that is, compares the first elements and only if they are equivalent, compares the second elements.
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

lhs, rhs -
paires à comparer
Original:
pairs to compare
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

1)
true si les deux lhs.first == rhs.first et lhs.second == rhs.second, sinon false
Original:
true if both lhs.first == rhs.first and lhs.second == rhs.second, otherwise false
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
2)
true si l'une ou lhs.first != rhs.first lhs.second != rhs.second, sinon false
Original:
true if either lhs.first != rhs.first or lhs.second != rhs.second, otherwise false
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
3)
Si lhs.first<rhs.first, retourne true. Sinon, si rhs.first<lhs.first, retourne false. Sinon, si lhs.second<rhs.second, retourne true. Sinon, retourne false .
Original:
If lhs.first<rhs.first, returns true. Otherwise, if rhs.first<lhs.first, returns false. Otherwise, if lhs.second<rhs.second, returns true. Otherwise, returns false.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

4) !(rhs < lhs)

5) rhs < lhs

6) !(lhs < rhs)

[modifier] Exemple

Parce que l'opérateur <est définie pour les couples, les conteneurs de paires peuvent être triés .
Original:
Because operator< is defined for pairs, containers of pairs can be sorted.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
 
int main()
{
    std::vector<std::pair<int, std::string>> v = { {2, "baz"},
                                                   {2, "bar"},
                                                   {1, "foo"} };
    std::sort(v.begin(), v.end());
 
    for(auto p: v) {
        std::cout << "(" << p.first << "," << p.second << ")\n";
    }
}

Résultat :

(1,foo)
(2,bar)
(2,baz)