std::rel_ops::operator!=,>,<=,>=
Материал из cppreference.com
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
| Заголовочный файл <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) | |
Учитывая определенный пользователем operator== и operator< для объектов типа
1) T, реализующего обычную семантику других операторов сравнения.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.
Реализует operator!= с точки зрения 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.
Реализует operator> с точки зрения 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.
Реализует operator<= с точки зрения 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.
Реализует operator>= с точки зрения 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.
Содержание |
[править] Параметры
| lhs | - | левый аргумент
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 | - | правый аргумент
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. |
[править] Возвращаемое значение
1)Возврат true если
2) lhs это не равно для 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.
Возврат true если
3) lhs является' больше, чем 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.
Возврат true если
4) lhs является меньше или равно для 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.
Возврат true если
lhs является больше или равно для 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.
You can help to correct and verify the translation. Click here for instructions.
[править] Возможная реализация
| Первый вариант |
|---|
namespace rel_ops { template< class T > bool operator!=( const T& lhs, const T& rhs ) { return !(lhs == rhs); } } |
| Второй вариант |
namespace rel_ops { template< class T > bool operator>( const T& lhs, const T& rhs ) { return rhs < lhs; } } |
| Третий вариант |
namespace rel_ops { template< class T > bool operator<=( const T& lhs, const T& rhs ) { return !(rhs < lhs);; } } |
| Четвёртый вариант |
namespace rel_ops { template< class T > bool operator>=( const T& lhs, const T& rhs ) { return !(lhs < rhs); } } |
[править] Пример
#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'; }
Вывод:
not equal? : true greater? : false less equal? : true greater equal? : false