The Many Faces of D - slides
Walter Bright
newshound2 at digitalmars.com
Mon Oct 4 00:05:28 PDT 2010
Peter Alexander wrote:
> == Quote from Walter Bright (newshound2 at digitalmars.com)'s article
>> This can be defined instead as:
>> alias reduce!"a+b" sum;
>
> But then you have to write:
>
> sum(sequence, 0)
>
> which is very unintuitive.
This works:
import std.stdio;
import std.algorithm;
alias reduce!"a+b" sum;
auto sumOfSquares( R )( R range ) {
return sum( map!"a*a"( range ) );
}
void main()
{
writeln(sumOfSquares([1,2,3]));
}
More information about the Digitalmars-d
mailing list