Marketing of D - article topic ideas?

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Tue Jun 8 05:28:48 PDT 2010


On 06/07/2010 05:16 PM, Nick Sabalausky wrote:
> "Nick Sabalausky"<a at a.a>  wrote in message
> news:hujd9m$11of$1 at digitalmars.com...
>> "Nick Sabalausky"<a at a.a>  wrote in message
>> news:hujd6a$11e8$1 at digitalmars.com...
>>>
>>> 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



More information about the Digitalmars-d mailing list