Feature request: Templates as template parameters

Simen Kjaeraas simen.kjaras at gmail.com
Mon Mar 24 12:49:03 PDT 2008


On Mon, 24 Mar 2008 01:07:43 +0100, Jarrett Billingsley  
<kb3ctd2 at yahoo.com> wrote:

> "Simen Kjaeraas" <simen.kjaras at gmail.com> wrote in message
> news:op.t8hkl3ln1hx7vj at spill04.lan...
> struct foo(T = void)
> {
>      static if (!is(T == void))
>      {
>          mixin T;
>      }
> }
>
> I have a struct basically looking like this, and instantiated with T  
> being
> a
> template to be mixin'd in the struct (other methods are added via CTFE'd
> string
> mixins and a few are inline).
>
> As you an see, the line 'static if (!is(T == void))' is hardly safe, and
> should
> be exchanged for 'static if (is(T == template))' or the parameter list  
> with
> something like 'foo(T : template)'. Could we get something like this?
>
> --Simen
>
> Templates are not types, and you cannot instantiate a template using a
> template as a type parameter.  In order to pass a template to another
> template, you use an alias parameter:
>
> struct foo(alias T)
> {
>     mixin T;
> }
>
> template bar()
> {
>     int x;
> }
>
> alias foo!(bar) baz;

You are right, of course. New question, then: How do I check if a template  
alias parameter is a template?
T.stringof does give me some information, perhaps it is enough to check  
that it is on the form .*\(.*\).

-- Simen


More information about the Digitalmars-d-learn mailing list