D2: Template as an alias to another template instance

Stanislav Blinov stanislav.blinov at gmail.com
Thu Dec 24 09:45:41 PST 2009


I'm trying to make a template that would be an alias to another template 
instance (sort of a shortcut), but I'm having some difficulties. 
Consider this code:


import std.stdio;

struct Templ(int N,T){}

alias Templ!(1,float) Templ1f;

template Templ1(T)
	alias Templ!(1,T) Templ1;

void foo1(T)(Templ!(1,T) t){}

void foo2(T)(Templ1!T t){}

void main()
	Templ1f t1f;
	Templ1!(float) t1f1;
	foo2(t1f1); // this doesn't compile
	// foo2(t1f); // this won't compile either


Unfortunately, dmd 2.032 on Windows and 2.037 on Linux both give me this 


templ.d(21): Error: template templ.foo2(T) does not match any function 
template declaration
templ.d(21): Error: template templ.foo2(T) cannot deduce template 
function from argument types !()(Templ!(1,float))


I had an impression that aliasing employed in Templ1 would effectively 
make Templ1 work as a type (a shortcut to Templ!(1,T)), but I don't get 
this behvior.
Now, I'm not lazy to declare functions with parameters having full 
template instance names. It's just that sometimes function declaration 
will be obvious (or at least cleaner) if its parameters have shorter but 
meaningful type names instead of generic name with a set of properties 
(that is, a template name with a full set of template parameters).

Is there something wrong with my code, am I missing something perhaps?

More information about the Digitalmars-d-learn mailing list