Using C++20’s Three-way Comparison <=>

CppCon

C++20 adds the “spaceship operator” <=> for three-way comparison, fundamentally changing the way we implement comparison. But there are a lot more changes: Comparison categories will give more structure, and the new operator rewriting rules will massively reduce boilerplate. And like most C++ features, there are a couple of caveats we need to be aware of.

This talk will cover all the changes and give guidelines on how to use them. It will be very practical, answering questions like: How do I write a comparison operator for my classes? How do I write it for a generic container? How should I implement algorithms to leverage the three-way comparison? How do I handle all the types written without <=>?

Whether you are writing concrete applications or generic library code, you will have the necessary knowledge to apply the new features. And even if you cannot use C++20 in the foreseeable future, you will have a deeper understanding on proper comparison design.

See Also