Expression Precondition Semantics
Less x < y x and y are in the domain of <
Greater x > y x and y are in the domain of < Equivalent to y < x [1]
Less or equal x <= y x and y are in the domain of < Equivalent to !(y < x) [1]
Greater or equal x >= y x and y are in the domain of < Equivalent to !(x < y) [1]
Invariants
Irreflexivity x < x must be false.
Antisymmetry x < y implies !(y < x) [2]
Transitivity x < y and y < z implies x < z [3]
Models

• int

Notes

[1] Only operator< is fundamental; the other inequality operators are essentially syntactic sugar.

[2] Antisymmetry is a theorem, not an axiom: it follows from irreflexivity and transitivity.

[3] Because of irreflexivity and transitivity, operator< always satisfies the definition of a partial ordering. The definition of a strict weak ordering is stricter, and the definition of a total ordering is stricter still.

See also

EqualityComparable, StrictWeakOrdering

Functions

Relational Operators

Category: utilities

Component type: function

Prototype

template <class T>

bool operator!=(const T& x, const T& y);

template <class T>

bool operator>(const T& x, const T& y);

template <class T>

bool operator<=(const T& x, const T& y);

template <class T>

bool operator>=(const T& x, const T& y);

Description

The Equality Comparable requirements specify that it must be possible to compare objects using operator!= as well as operator==; similarly, the LessThan Comparable requirements include operator>, operator<= and operator>= as well as operator<. Logically, however, most of these operators are redundant: all of them can be defined in terms of operator== and operator<.

These four templates use operator== and operator< to define the other four relational operators. They exist purely for the sake of convenience: they make it possible to write algorithms in terms of the operators !=, >, <=, and >=, without requiring that those operators be explicitly defined for every type.

As specified in the Equality Comparable requirements, x != y is equivalent to !(x == y). As specified in the LessThan Comparable requirements, x > y is equivalent to y < x, x >= y is equivalent to !(x < y), and x <= y is equivalent to !(y < x).

Добавить отзыв
ВСЕ ОТЗЫВЫ О КНИГЕ В ИЗБРАННОЕ

0

Вы можете отметить интересные вам фрагменты текста, которые будут доступны по уникальной ссылке в адресной строке браузера.

Отметить Добавить цитату