operator==,!=,<,<=,>,>=(std::tuple)
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. |
<metanoindex/>
<tbody> </tbody>| Déclaré dans l'en-tête <tuple>
|
||
template< class... TTypes, class... UTypes > bool operator==( const tuple<TTypes...>& lhs, const tuple<UTypes...>& rhs ); |
(1) | (depuis C++11) |
template< class... TTypes, class... UTypes > bool operator!=( const tuple<TTypes...>& lhs, const tuple<UTypes...>& rhs ); |
(2) | (depuis C++11) |
template< class... TTypes, class... UTypes > bool operator<( const tuple<TTypes...>& lhs, const tuple<UTypes...>& rhs ); |
(3) | (depuis C++11) |
template< class... TTypes, class... UTypes > bool operator<=( const tuple<TTypes...>& lhs, const tuple<UTypes...>& rhs ); |
(5) | (depuis C++11) |
template< class... TTypes, class... UTypes > bool operator>( const tuple<TTypes...>& lhs, const tuple<UTypes...>& rhs ); |
(4) | (depuis C++11) |
template< class... TTypes, class... UTypes > bool operator>=( const tuple<TTypes...>& lhs, const tuple<UTypes...>& rhs ); |
(6) | (depuis C++11) |
1-2)
Compare chaque élément de la
lhs uplet avec l'élément correspondant de la rhs tuple .Original:
Compares every element of the tuple
lhs with the corresponding element of the tuple rhs.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.
3-6)
lhs compare lexicographiquement et rhs, qui est, compare les premiers éléments, s'ils sont équivalents, compare les deuxièmes éléments, si ce sont équivalentes, compare les troisièmes éléments, et ainsi de suite .Original:
Compares
lhs and rhs lexicographically, that is, compares the first elements, if they are equivalent, compares the second elements, if those are equivalent, compares the third elements, and so on.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.
Tous les opérateurs de comparaison sont court-circuitées, ils n'ont pas accès aux éléments de tuple au-delà de ce qui est nécessaire pour déterminer le résultat de la comparaison .
Original:
All comparison operators are short-circuited; they do not access tuple elements beyond what is necessary to determine the result of the comparison.
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.
Paramètres
| lhs, rhs | - | tuples à comparer
Original: tuples to compare The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
Retourne la valeur
1)
true si std::get<i>(lhs) == std::get<i>(rhs) pour tout i dans [0, sizeof...(Types)), sinon false. Pour deux déclarations de tuples vides true .Original:
true if std::get<i>(lhs) == std::get<i>(rhs) for all i in [0, sizeof...(Types)), otherwise false. For two empty tuples returns true.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.
2) !(lhs == rhs)
3)
(bool)(std::get<0>(lhs) < std::get<0>(rhs)) || (!(bool)(std::get<0>(rhs) < std::get<0>(lhs)) && lhstail < rhstail), où lhstail est lhs sans son premier élément, et rhstail est membre de droite sans son premier élément. Pendant deux tuples vides, les rendements false .Original:
(bool)(std::get<0>(lhs) < std::get<0>(rhs)) || (!(bool)(std::get<0>(rhs) < std::get<0>(lhs)) && lhstail < rhstail), where lhstail is lhs without its first element, and rhstail is rhs without its first element. For two empty tuples, 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) !(lhs < rhs)
5) rhs < lhs
6) !(rhs < lhs)
Exemple
Parce que l'opérateur <est défini pour les tuples, les conteneurs de tuples peuvent être triés .
Original:
Because operator< is defined for tuples, containers of tuples 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 <tuple>
#include <vector>
#include <algorithm>
int main()
{
std::vector<std::tuple<int, std::string, float>> v;
v.emplace_back(2, "baz", -0.1);
v.emplace_back(2, "bar", 3.14);
v.emplace_back(1, "foo", 100.1);
std::sort(v.begin(), v.end());
for(auto p: v) {
std::cout << "(" << std::get<0>(p) << ", " << std::get<1>(p)
<< ", " << std::get<2>(p) << ")\n";
}
}
Résultat :
(1, foo, 100.1)
(2, bar, 3.14)
(2, baz, -0.1)