On Friday, 27 May 2016 at 18:26:07 UTC, Vladimir Panteleev wrote:
https://github.com/CyberShadow/ae/blob/master/utils/meta/args.d
:D
Nice work! Is it intentional to require default parameters? I
think you can change lines 34-36:
foreach (i, arg; ParameterDefaults!fun)
static if (i >= posArgs.length)
args[i] = ParameterDefaults!fun[i];
into
foreach (i, arg; ParameterDefaults!fun)
static if (i >= posArgs.length) {
static if (is(arg==void))
args[i] = Parameters!fun[i].init;
else
args[i] = arg;
}
That makes this work:
import ae.utils.meta.args;
void fun(int one, int two, double three, string four)
{
import std.stdio;
writeln("one=", one, "; two=", two, "; three=", three, ";
four=", four);
}
void main(string[] a)
{
args!(fun, four=>"4", two=>2, one=>a.length, three=>3.0);
}
By the way your unit tests don't really test that named arguments
can be given in arbitrary order (although they can) as summation
is communitative.
Bastiaan.