[Bug 31] Keyword 'function' and pointer test broken for IsExpression

Sean Kelly sean at f4.ca
Thu May 4 16:31:47 PDT 2006


d-bugmail at puremagic.com wrote:
>>
>> alias void function() fp;
>> static if( is( fp == function ) ) printf( "6. function passes\n" );
> 
> fp is not declared as a function, it is declared as a pointer to a function. If
> fp is declared as:
>     alias void fp();
> it will 'pass'.

So how do I test if T is a function pointer?  Currently, I can test if T 
is a delegate via "if( is(T==delegate) )" but "if( is(T==function) )" 
clearly has a different meaning.  For example:

     void delegate() dp;

     template isDelegate( T )
     {
         const bool isDelegate = is( T == delegate );
     }

     static assert( isDelegate!(dp) );

So far so good, but:

     void function() fp;

     template isFunctionPointer( T )
     {
         const bool isFunctionPointer = ???;
     }

     static assert( isFunctionPointer!(fp) );

Currently, I'm examining the mangled name, which is a terrible hack:

     template isFunctionPointer( T )
     {
         const bool isFunctionPointer= T.mangleof.length > 2 &&
                                       T.mangleof[0] == 'P'  &&
                                       T.mangleof[1] == 'F';
     }



Sean



More information about the Digitalmars-d-bugs mailing list