Learning about the C++ spaceship operator
As this is a short chapter, I thought it would be a good place to learn some more C++. We don’t need this theory in the current project. Yes, the spaceship operator is a real thing. It is another neat C++ operator.
The spaceship operator, represented by <=>
, is a relatively new addition to the C++ language, introduced in C++20. It is used for three-way comparisons between two objects, which means it helps determine whether one object is less than, equal to, or greater than another. The spaceship operator returns one of three values: <, ==, or >, indicating the relationship between the two objects. Here’s how it works.
If the LHS of the spaceship operator is less than the RHS, it returns a negative value. This indicates that the LHS is “less than” the RHS.
If the LHS is equal to the RHS, it returns 0. This indicates that the two objects are equal.
If the LHS is greater than the RHS, it...