On 06/07/2010 05:16 PM, Nick Sabalausky wrote:
"Nick Sabalausky"<[email protected]>  wrote in message
news:[email protected]...
"Nick Sabalausky"<[email protected]>  wrote in message
news:[email protected]...

Assuming, of course, a 'max' that works on a range, which would be easy
enough to do. Probably something like:


ElementType!T max(T range)  // Corrected

{
    return reduce!ordinaryMax(range);
    // Or
    return reduce!"a>b?a:b"(range);
}



Or:

alias reduce!"a>b?a:b" max;

God, I love D :)

This is kind of funny. This works because reduce is defined as follows:

template reduce(alias fun)
{
    alias Reduce!(fun).reduce reduce;
}

I did that to work around some old compiler bugs that have been since fixed. I'd initially intended to define reduce like this:

Unqual!E reduce(alias fun, E, R)(E seed, R r) { ... }

but that wouldn't have allowed Nick's alias, which is quite useful. So it looks like we have a cool idiom.


Andrei

Reply via email to