3 ms·
One of the useful things added is that the language can now define a default <=> operator for your own classes, for example if you had struct Foo {int a; int b;
by HarHarVeryFunny 7y ago
One of the useful things added is that the language can now define a default <=> operator for your own classes, for example if you had struct Foo {int a; int b;} previously you'd have had to define your own comparison operators such as:
bool operator<(const Foo& foo) const
{
if (a < foo.a) return true;
if (a > foo.a) return false;
if (b < foo.b) return true;
if (b > foo.b) return false;
return false;
}
.. and all the other comparison operators that you needed.
But now, you can just say:
auto operator<=>(const Foo&) const = default;
and the compiler will automatically generate all the operators for you.