Template question about alias

Bill Baxter dnewsgroup at billbaxter.com
Sat Mar 22 18:08:20 PDT 2008


Edward Diener wrote:
> Another D template question.
> 
> I am assuming that one can not create a variable which refers to a 
> template instance, but one can create an "alias" for a template 
> instance, ie.
> 
> template MyTemplate(T) { T data; /* other decldefs ... */};
> MyTemplate!(int) aname; // illegal

This looks like the declaration of a class template instantiated for 
int.  So I'm glad that doesn't create an alias.  It would be very confusing.

> alias MyTemplate!(int) aname; // legal
> 
> Is this correct ? If it is so, why did D not just scrap the use of 
> 'alias' in this case and allow the first form, 'MyTemplate!(int) aname;' 

Because 'alias' is how you create type aliases in D.  I don't get why 
you'd view dispensening of the 'alias' there a benefit.

> to represent an alias automatically, since it would save endlessly 
> having to type 'alias' for a syntax which could not be anything else ?

--bb



More information about the Digitalmars-d mailing list