swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.49k stars 10.35k forks source link

[SR-4002] Change Comparable to support ternary comparison #46587

Open airspeedswift opened 7 years ago

airspeedswift commented 7 years ago
Previous ID SR-4002
Radar rdar://problem/17191993
Original Reporter @airspeedswift
Type Improvement
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Standard Library | |Labels | Improvement, swift-evolution-proposal-needed | |Assignee | None | |Priority | Medium | md5: 4358b25b7134cfa112592b2bdfc49432

Issue Description:

Equatable and Comparable currently require implementation of == and \< respectively.

There are many benefits to replacing the \< operation of Comparable to return a ternary enum for less, equal, greater. == and \< could then be implemented in terms of it.

For simplicity and source compatibility, implementations of == / \< should still be accepted as fulfilling the requirements of the ternary equivalent.

airspeedswift commented 6 years ago

Removing ABI keyword. If this proposal is made, it will need to be made in a way that doesn't affect the ABI.