Marketing of D - article topic ideas?
BCS
none at anon.com
Mon Jun 7 18:59:18 PDT 2010
Hello Nick,
> "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 :)
>
so we have:
alias reduce!"a>b?a:b" range_max;
CommonType!(staticMap!(ElementType, T)) largestElement(T...)(T args)
{
static assert( !is(typeof(return) == void) );
return max( map!max(args) );
}
Why isn't that just one line, like:
alias polyMapReduce!(reduce!"a>b?a:b", "a>b?a:b") largestElelemt;
I'm shure a better one could be written but I think this would do it:
auto polyMapReduce(alias map, string reduce, T...)(T t)
{
static assert(T.length > 0);
static if(T.length > 1)
{
auto a = map(t[0]);
auto b = polyMapReduce!(map,reduce)(t[1..$]);
return mixin(reduce);
}
else
return map(t[0]);
}
--
... <IXOYE><
More information about the Digitalmars-d
mailing list