Wow, talk about enlightement. I think I've done it now:
import std.stdio;
import std.traits;
import std.metastrings;
template count(T...)
{
enum count = T.length;
}
template myCurry(alias fun, args...)
{
static if (args.length > (ParameterTypeTuple!fun).length)
{
static assert(0, Format!("Tried to pass %s arguments, max is %s.",
count!args, (ParameterTypeTuple!fun).length));
}
ReturnType!fun myCurry(T...)(T t)
{
return fun(args, t);
}
}
void foo(string x, int y, int z)
{
writeln(x, y, z);
}
alias myCurry!(foo, "bar") oneCurry;
alias myCurry!(foo, "bar", 1) twoCurry;
alias myCurry!(foo, "bar", 1, 2) threeCurry;
void main()
{
oneCurry(1, 2);
twoCurry(2);
threeCurry();
}