www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Variadic template alias parameters

reply "Dylan Knutson" <tcdknutson gmail.com> writes:
Hello!
As far as I can tell, you can't have a variadic of alias 
parameters on a template, which is strange to me. Eg, you can't 
do something like:

template Foo(alias Args...) {
  ...
}

int i = 0;
Foo!(std.conv, "123", i);

Is there a reason for this restriction?
Jun 04 2013
next sibling parent reply "Simen Kjaeraas" <simen.kjaras gmail.com> writes:
On 2013-06-05, 00:33, Dylan Knutson wrote:

 Hello!
 As far as I can tell, you can't have a variadic of alias parameters on a  
 template, which is strange to me. Eg, you can't do something like:

 template Foo(alias Args...) {
   ...
 }

 int i = 0;
 Foo!(std.conv, "123", i);

 Is there a reason for this restriction?
Try without the alias - variadic template parameters may be aliases or types or any mix thereof. Also, please ask such questions in digitalmars.D.learn in the future. -- Simen
Jun 04 2013
parent reply "Dylan Knutson" <tcdknutson gmail.com> writes:
 Also, please ask such questions in digitalmars.D.learn in the 
 future.
Sorry; I was trying to decide if if belonged there or here, so I decided on here because it was a question about D's grammar.
 It wouldn't add any functionality.
Oh; I didn't know that variadic template params were aliased. Thanks for the clarification :-)
Jun 04 2013
parent Timon Gehr <timon.gehr gmx.ch> writes:
On 06/05/2013 01:13 AM, Dylan Knutson wrote:
 Also, please ask such questions in digitalmars.D.learn in the future.
Sorry; I was trying to decide if if belonged there or here, so I decided on here because it was a question about D's grammar.
 It wouldn't add any functionality.
Oh; I didn't know that variadic template params were aliased. Thanks for the clarification :-)
Oh, it is more subtle than that. DMD won't accept built-in types as arguments to alias template parameters, but they still can be passed as arguments to variadic template params.
Jun 04 2013
prev sibling parent Timon Gehr <timon.gehr gmx.ch> writes:
On 06/05/2013 12:33 AM, Dylan Knutson wrote:
 Hello!
 As far as I can tell, you can't have a variadic of alias parameters on a
 template, which is strange to me. Eg, you can't do something like:

 template Foo(alias Args...) {
   ...
 }

 int i = 0;
 Foo!(std.conv, "123", i);

 Is there a reason for this restriction?
It wouldn't add any functionality. template Foo(Args...) { ... } int i = 0; Foo!(std.conv, "123", i);
Jun 04 2013