The Compiler-generated Spaceship Operator

Learn how a three-way comparison operator works.

The compiler-generated three-way comparison operator needs the header <compare>, is implicitly constexpr and noexcept, and it performs a lexicographical comparison. You can even directly use the three-way comparison operator.

Direct use of the three-way comparison operator

The following program directly uses the spaceship operator.

Get hands-on with 1200+ tech skills courses.