Why doesn't curry work with multiple arguments?
Andrej Mitrovic
andrej.mitrovich at gmail.com
Wed Apr 6 14:36:10 PDT 2011
Ok, enjoy this monstrosity:
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));
}
static if (is(typeof(fun) == delegate) || is(typeof(fun) == function))
{
static if ((ParameterTypeTuple!fun).length - count!args)
{
ReturnType!fun myCurry(ParameterTypeTuple!fun[0 ..
(ParameterTypeTuple!fun).length - count!args] myarg)
{
return fun(args, myarg);
}
}
else
{
ReturnType!fun myCurry()
{
return fun(args);
}
}
}
}
More information about the Digitalmars-d-learn
mailing list