Comment #0 by monkeyworks12 — 2013-08-12T15:17:40Z
import std.typecons;
template Pair(T, U)
{
alias Pair = Tuple!(T, U);
}
T left(T, U)(Pair!(T, U) t)
{
return t[0];
}
void main()
{
//Error: template left(T, U)(Pair!(T, U) t) cannot deduce
//template function from argument types !()(Tuple!(int, string))
auto t = Pair!(int, string)(0, "");
assert(left(t) == 0);
}
This is really annoying, and it's going to get even worse when the new alias(T) syntax is introduced. I know that aliases are expanded before other stuff, but using `typedef Tuple!(T, U) Pair` instead gives the same error message. *Ideally*, I could also do something like this (this currently doesn't compile):
T left(T, U, Tup: Pair!(T, U))(Tup t)
{
return t[0];
}
Comment #1 by monkeyworks12 — 2013-08-12T15:25:36Z
It looks like there is a way to "work around" this:
import std.typecons;
alias Pair = Tuple;
T left(T, U)(Pair!(T, U) t)
{
return t[0];
}
void main()
{
//Ok
auto t = Pair!(int, string)(0, "");
assert(left(t) == 0);
}
I can't think of a different use-case at the moment that this doesn't cover, so I'll close this for the time being.