Template function limitations

Sean Kelly sean at f4.ca
Wed Sep 19 11:38:45 PDT 2007


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



More information about the Digitalmars-d mailing list