implementing default opCmp

Steven Schveighoffer schveiguy at gmail.com
Thu Nov 19 14:12:39 UTC 2020


On 11/18/20 6:06 PM, ag0aep6g wrote:
> 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));
>      }


Ah, excellent solution! I hadn't thought of that.

-Steve


More information about the Digitalmars-d-learn mailing list