On Tuesday, 17 April 2012 at 12:04:44 UTC, Erèbe wrote:
[snip]

There is something I still don't understand :

mixin template Foo( T... )
{
//Code here
}

mixin Foo!( "Hello", "Word" ); <---- Good

T is TemplateTypeParameter, and matches any kind of template arguments - types, values, and symbols. The both arguments "Hello" and "World" are values, so you can bind them with T.

http://dlang.org/template.html#TemplateTupleParameter

--------------------------------------------

"mixin template Foo( A, T... )
{
//code here
}

mixin Foo!( "Hello", "Word" ); <--- Fail !
mixin Foo!( string, "Word" ); <---- Good
--------------------------------------------

'A' is TemplateTypeParameter, and it matches only types. In the first instantiation of Foo, A doesn't match with the value "hello". In the second instantiation, string is type, and T matches with it.

http://dlang.org/template.html#TemplateTypeParameter

mixin template Foo( alias A, T... )
{
//code here
}

mixin Foo!( "Hello", "world" ); <--- Good
mixin Foo!( string, "world" ); <--- Fail !

---------------------------------------------

'alias A' is TemplateAliasParameter, and it matches both symbols and values. Then A matches with the value "Hello", but doesn't with the type string. (string is an aliased name of immutable(char)[], and it is built-in array type.)

http://dlang.org/template.html#TemplateAliasParameter

Kenji Hara

Reply via email to