Partial template function specialization
Lutger
lutger.blijdestijn at gmail.com
Thu Aug 20 08:23:22 PDT 2009
You can also do this with template constraints in D2:
template foo(T, U)
if ( is(T == int) )
{
void foo(T t, U u)
{
//t is int
}
}
template foo(T, U)
if ( is(T == string) )
{
void foo(T t, U u)
{
//t is string
}
}
IFTI still works here: foo("bla", 1) and foo(1,1) are both valid
You can do almost anything in the if condition (constraint) that can
evaluate to bool at compile time. See std.traits and the __traits keywords
for useful stuff.
More information about the Digitalmars-d-learn
mailing list