proposals/p1178.md
Our operator interface names need to be updated to match the decision in #1058. Further, we are missing a description of the interfaces used to overload comparison operators, and the rules are not up to date with the decision in #710.
See the two leads issues for background and discussion of options.
See changes to the design.
Beyond establishing names for interfaces, this proposal also establishes:
== and !=. The relational
comparison interface provides all of <, <=, >, and >=.T is EqWith(T) is equivalent to T is Eq.bool.It is intended that we also provide low-level interfaces, to directly control
individual operators and to allow a result type other than bool. These are not
included in this proposal, as it's not yet clear how they should be specified,
and it's more important to get the high-level interfaces decided at this point.
Ordered doesn't satisfy the
expected rules and produce a warning.== and ordering to be customized separately, in order to
avoid cases where a suboptimal == is constructed in terms of an
ordering. See
C++ committee paper P1190R0
for details on the problem.ComparableWith instead of OrderedWithWe could use the term "comparable" for relational comparisons instead of
"ordered". There is existing practice for both: for example, Rust and Haskell
use Ord, and Swift uses Comparable.
The main argument for using "ordered" instead of "comparable" is that == and
!= are also a form of comparison but aren't part of OrderedWith, and the
word "ordered" distinguishes relational comparison from equality comparison.