Get class type parameters at compile time
    bearophile 
    bearophileHUGS at lycos.com
       
    Thu Dec 13 16:18:10 PST 2012
    
    
  
Philippe Sigaud:
> template TemplateArity(Type)
> {
>     enum T = Type.stringof;
>     mixin("alias " ~ T ~ " U;");
>     static if (is(Type _ == U!Args, Args...))
>         enum TemplateArity = Args.length;
>     else
>         enum TemplateArity = -1;
> }
>
> void main()
> {
>     alias Test!(int, double, string) T;
...
>     assert(TemplateArity!T == 3); // External deduction
> }
Fit to be added to Phobos?
Bye,
bearophile
    
    
More information about the Digitalmars-d-learn
mailing list