std::rel_ops::operator!=,>,<=,>=
Da cppreference.com.
![]() | Questa pagina è stata tradotta in modo automatico dalla versione in ineglese della wiki usando Google Translate. La traduzione potrebbe contenere errori e termini strani. Muovi il puntatore sopra al testo per vedere la versione originale. Puoi aiutarci a correggere gli gli errori. Per ulteriori istruzioni clicca qui. |
Elemento definito nell'header <utility> | ||
template<class T > bool operator!=(const T& lhs, const T& rhs ); | (1) | |
template<class T > bool operator>(const T& lhs, const T& rhs ); | (2) | |
template<class T > bool operator<=(const T& lhs, const T& rhs ); | (3) | |
template<class T > bool operator>=(const T& lhs, const T& rhs ); | (4) | |
Dato un definito dall'utente operator==operator< e per gli oggetti di tipo
1) T
, implementa la semantica abituali di altri operatori di confronto.Original:
Given a user-defined operator== and operator< for objects of type
T
, implements the usual semantics of other comparison operators.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.
Implementa operator!= in termini di operator==.
2) Original:
Implements operator!= in terms of operator==.
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.
Implementa operator> in termini di operator<.
3) Original:
Implements operator> in terms of operator<.
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.
Implementa operator<= in termini di operator<.
4) Original:
Implements operator<= in terms of operator<.
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.
Implementa operator>= in termini di operator<.
Original:
Implements operator>= in terms of operator<.
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.
Indice |
[modifica]Parametri
lhs | - | sinistra argomento Original: left-hand argument The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
rhs | - | destra argomento Original: right-hand argument The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
[modifica]Valore di ritorno
1)Restituisce true se
2) lhs
è' non è uguale a rhs
.Original:
Returns true if
lhs
is not equal to 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.
Restituisce true se
3) lhs
è superiore di rhs
.Original:
Returns true if
lhs
is greater than 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.
Restituisce true se
4) lhs
' è minore o uguale a rhs
.Original:
Returns true if
lhs
is less or equal to 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.
Restituisce true se
lhs
è maggiore o uguale arhs
.Original:
Returns true if
lhs
is greater or equal to 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.
[modifica]Possibile implementazione
First version |
---|
namespace rel_ops {template<class T >bool operator!=(const T& lhs, const T& rhs ){return!(lhs == rhs);}} |
Second version |
namespace rel_ops {template<class T >bool operator>(const T& lhs, const T& rhs ){return rhs < lhs;}} |
Third version |
namespace rel_ops {template<class T >bool operator<=(const T& lhs, const T& rhs ){return!(rhs < lhs);;}} |
Fourth version |
namespace rel_ops {template<class T >bool operator>=(const T& lhs, const T& rhs ){return!(lhs < rhs);}} |
[modifica]Esempio
#include <iostream>#include <utility> struct Foo {int n;}; bool operator==(const Foo& lhs, const Foo& rhs){return lhs.n== rhs.n;} bool operator<(const Foo& lhs, const Foo& rhs){return lhs.n< rhs.n;} int main(){ Foo f1 ={1}; Foo f2 ={2};usingnamespace std::rel_ops; std::cout<<std::boolalpha;std::cout<<"not equal? : "<<(bool)(f1 != f2)<<'\n';std::cout<<"greater? : "<<(bool)(f1 > f2)<<'\n';std::cout<<"less equal? : "<<(bool)(f1 <= f2)<<'\n';std::cout<<"greater equal? : "<<(bool)(f1 >= f2)<<'\n';}
Output:
not equal? : true greater? : false less equal? : true greater equal? : false