Comment #0 by andrej.mitrovich — 2012-10-16T20:12:56Z
import std.typetuple;
void func(alias arg)() { }
void main()
{
int x, y;
alias TypeTuple!(
func!(x),
func!(y),
) Map;
}
test.d(9): Error: template instance TypeTuple!(func,func) TypeTuple!(func,func) is nested in both func!(x) and func!(y)
But this works fine (notice 'y' isn't passed here):
void main()
{
int x, y;
alias TypeTuple!(
func!(x),
func!(x),
) Map;
}
This was while trying to implement an interesting question on SO: http://stackoverflow.com/questions/12888263/mapping-variadic-template-arguments-in-d
That solution is partially implementable by constructing function call expressions, however I can never get around this strange bug.
Comment #1 by andrej.mitrovich — 2012-10-16T20:26:04Z
Btw if you want to see some interesting code:
import std.stdio;
import std.typetuple;
int Delay(alias Call, alias arg)() { return Call(arg); }
template Map(alias Call, args...)
{
alias TypeTuple!(
Delay!(Call, args[0]),
//~ Delay!(Call, args[1]), // can't due to error
2 * 10 // pretend we could
) Map;
}
int fun(int arg)
{
return arg * 10;
}
void foo(Args...)(Args args)
{
print( Map!(fun, args) );
}
void print(int res1, int res2)
{
writefln("%s %s", res1, res2); // writes 10 20
}
void main()
{
int x = 1;
int y = 2;
foo(x, y);
}
Fun or what?
Comment #2 by andrej.mitrovich — 2012-10-16T20:27:16Z
(In reply to comment #1)
> int Delay(alias Call, alias arg)() { return Call(arg); }
Btw although 'auto' won't work here (forward reference error) we can easily use ReturnType!Call in the return type.