C++ Logo

std-discussion

Advanced search

Re: The std::equality_comparable concept and reflexivity.

From: Jan Schultke <janschultke_at_[hidden]>
Date: Wed, 30 Jul 2025 07:48:05 +0200
> This got me wondering whether reflexivity
> is a semantic requirement of std::equality_comparable or not?

My reading is that it's not a requirement.
To model weakly-equality-comparable-with<T,U>,
with lvalues t and u of types T and U,
the following requirement has to be met:

> bool(t != u) == !bool(t == u).

See https://eel.is/c++draft/concept.equalitycomparable

For a value such as NaN, this is "false == true" because all
comparisons are false. If a value was equal to all other values but
not to itself, then equality wouldn't be transitive, so that also
wouldn't work. HOWEVER, if == always yields false and != always yields
true, then it seems like all the requirements are met.

I don't know what the motivation is, seeing that NaN is not supported,
but I suppose it's a slightly more minimalistic requirement if we
allow values that are equal to nothing, not even themselves, even
though I cannot think of a good use case.

Received on 2025-07-30 05:48:19