digitalmars.D - Template function limitations
- Sean Kelly (31/31) Sep 19 2007 I've been playing with template functions over the past few days and
- Janice Caron (6/7) Sep 19 2007 Shouldn't that be
- Sean Kelly (3/12) Sep 19 2007 Perhaps, but I get the same error with and without "alias."
I've been playing with template functions over the past few days and have been wondering about how much detail they should be able to infer about a parameter. In particular, template template parameters seem to have only limited support. For example: class One(T) {} class Two(T, U) {} void fnA(T)( One!(T) val ) {} void fnB(T,U)( T!(U) val ) {} void fnC(T...)( Two!(T) val ) {} void main() { fnA( new One!(int) ); // works fnB( new One!(int) ); // test.d(14): template test.fnB(T,U) does not match any // template declaration // test.d(14): template test.fnB(T,U) cannot deduce template // function from argument types (One) fnB!(One,int)( new One!(int) ); // test.d(21): template instance fnB!(One,int) does not match // any template declaration // test.d(21): Error: template instance 'fnB!(One,int)' is not // a variable fnC( new Two!(int,int) ); // test.d(27): template test.fnC(T...) does not match any // template declaration // test.d(27): template test.fnC(T...) cannot deduce template // function from argument types (Two) } Which of the above functions /should/ work? Sean
Sep 19 2007
On 9/19/07, Sean Kelly <sean f4.ca> wrote:void fnB(T,U)( T!(U) val ) {}Shouldn't that be void fnB(alias T,U)( T!(U) val ) {} ? I could be wrong, but I thought "alias" was necessary if you want a template template parameter.
Sep 19 2007
Janice Caron wrote:On 9/19/07, Sean Kelly <sean f4.ca> wrote:Perhaps, but I get the same error with and without "alias." Seanvoid fnB(T,U)( T!(U) val ) {}Shouldn't that be void fnB(alias T,U)( T!(U) val ) {} ? I could be wrong, but I thought "alias" was necessary if you want a template template parameter.
Sep 19 2007