How to implement opCmp?

Honey via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jun 9 10:50:28 PDT 2017


On Friday, 9 June 2017 at 17:28:18 UTC, Steven Schveighoffer 
wrote:
> This is why I think such a function should exist in 
> Phobos/druntime. I'm not 100% sure it doesn't already, but I 
> couldn't find one...

Looking at the implementation of Tuple.opCmp, I'm not sure I'd 
bet on existence of opCmp for fundamental types:

         int opCmp(R)(R rhs)
         if (areCompatibleTuples!(typeof(this), R, "<"))
         {
             foreach (i, Unused; Types)
             {
                 if (field[i] != rhs.field[i])
                 {
                     return field[i] < rhs.field[i] ? -1 : 1;
                 }
             }
             return 0;
         }



More information about the Digitalmars-d-learn mailing list