[class.spaceship] (original) (raw)

11 Classes [class]

11.10 Comparisons [class.compare]

11.10.3 Three-way comparison [class.spaceship]

The synthesized three-way comparisonof type R ([cmp.categories]) of glvalues a and b of the same type is defined as follows:

[Note 1:

A synthesized three-way comparison is ill-formed if overload resolution finds usable candidates that do not otherwise meet the requirements implied by the defined expression.

— _end note_]

Let R be the declared return type of a defaulted three-way comparison operator function, and let be the elements of the expanded list of subobjects for an object x of type C.

The return value of type Rof the defaulted three-way comparison operator function with parameters x and y of the same type is determined by comparing corresponding elements and in the expanded lists of subobjects for x and y(in increasing index order) until the first index i where the synthesized three-way comparison of type Rbetween and yields a result value where , contextually converted to bool, yields true.

The return value is a copy of if such an index exists andstatic_cast<R>(std​::​strong_ordering​::​equal) otherwise.

The common comparison type Uof a possibly-empty list of n comparison category types, , …, is defined as follows: