Espaces de noms
Variantes
Affichages
Actions

std::rel_ops::operator!=,>,<=,>=

De cppreference.com
< cpp‎ | utility

Defined in 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)
Étant donné défini par l'utilisateur operator== et operator< pour les objets de T type, met en œuvre les sens habituel d'autres opérateurs de comparaison .
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.
1)
Met en œuvre operator!= en termes de 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.
2)
Met en œuvre operator> en termes de 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.
3)
Met en œuvre operator<= en termes de 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.
4)
Met en œuvre operator>= en termes de 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.

Sommaire

[modifier] Paramètres

lhs -
gauche argument
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 -
droite argument
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.

[modifier] Retourne la valeur

1)
Retours true si lhs' est pas égal à 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.
2)
Retours true si lhs est plus que 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.
3)
Retours true si lhs' est inférieure ou égale à 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.
4)
Retours true si lhs est' plus ou égale à rhs .
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.

[modifier] Mise en œuvre possible

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);
    }
}

[modifier] Exemple

#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};
    using namespace 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';
}

Résultat :

not equal?     : true
greater?       : false
less equal?    : true
greater equal? : false