Grey area: template specializations based on other templates with tuples
Jarrett Billingsley
kb3ctd2 at yahoo.com
Sat Nov 17 08:15:04 PST 2007
You can specialize a template on an instantiation of another template, like
so:
struct Temp(T)
{
T t;
}
void fooImpl(T : Temp!(U))(T t)
{
Stdout.formatln("is a temp: {}", t.t);
}
void fooImpl(T)(T t)
{
Stdout.formatln("is not a temp: {}", t);
}
void foo(T)(T t)
{
fooImpl!(T)(t);
}
void main()
{
Temp!(int) x;
x.t = 5;
foo(x);
foo(7);
}
This will print:
is a temp: 5
is not a temp: 7
as expected.
However, throw tuples into the mix and the matching no longer seems to work:
struct Temp(T, U...)
{
T t;
}
void fooImpl(T : Temp!(U, V))(T t)
{
Stdout.formatln("is a temp: {}", t.t);
}
void fooImpl(T)(T t)
{
Stdout.formatln("is not a temp: {}", t);
}
void foo(T)(T t)
{
fooImpl!(T)(t);
}
void main()
{
Temp!(int) x;
x.t = 5;
Temp!(float, float) y;
y.t = 3.4;
foo(x);
foo(y);
foo(7);
}
This prints:
is a temp: 5
is not a temp: {unhandled argument type: dtest.Temp!(float,float).Temp}
is not a temp: 7
Notice that the match in fooImpl has been changed to T : Temp!(U, V), and
that it works for Temp!(int) but not for Temp!(float, float).
Only thing is, I can't find anything in the spec about this, so I don't know
if it's behaving properly. I think it isn't. Thoughts?
More information about the Digitalmars-d-bugs
mailing list