Date: Wed, 30 Jul 2025 02:46:42 +0300
Hello everyone!
Recently I've noticed that reflexivity was removed from the semantic
requirements' note of std::equality_comparable:
- [concept.equalitycomparable] Remove note that the equality-preserving
nature of == implies that == is reflexive.
This turns out to not quite be justified by the normative rules.
<https://github.com/cplusplus/draft/commit/01f681dd376ec6285fae0253d21745999fd9557f>
This got me wondering whether reflexivity is a semantic requirement of std::
equality_comparable or not?
As far as I understand, the intention behind the
std::equality_comparable concept
is to represent types,
which provide operator == implementing mathematical equality, which is, by
definition,
reflexive, symmetric and transitive, so I would say that transitivity
should be one of the semantic requirements.
However, when I look at the wording of [concept.equalitycomparable]/2, I'm
not so sure:
*Let *a* and *b* be objects of type *T*.*
T* models *equality_comparable* only if *bool(a == b)* is *true* when *a* is
> equal to *b*, and *false* otherwise. *
Is it valid for a type modelling std::equality_comparable to return false
from operator == when a does equal to b,
as long as, that operator == never returns true when a does not equal to b?
In order words, does std::equality_comparable concept permits
non-comparable values, such as NaN?
The phrase *"(...) and *false* otherwise."* might suggest that. The
description, available on *cppreference.com*
<https://cppreference.com/w/cpp/concepts/equality_comparable.html>,
of semantic requirements of the std::equality_comparable concept explicitly
permits non-comparable values:
std::equality_comparable<T> is modeled only if,
given objects a and b of type T, bool(a == b) is true if and only if a
and b are
> equal.
>
Together with the requirement that a == b is equality-preserving,
this implies that == is symmetric and transitive,
and further that == is reflexive for all objects a that are equal to at
> least one other object.
Does the wording of the normative rule [concept.equalitycomparable]/2
intentionally permits non-comparable values,
in order to allow floating-point types, such as float and double, to model
the std::equality_comparable concept?
Thank you, Mateusz Zych
Recently I've noticed that reflexivity was removed from the semantic
requirements' note of std::equality_comparable:
- [concept.equalitycomparable] Remove note that the equality-preserving
nature of == implies that == is reflexive.
This turns out to not quite be justified by the normative rules.
<https://github.com/cplusplus/draft/commit/01f681dd376ec6285fae0253d21745999fd9557f>
This got me wondering whether reflexivity is a semantic requirement of std::
equality_comparable or not?
As far as I understand, the intention behind the
std::equality_comparable concept
is to represent types,
which provide operator == implementing mathematical equality, which is, by
definition,
reflexive, symmetric and transitive, so I would say that transitivity
should be one of the semantic requirements.
However, when I look at the wording of [concept.equalitycomparable]/2, I'm
not so sure:
*Let *a* and *b* be objects of type *T*.*
T* models *equality_comparable* only if *bool(a == b)* is *true* when *a* is
> equal to *b*, and *false* otherwise. *
Is it valid for a type modelling std::equality_comparable to return false
from operator == when a does equal to b,
as long as, that operator == never returns true when a does not equal to b?
In order words, does std::equality_comparable concept permits
non-comparable values, such as NaN?
The phrase *"(...) and *false* otherwise."* might suggest that. The
description, available on *cppreference.com*
<https://cppreference.com/w/cpp/concepts/equality_comparable.html>,
of semantic requirements of the std::equality_comparable concept explicitly
permits non-comparable values:
std::equality_comparable<T> is modeled only if,
given objects a and b of type T, bool(a == b) is true if and only if a
and b are
> equal.
>
Together with the requirement that a == b is equality-preserving,
this implies that == is symmetric and transitive,
and further that == is reflexive for all objects a that are equal to at
> least one other object.
Does the wording of the normative rule [concept.equalitycomparable]/2
intentionally permits non-comparable values,
in order to allow floating-point types, such as float and double, to model
the std::equality_comparable concept?
Thank you, Mateusz Zych
Received on 2025-07-29 23:46:57