I'm in the process of learning how comparisons work in C++20 and I'm struggling to understand one thing: since operator<=>
has to check for equality do we really need a separate operator==
? For example, the following check:
a == b
could be rewritten (by the compiler) as:
a.operator<=>(b) == 0
but instead, it will still try to call operator==
. Wouldn't it make more sense to deprecate operator==
and just use operator<=>
for both ordering and equality? In a case a class needs some custom ordering one has to implement both operator<=>
and operator==
which creates an additional room for error. Is there a reason there are now two ways to check for equality?