digitalmars.D.bugs - Template specialisation does not agree with documents (0.88)
- Mike Wynn (83/83) May 08 2004 template.html constaines the following example
template.html constaines the following example template TBar(T : U*, U : A) { } alias TBar!(B*, B) Foo5; // (2) T is B* // (3) U is B so I tried the following ..... ------------------------------------------ template typename( T : U*, U = short ) { static char[] name() { return "some stuff"; } } int main( char[][] args ) { printf( "typename!(short*).getname=%.*s\n", typename!(short*).name ); return 0; } //temt01.d(2): identifier 'U' is not defined ------------------------------------------ template typename( T : U*, U : short ) { static char[] name() { return "some stuff"; } } int main( char[][] args ) { printf( "typename!(short*, short).getname=%.*s\n", typename!(short*, short).name ); return 0; } // temt02.d(2): identifier 'U' is not defined ------------------------------------------ these do not work. this is related to another post for matching to a assoc array the D docs imply that you may be able to do template typename( T : T[U] ) { } I agree that U here may be viewed as an undef identifier so the option is to do template typename( T : T[U], U ) { } (but you need to declate the key type) i.e. typename( int[char[]], char[] ) so I though maybe template typename( T : T[U], U = int ) { } which should match (char[int]) with T=char U= int) or template typename( T : T[U], U : int = int ) { } I also understand why you would do stuff( D, E: D[] ) but stuff( Base, Derv[] ) does not match! ------------------------------ class Base {} class Derv : Base {} template typename( T , U : T[] ) { static char[] name() { return "some stuff"; } } int main( char[][] args ) { printf( "typename!(Base, Derv[]).getname=%.*s\n", typename!(Base, Derv[]).name ); return 0; } // template instance typename!(Base ,Derv []) does not match any template declaration ---------------------------------------------- even ------------------------------- template typename( T , U : T ) { static char[] name() { return "some stuff"; } } int main( char[][] args ) { printf( "typename!(Base, Derv).getname=%.*s\n", typename!(Base, Derv).name ); return 0; } -------------------------------------- does not match but I though ( T : class ) was match class or sub class i.e ( T: Object ) would match Foo so why does (Base,Derv) not match ( T, U : T ) it matches ( T:Base, U:Base ) and (Base,Derv[]) not match ( T, U : T[] ) it does match ( T : Base, U : Base[] ) without that there is no point to this particual syntax as U will only be T/T[] so you might as well do template foo(T) { alias T[] U; .... } it would be usefull for collection classes etc to match sub classes.
May 08 2004