implementing default opCmp

ag0aep6g anonymous at example.com
Wed Nov 18 23:06:04 UTC 2020


On Wednesday, 18 November 2020 at 22:29:17 UTC, Steven 
Schveighoffer wrote:
> How do I do something really simple for opCmp? I tried this it 
> didn't work:
>
> return this == other ? 0 :
>     this.tupleof < other.tupleof ? -1 : 1;

std.typecons.Tuple has opCmp. So this works:

     int opCmp(S other)
     {
         import std.typecons: tuple;
         return tuple(this.tupleof).opCmp(tuple(other.tupleof));
     }


More information about the Digitalmars-d-learn mailing list