On 15.01.2016 21:42, Nordlöw wrote:
How do I index a function parameter tuple with a run-time index?

With a switch and a static foreach:

----
void f(A...)(size_t i, A a)
{
    import std.stdio: writeln;
    switch_: switch (i)
    {
        foreach (iT, T; A)
        {
            case iT: writeln(T.stringof); break switch_;
        }
        default: writeln("??"); break;
    }
}

void main()
{
    f(0, "foo", 42); /* string */
    f(1, "foo", 42); /* int */
    f(2, "foo", 42); /* ?? */
}
----

Reply via email to