digitalmars.D - template arguments deduction (Limited)
- Genki Takiuchi (33/33) May 21 2004 I have tried to deduct arguments of template member function.
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.
May 21 2004