FR: allow defining only “operator <” for all comparisons.
Motivating example:
Very very often (counterexamples are of course possible, like float16
implementation that wants to respect NaN ANY_COMPARISON NaN = false
), the following is true for overloaded operators:
a > b
is equivalent to b < a
,
a >= b
is equivalent to not (a < b)
a <= b
is equivalent to not (b < a)
.
Hence, my feature request is to support all four <
, >
, <=
, >=
for objects that define only <
operator, rewriting them through <
. More loose variant can support rewriting through any other operator (when only one is defined).
This approach was once used in Lua (and partially cut later for some reason...). Namely, Lua 5.4 supports ONLY overloading of <
and <=
, always rewriting a > b
as b < a
and a >= b
as b <= a
. But in addition to that, previous versions supported exactly what I propose — defining only <
or only <=
for all four comparisons.