How to sort a 2D array by column

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Jun 7 12:29:46 PDT 2014


On 06/07/2014 12:18 PM, Chris Cain wrote:

> Also note that the examples use a string to define the predicate, but it
> accepts functions as well. Such as:
>
>      bool myCompareFunc(AType lhs, AType rhs)
>      {
>          return lhs.blah < rhs.blah;
>      }
>
>      //...
>      AType[] arr;
>      //...
>      arr.sort!myCompareFunc();

Just for completeness, lambdas as well:

     arr.sort!((a, b) => a.blah < b.blah);

Ali



More information about the Digitalmars-d-learn mailing list