3 ms·
This operator already exists in Ruby, Perl and a couple other languages. It's also incredibly useful, allowing six functions to be replaced by one. Or, rather,
by slavik81 9y ago
This operator already exists in Ruby, Perl and a couple other languages.
It's also incredibly useful, allowing six functions to be replaced by one. Or, rather, with zero, because in 99.9% of cases you will just be able to declare the signature with '= default;' and let the compiler generate the implementation. Then you have all relational operators available for that type. It makes defining new types much, much easier.
Plus, it provides a place to statically define what sort of ordering the type has, so further compile-time optimizations can be done.
In contrast, <=> as is_ordered is nearly useless. It would basically only be used for floats, where !(isnan(a)||isnan(b)) is both equivalent and IMO more clear.