language: D (dmd) (dmd-2.042)
date: 104 days 23 hours ago
link:
visibility: public
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import std.stdio, std.typecons;
 
int[] foo(T...)(T args)
{
    writeln("Called foo ...");
    foreach (i, arg; args)
        writefln("    args[%d] == %s", i, arg);
    writeln("... foo end");
 
    return [ 5, 10, 15, 20 ];
}
 
auto unpack(alias fun, V...)(ref Tuple!V t)
{
    auto f(size_t i, U...)(U args)
    {
        static if (i == 0)
            return fun(args);
        else
            return f!(i - 1)(t[i - 1], args);
    }
    return f!(V.length)();
}
 
void main()
{
    auto tup = tuple(
        5, 3.14f, "hello world", [ 5, 10, 15 ], [ "foo":5, "bar":10 ]
    );
 
    auto ret = unpack!foo(tup);
    writeln("retval from foo: ", ret);
}
 
prog.d(20): Error: no [] operator overload for type Tuple!(int,float,string,int[],int[string])