args

Simulates named arguments for function calls. Accepts arguments as lambdas (name => value) on the template parameter list, and positional arguments on the runtime parameter list (see examples below).

template args(alias fun, dgs...)
args
(
PosArgs...
)
(
auto ref PosArgs posArgs
)
if (
is(typeof(fun) == function)
)

Examples

static int fun(int a=1, int b=2, int c=3, int d=4, int e=5)
{
	return a+b+c+d+e;
}

assert(args!(fun) == 15);
assert(args!(fun, b=>3) == 16);
assert(args!(fun, b=>3, d=>3) == 15);

Mixing named and positional arguments

static int fun(int a, int b=2, int c=3, int d=4, int e=5)
{
	return a+b+c+d+e;
}

assert(args!(fun)(1) == 15);
assert(args!(fun, b=>3)(1) == 16);
Suggestion Box / Bug Report