Re:The C++20 Naughty and Nice List for Game Devs
by mysterydip on Monday December 25, 2023 @07:33AM
(#38762107)
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.
[ Parent
| on HN ]
Re:The C++20 Naughty and Nice List for Game Devs
by craftit on Monday December 25, 2023 @07:41AM
(#38762149)
It saves writing lots of boilerplate. If you implement it for a type, you automatically get: <, >, <=, >=, ==, !=
Re:The C++20 Naughty and Nice List for Game Devs
by mysterydip on Monday December 25, 2023 @07:59AM
(#38762250)
Ah that makes sense, thanks! Then you can just do normal comparisons on the integer value of < > or == to 0.
Re:The C++20 Naughty and Nice List for Game Devs
by wkennington on Monday December 25, 2023 @11:51PM
(#38769018)
It also makes implementing all those operators easier for similar objects as you don’t need to plumb 6 different routines.
Re:The C++20 Naughty and Nice List for Game Devs
by wscott on Monday December 25, 2023 @07:40AM
(#38762146)
read 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