On 7/23/14, 11:52 AM, H. S. Teoh via Digitalmars-d wrote:
On Wed, Jul 23, 2014 at 11:48:42AM -0700, Andrei Alexandrescu via Digitalmars-d
wrote:
On 7/23/14, 9:45 AM, H. S. Teoh via Digitalmars-d wrote:
Why isn't "a==b" rewritten as "a.opCmp(b)==0"?? I'm pretty sure TDPL
says this is the case (unfortunately I'm at work so I can't check my
copy of TDPL).
https://issues.dlang.org/show_bug.cgi?id=13179
:-(
It's a good decision. There are types that are comparable for equality
but not compared for ordering. -- Andrei
That's the wrong way round.
No.
I fully agree that we should not
autogenerate opCmp if the user defines opEquals, since not all types
comparable with equality are orderable. However, surely all orderable
types are equality-comparable!
http://en.wikipedia.org/wiki/Lattice_(order)
Therefore, if opCmp is defined but
opEquals isn't, then we should autogenerate opEquals to be the same as
a.opCmp(b)==0.
It's a sensible decision, but I'm not so sure.
Andrei