Determining if a class has a template function
    Marc Schütz via Digitalmars-d-learn 
    digitalmars-d-learn at puremagic.com
       
    Fri Oct 14 02:15:40 PDT 2016
    
    
  
On Wednesday, 12 October 2016 at 16:57:50 UTC, Meta wrote:
> There's also a *very* ugly hack you can do:
>
> //A template function's .stringof is of the format <function 
> name>(<template args>)(<function args>)
> //so match on the number of brackets to determine whether it's 
> a template function or not
> enum isTemplateFunction = __traits(isTemplate, f)
>                               && fstr.balancedParens('(', ')')
>                               && (fstr.canFind("if")
>                                   || fstr.count!(c =>
>                                          
> cast(bool)c.among!('(', ')')) == 4);
This won't work if there are additional parens _inside_ 
compile/runtime parameters, though, which there is ample 
opportunity for:
T func(T : U!(int, string), U)(const(T) param = 
defaultValue!(const(T))());
    
    
More information about the Digitalmars-d-learn
mailing list