Space Invaders: The Spaceship Operator is upon us

By Lieven de Cock

Before C++20 we had to write 6 comparison operators for our user defined types (or even more). For sure, a tedious task. All this gets simplified with the introduction of the spaceship operator.

What happens to your code, when you turn on “-std=c20” even before we go near the spaceship operator, did your build break? Why does that happen? We will first investigate, another new feature of C20, the rewriting rules, and how that impacts your code base. And then we will dissect the spaceship operator, from a using perspective, and from an implementation perspective. Oh yes, comparison categories, what are those, and why are these important with respect to the spaceship operator? All will be answered, what initially looked so simple, does require some extra thoughts it seems to correctly use the tool.





Your Privacy

By clicking "Accept Non-Essential Cookies" you agree ACCU can store non-essential cookies on your device and disclose information in accordance with our Privacy Policy and Cookie Policy.

Current Setting: Non-Essential Cookies REJECTED


By clicking "Include Third Party Content" you agree ACCU can forward your IP address to third-party sites (such as YouTube) to enhance the information presented on this site, and that third-party sites may store cookies on your device.

Current Setting: Third Party Content EXCLUDED



Settings can be changed at any time from the Cookie Policy page.