Definition:
Let
<
be a binary relation wherea < b
means "a
is less thanb
".
Let
>
be a binary relation wherea > b
means "a
is greater thanb
".
So, we assume <
and >
have meanings we usually use in a daily life. Though, in some programming languages (e.g. C++), we can overload them to give them different definitions, hereafter we don't think about that.
Context:
As far I read mathematical definition of strict weak ordering (e.g. Wikipedia), I think both <
and >
satify it. However, all examples I saw in many websites refer only to <
. There is even a website which says
what they roughly mean is that a Strict Weak Ordering has to behave the way that "less than" behaves: if a is less than b then b is not less than a, if a is less than b and b is less than c then a is less than c, and so on.
Also, in N4140 (C++14 International Standard), strict weak ordering is defines as
(§25.4-4) If we define
equiv(a, b)
as!comp(a, b) && !comp(b, a)
, then the requirements are thatcomp
andequiv
both be transitive relations
where comp
is defined as
(§25.4-2)
Compare
is a function object type (20.9). The return value of the function call operation applied to an object of typeCompare
, when contextually converted tobool
(Clause 4), yieldstrue
if the first argument of the call is less than the second, andfalse
otherwise.Compare comp
is used throughout for algorithms assuming an ordering relation.
Question:
Does ">" satisfy strict weak ordering? I expect so, but have no confidence.
std::greater<>{}(5, 4)
5 is considered less than 4, so it needs to come first. Does that make sense? – Rustyrut<
, the phrase "is less than" means it has a smaller magnitude whereas later on, the phrase "is less than" means that it comes first in the particular strict weak ordering we are interested in. – Octavla<=
nor>=
satisfies strict weak ordering. – Disenchant