May 21, 2004 template arguments deduction (Limited) | ||||
|---|---|---|---|---|
| ||||
I have tried to deduct arguments of template member function. The result is as follows:
import std.c.stdio;
class Foo
{
//! interface
template func(alias arg1)
{
int func() { return funcImpl!(typeof(arg1))(arg1); }
}
//! implementation
template funcImpl(T1)
{
int funcImpl(T1 value)
{
printf("%.*s\n", value.toString());
return 0;
}
}
}
class Bar { char[] toString() { return "I am Bar!"; } }
class Baz { char[] toString() { return "I am Baz!"; } }
Bar bar;
Baz baz;
void main(char[][] arg)
{
Foo foo = new Foo;
bar = new Bar;
foo.func!(bar)();
baz = new Baz;
foo.func!(baz)();
}
However, deductable arguments are limited to things able to be alias.
| ||||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply