When you use:
auto operator<=>(const X&) const = default;
the compiler automatically synthesizes operator==
for you, because it knows your intent to use defaulted comparisons for this type.
However, when you define:
auto operator<=>(const X& other) const { return Dummy <=> other.Dummy; }
you’re providing a custom implementation, and the compiler no longer assumes what equality should mean, so it does not generate operator==
.
If you still want ==
support with a custom <=>
, you must define it manually, like this:
#include <compare>
struct X {
int Dummy = 0;
auto operator<=>(const X& other) const {
return Dummy <=> other.Dummy;
}
bool operator==(const X& other) const {
return (*this <=> other) == 0;
}
};
This tells the compiler explicitly what equality means based on your comparison logic.