Espacios de nombres
Variantes
Acciones

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

De cppreference.com
< cpp‎ | utility
 
 
Biblioteca de servicios
Servicios generales
Operadores relacionales (en desuso en C++20)
rel_ops::operator!=rel_ops::operator>
  
rel_ops::operator<=rel_ops::operator>=
Funciones de comparación de enteros
(C++20)(C++20)(C++20)  
(C++20)
Intercambio y operaciones de tipos
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
Tipos vocabulario comunes
(C++11)
(C++17)
(C++17)
(C++17)
(C++11)
(C++17)
(C++23)



 
Definido en el archivo de encabezado <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)
Dada una definida por el usuario y operator== operator< para objetos de tipo T, implementa la semántica usual de otros operadores de comparación .
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)
Implementa operator!= en términos 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)
Implementa operator> en términos 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)
Implementa operator<= en términos 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)
Implementa operator>= en términos 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.

Contenido

[editar] Parámetros

lhs -
izquierda argumento
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 -
derecha argumento
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.

[editar] Valor de retorno

1)
Devoluciones true si lhs no igual 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.
2)
Devoluciones true si lhs es' mayor 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)
Devoluciones true si lhs es menor o igual' 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.
4)
Devoluciones true si lhs es' mayor o igual a 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.

[editar] Posible implementación

Primera versión
namespace rel_ops {
    template< class T >
    bool operator!=( const T& lhs, const T& rhs ) 
    {
        return !(lhs == rhs);
    }
}
Segunda versión
namespace rel_ops {
    template< class T >
    bool operator>( const T& lhs, const T& rhs ) 
    {
        return rhs < lhs;
    }
}
Tercera versión
namespace rel_ops {
    template< class T >
    bool operator<=( const T& lhs, const T& rhs ) 
    {
        return !(rhs < lhs);;
    }
}
Cuarta versión
namespace rel_ops {
    template< class T >
    bool operator>=( const T& lhs, const T& rhs ) 
    {
        return !(lhs < rhs);
    }
}

[editar] Ejemplo

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

Salida:

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