std::rel_ops::operator!=,>,<=,>=
Min standard notice:
Header: <utility>
Given a user-defined operator== and operator< for objects of type T, implements the usual semantics of other comparison operators.
# Declarations
template< class T >
bool operator!=( const T& lhs, const T& rhs );
(deprecated in C++20)
template< class T >
bool operator>( const T& lhs, const T& rhs );
(deprecated in C++20)
template< class T >
bool operator<=( const T& lhs, const T& rhs );
(deprecated in C++20)
template< class T >
bool operator>=( const T& lhs, const T& rhs );
(deprecated in C++20)
# Parameters
lhs: left-hand argumentrhs: right-hand argument
# Notes
Boost.operators provides a more versatile alternative to std::rel_ops.
As of C++20, std::rel_ops are deprecated in favor of operator<=>.
# Example
#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
<< "{1} != {2} : " << (f1 != f2) << '\n'
<< "{1} > {2} : " << (f1 > f2) << '\n'
<< "{1} <= {2} : " << (f1 <= f2) << '\n'
<< "{1} >= {2} : " << (f1 >= f2) << '\n';
}