Почему я должен предоставить «Оператор ==», когда «оператора <=>» достаточно?C++

Программы на C++. Форум разработчиков
Anonymous
Почему я должен предоставить «Оператор ==», когда «оператора <=>» достаточно?

Сообщение Anonymous »

Код: Выделить всё

#include 

struct A
{
int n;

auto operator(A const& other) const
{
if (n < other.n)
{
return std::strong_ordering::less;
}
else if (n > other.n)
{
return std::strong_ordering::greater;
}
else
{
return std::strong_ordering::equal;
}
}

// compile error if the following code is commented out.
// bool operator==(A const& other) const
// { return n == other.n; }
};

int main()
{
A{} == A{};
}
См. Демо -онлайн
Почему я должен предоставить operator == , когда operator достаточно?

Подробнее здесь: https://stackoverflow.com/questions/682 ... -is-enough

Вернуться в «C++»