operator==,!=,<,<=,>,>=(std::pair)
De 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. |
| Défini dans l'entête <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) | |
Teste si deux éléments de lhs et rhs sont égaux, c'est-à-
3-6) lhs.first compare avec rhs.first et lhs.second avec rhs.secondOriginal:
Tests if both elements of lhs and rhs are equal, that is, compares
lhs.first with rhs.first and lhs.second with rhs.secondThe 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.
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.
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
2) lhs.first == rhs.first et lhs.second == rhs.second, sinon falseOriginal:
true if both
lhs.first == rhs.first and lhs.second == rhs.second, otherwise falseThe 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.
true si l'une ou
3) lhs.first != rhs.first lhs.second != rhs.second, sinon falseOriginal:
true if either
lhs.first != rhs.first or lhs.second != rhs.second, otherwise falseThe 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.
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.
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.
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)