opCmp, [partial/total/pre]orders, custom floating point types etc.

John Colvin via Digitalmars-d digitalmars-d at puremagic.com
Tue Jan 12 13:00:16 PST 2016


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));
> }

Interesting, I'll have to think more about this. Pretty ugly to 
have to use floating point instructions for every comparison, no 
matter the actually data, but maybe there's something here...


More information about the Digitalmars-d mailing list