Operators as function arguments?
Jarrett Billingsley
kb3ctd2 at yahoo.com
Sat Mar 24 07:55:35 PDT 2007
"Falk Henrich" <schreibmalwieder at hammerfort.de> wrote in message
news:eu1cm8$k2i$1 at digitalmars.com...
>
> But this is extremely clumsy. Any idea?
>
Perhaps?
typeof(a[0]) reduce(alias a, alias func)()
{
auto ret = a[0];
foreach(v; a[1 .. $])
ret = func(ret, v);
return ret;
}
T[] cat(T)(T[] a, T[] b)
{
return a ~ b;
}
void main()
{
int[][] a = [[1, 2, 3], [4, 5, 6], [7, 8, 9]];
int[] b;
b = reduce!(a, cat)();
writefln(b);
}
Using the alias parameter for the function means you can no longer use
delegate literals for the function, but..
More information about the Digitalmars-d-learn
mailing list