Problem with templates
Sean Reque
seanthenewt at yahoo.com
Mon Jul 7 10:23:30 PDT 2008
Never mind, I wrote the function wrong. This actually works. Alpha compilers have terrible error messages sometimes!
import std.stdio;
/* R is return type
* A is first argument type
* U is TypeTuple of rest of argument types
*/
R delegate(U) Curry(R, A, U...)(R delegate(A, U) dg, A arg)
{
return delegate R(U args) { return dg(arg, args); };
}
void main()
{
int plus(int x, int y, int z)
{
return x + y + z;
}
auto plus_two = Curry(&plus, 2);
writefln("%d", plus_two(6, 8)); // prints 16
}
More information about the Digitalmars-d-learn
mailing list