kennytm <[email protected]> wrote:
> Andrei Alexandrescu <[email protected]> wrote:
>
>> Heh, thanks. I reckon doing the equivalent for pointers would require
>> some unsavory manipulation.
>>
>> Andrei
>
> You may want you check Python's "cmp_to_key" function. In terms of D it
> would be like:
>
> struct CmpToKey(alias binaryPred, T) {
> int opCmp(other) { return binaryPred(this, other); }
> T wrapped;
> }
>
> Then sort/min/max by `cmpToKey!"a<b"(a)`.
Err I mean
int opCmp(other) {
if (binaryPred(this, other)) return -1;
else if (binaryPred(other, this)) return 1;
else return 0;
}