3 ms·
One of the goals is to eliminate boilerplate. If I'm remembering my C++ correctly,!=, <=, >, and >= can be easily defined in terms of < and ==, but programmers
by aw1621107 7y ago
One of the goals is to eliminate boilerplate. If I'm remembering my C++ correctly,!=, <=, >, and >= can be easily defined in terms of < and ==, but programmers were required to spell out the definitions for all the operators manually. With operator<=>, one definition would allow the compiler to generate all 6 operators.
There are some correctness and efficiency concerns operator<=> addresses, too, but I'm not confident I can explain those well.
You can read more in P0515R0 [0], which sort of "rolls up" previous papers discussing comparisons.
[0]: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0515r0.pdf http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p051...
- contravariant 7y agoTechnically you don't even need both '<' and '=='. Just '<=' will do if you follow the mathematical definitions (i.e. a <= b and b <= a implies a == b). This is not always the most efficient, but it's not the worst option.
- aw1621107 7y agoAh, you're right. I don't see programmers defining the operators that way very frequently for one reason or another, but perhaps I just need to be exposed to more code bases.