Another interesting hack: expand a static array into parameter arguments
Andrej Mitrovic
andrej.mitrovich at gmail.com
Wed Apr 2 12:40:40 PDT 2014
-----
import std.stdio;
import std.typetuple;
auto Delay(alias arg, size_t idx)() { return arg[idx]; }
template expand(alias args, size_t idx = 0)
{
alias Args = typeof(args);
static if (is(Args : C[N], C, size_t N))
{
static if (idx < (N - 1))
alias expand = TypeTuple!(Delay!(args, idx),
expand!(args, idx + 1));
else
alias expand = Delay!(args, N - 1);
}
}
void foo(int a, int b, int c)
{
writefln("a: %s, b: %s, c: %s", a, b, c);
}
void main()
{
int[3] arr = [1, 2, 3];
foo(expand!arr);
}
-----
More information about the Digitalmars-d
mailing list