# 11 Classes [class]

## 11.10 Comparisons [class.compare]

### 11.10.3 Three-way comparison [class.spaceship]

Given an expanded list of subobjects for an object x of type C, the type of the expression <=> is denoted by .
If the declared return type of a defaulted three-way comparison operator function is auto, then the return type is deduced as the common comparison type (see below) of , , , .
[Note
:
Otherwise, the program will be ill-formed if the expression <=> is not implicitly convertible to the declared return type for any i.
end note
]
If the return type is deduced as void, the operator function is defined as deleted.
The return value V of type R of 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 <=> yields a result value where , contextually converted to bool, yields true; V is converted to R.
If no such index exists, V is std::strong_­ordering::equal converted to R.
The common comparison type U of a possibly-empty list of n types , , , is defined as follows:
• If any is not a comparison category type ([cmp.categories]), U is void.
• Otherwise, if at least one is std::weak_­equality, or at least one is std::strong_­equality and at least one is std::partial_­ordering or std::weak_­ordering, U is std::weak_­equality ([cmp.weakeq]).
• Otherwise, if at least one is std::strong_­equality, U is std::strong_­equality ([cmp.strongeq]).
• Otherwise, if at least one is std::partial_­ordering, U is std::partial_­ordering ([cmp.partialord]).
• Otherwise, if at least one is std::weak_­ordering, U is std::weak_­ordering ([cmp.weakord]).
• Otherwise, U is std::strong_­ordering ([cmp.strongord]).
[Note
:
In particular, this is the result when n is 0.
end note
]