Feature request: Templates as template parameters

Jarrett Billingsley kb3ctd2 at yahoo.com
Sun Mar 23 17:07:43 PDT 2008


"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; 




More information about the Digitalmars-d-learn mailing list