Template Arguments

Xinok xnknet at gmail.com
Tue Jan 9 08:49:14 PST 2007


Don Clugston Wrote:

> 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.

I see template parameters as a 'self documenting' feature, so the developer knows two things:
1) The template is looking for a template
2) The dev knows what arguments the template needs

If you apply a template to an alias, you can basically make any template compatible with the template argument:

template a(int V, T){ }

template b(template T(T, int V)){ }

template al(T, int V){
	alias a!(V, T) al;
}

b!(al) // Makes template 'b' compatible with template 'a'

And regardless if you use an alias or template argument, you'd still have to define template 'al'.


> Yes.
> 
> template temp(alias T1: T!(int) )
> {
> }
> 
> And you can have default alias template arguments, too.
> 

I tried the following code:
template temp(alias T){
}

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

And got the error:
template main.temp(alias T : T!(int)) conflicts with main.temp(alias T) at main.d(4)



More information about the Digitalmars-d mailing list