Using C++20's Three-way Comparison <=>
summary
C++20's three-way comparison (<=>) lets classes delegate comparison logic to the compiler by writing a defaulted <=>, which yields lexicographic member-wise ordering and auto-generates == and relational operators to eliminate boilerplate. It introduces the comparison category types strong_ordering, weak_ordering, and partial_ordering, defines operator-rewriting rules for templates and containers, and discusses pitfalls such as floating-point partial orders, implicit conversions, and heterogeneous comparison overload resolution.
AI-written summary · about
chapters (8)
- 0:00Introduction to C++20 comparison
- 7:31Default comparison operators
- 15:01Member function comparison
- 22:22Spaceship operator use cases
- 33:39Library and container support
- 40:45Global comparison operator
- 45:28Optional and custom comparison
- 51:33Summary and Q&A
related talks
01h 02m“Operator Overloading: History, Principles and Practice”
52m“Regular Types and Why Do I Care ?”
01h 00mThe Small Pearls of C++20
01h 06mRegular Types: From Stepanov to C++ Concepts
01h 01mMoving to C++20 for Fun, Beauty... and Results!
46mComparison is not simple, but it can be simpler
01h 02mC++20 - My Favourite Code Examples
24mC++17 and 20 Goodies
