Determining if a symbol is a function
    Lars Kyllingstad 
    public at kyllingen.NOSPAMnet
       
    Mon Apr 13 02:46:25 PDT 2009
    
    
  
Doctor J wrote:
> Answered my own question:
> 
>     static if (is(typeof(func0) == function))
>         writefln("func0 is a function.");
> 
> is() really wants a type, not an expression.
You say you want to test whether a struct/class member is a field or a 
property. Pointers to class and struct methods are delegates, not 
function pointers.
     http://www.digitalmars.com/d/1.0/type.html#delegates
So the correct thing to write would be:
     static if (is(typeof(func0) == delegate)) { ... }
or, to test whether func0 is a function OR a delegate,
     static if (is(typeof(func0) == return)) { ... }
For details, see
     http://www.digitalmars.com/d/1.0/expression.html#IsExpression
-Lars
    
    
More information about the Digitalmars-d-learn
mailing list