Fixing opEquals and opCmp

Fool via Digitalmars-d digitalmars-d at puremagic.com
Sat May 13 08:00:27 PDT 2017


On Saturday, 13 May 2017 at 14:17:24 UTC, H. S. Teoh wrote:
> Andrei specifically stated before that opCmp may model a 
> partial order, i.e., returning 0 may indicate "not comparable" 
> rather than "equal".

Well, that's unsound.

Example: 'is (proper) subset of'

Given the sets a:= {1} and b:= {2}, we have

  a is not a proper subset of b;
  b is not a proper subset of a;

If a.opCmp(b) returns 0 in this situation then, due to the rewrite

  a <= b   a.opCmp(b) <= 0,

we have:

  a is a subset of b


More information about the Digitalmars-d mailing list