reflection over templates

Adam D. Ruppe destructionator at gmail.com
Wed Mar 19 09:00:02 PDT 2014


Given:

template Foo(string T) { enum Foo = to!int(T); }

(or anything else, really)

Is there anything we can do with static if to identify it as a 
template?

I tried:

static if(is(Foo == template)) {} // nope, basic type expected, 
not template

Note that is(typeof(Foo) == function) {} is how we check for 
regular functions.


static if(is(typeof(Foo) == template)) {} // nope


In fact, typeof(Foo) == void... is that something we can use?


I know we can break down a template instantiation with one of the 
arcane is expressions, but I don't have that here, I just want to 
identify the template Foo as a template.

This is in the context of doing __traits(allMembers) over a 
module and trying to categorize every member.


Checking for a void type seems to be the closest I've gotten, but 
that seems awfully strange. I guess other variables can't be 
declared with type void, so maybe that is a unique 
differentiator, but still, idk about it.


And after we determine it is a template, can we extract the 
required arguments list like we can with a regular function at 
all?


More information about the Digitalmars-d-learn mailing list