using unaryFun in functions that take a comparator (eg sort etc): sort!"a[0]" <=> sort!"a[0]<b[0]"
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Tue May 28 07:25:56 PDT 2013
On 5/28/13 4:16 AM, Timothee Cour wrote:
> very often I would wish that sort (+ related functions) could take
> unaryFun arguments and convert them to binaryFun as follows:
>
> //pseudocode:
> template unaryToBinaryComp(alias foo) {
> bool unaryToBinaryComp(T)(T a, T b) if (__traits(compiles,foo(a) <
> foo(b)) ) {
> return foo(a) < foo(b);
> }
> }
I actually have a branch in my code that does exactly that. I abandoned
it because the code, error messages, and documentation got really confusing.
It may be worth to add a keySort algorithm that only works with unary
keys, but then I thought people can always write a small lambda.
Andrei
More information about the Digitalmars-d
mailing list