Template Arguments

Don Clugston dac at nospam.com.au
Tue Jan 9 03:06:58 PST 2007


Xinok wrote:
> Is it possible to create template parameters in the D language?
> template <template <class T> class T> class N;
> 
> I think this would be the most obvious syntax, but it doesn't seem to work:
> template temp(template T(T1)){ }

Too complicated, and not powerful enough!

template temp(alias T) {
    T!(T1);
}

alias parameters are a generalisation of template template parameters.
T1 doesn't have to be a template, just anything that has a name.

> My second question, is it possible to specialize by template arguments?
> template temp(T : T!(T1 : int))

Yes.

template temp(alias T1: T!(int) )
{
}

And you can have default alias template arguments, too.




More information about the Digitalmars-d mailing list