Determining if a class has a template function
    Meta via Digitalmars-d-learn 
    digitalmars-d-learn at puremagic.com
       
    Wed Oct 12 09:59:57 PDT 2016
    
    
  
On Wednesday, 12 October 2016 at 16:57:50 UTC, Meta wrote:
> //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);
Whoops, I forget to say that fstr is defined like this:
enum fstr = f.stringof;
    
    
More information about the Digitalmars-d-learn
mailing list