3 ms·
This was my first encounter with the three-way comparison operator (<=>). Can someone give a practical use case? There must be one for it to be included in the
by mysterydip 3y ago
This was my first encounter with the three-way comparison operator (<=>). Can someone give a practical use case? There must be one for it to be included in the spec, but I'm not seeing it.
- wscott 3y agoread cppreference.com But the sort answer is all the other operators are automatically generated from that one if it is defined. So it makes the code simpler. And for many types <=> isn't much more complicated than the others
- craftit 3y agoIt saves writing lots of boilerplate. If you implement it for a type, you automatically get: <, >, <=, >=, ==, !=
- mysterydip 3y agoAh that makes sense, thanks! Then you can just do normal comparisons on the integer value of < > or == to 0.
- wkennington 3y agoIt also makes implementing all those operators easier for similar objects as you don’t need to plumb 6 different routines.