operator==,!=,<,<=,>,>=(std::tuple)
De cppreference.com
![]() | Esta página se ha traducido por ordenador/computador/computadora de la versión en inglés de la Wiki usando Google Translate. La traducción puede contener errores y palabras aparatosas/incorrectas. Planea sobre el texto para ver la versión original. Puedes ayudar a corregir los errores y mejorar la traducción. Para instrucciones haz clic aquí. |
Definido en el archivo de encabezado <tuple> | ||
template<class... TTypes, class... UTypes> bool operator==(const tuple<TTypes...>& lhs, | (1) | (desde C++11) |
template<class... TTypes, class... UTypes> bool operator!=(const tuple<TTypes...>& lhs, | (2) | (desde C++11) |
template<class... TTypes, class... UTypes> bool operator<(const tuple<TTypes...>& lhs, | (3) | (desde C++11) |
template<class... TTypes, class... UTypes> bool operator<=(const tuple<TTypes...>& lhs, | (5) | (desde C++11) |
template<class... TTypes, class... UTypes> bool operator>(const tuple<TTypes...>& lhs, | (4) | (desde C++11) |
template<class... TTypes, class... UTypes> bool operator>=(const tuple<TTypes...>& lhs, | (6) | (desde C++11) |
Compara cada elemento de la
3-6) lhs
tupla con el elemento correspondiente de la tupla rhs
.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.
Compara
lhs
y rhs
lexicográficamente, es decir, compara los elementos primero, si son equivalentes, compara los elementos segundo, si aquellos son equivalentes, compara los elementos tercero, y así sucesivamente .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.
Todos los operadores de comparación están en cortocircuito, ya que no tienen acceso a los elementos de tupla más allá de lo necesario para determinar el resultado de la comparación .
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.
Contenido |
[editar]Parámetros
lhs, rhs | - | tuplas para comparar 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. |
[editar]Valor de retorno
1)truestd::get<i>(lhs)==std::get<i>(rhs) si para todo i en
[0, sizeof...(Types))
, de lo contrario false. Durante dos retornos tuplas vacías 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), donde
lhstail
es lhs sin su primer elemento, y es rhstail
der. sin su primer elemento. Durante dos tuplas vacías, vuelve 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)
[editar]Ejemplo
Debido a <operador se define para tuplas, contenedores de tuplas se pueden clasificar .
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.
Ejecuta este código
#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";}}
Salida:
(1, foo, 100.1) (2, bar, 3.14) (2, baz, -0.1)