opCmp, [partial/total/pre]orders, custom floating point types etc.
Timon Gehr via Digitalmars-d
digitalmars-d at puremagic.com
Tue Jan 12 13:27:38 PST 2016
On 01/12/2016 10:02 PM, John Colvin wrote:
> On Tuesday, 12 January 2016 at 20:52:51 UTC, Timon Gehr wrote:
>> On 01/12/2016 07:27 PM, John Colvin wrote:
>>> ...
>>
>>
>> struct S{
>> auto opCmp(S rhs){ return float.nan; }
>> bool opEquals(S rhs){ return false; }
>> }
>>
>> unittest{
>> S a,b;
>> assert(!(a==b));
>> assert(!(a<b));
>> assert(!(a<=b));
>> assert(!(a>b));
>> assert(!(a>=b));
>> }
>
> what about classes and Object.opCmp?
You can introduce a new opCmp signature in your subclass, but == is
enforced to be reflexive for class objects. So this approach only really
works for structs. (And for structs, it is obviously a hack.)
More information about the Digitalmars-d
mailing list