[Bug 31] Keyword 'function' and pointer test broken for IsExpression
Oskar Linde
oskar.lindeREM at OVEgmail.com
Fri May 5 09:33:54 PDT 2006
Sean Kelly wrote:
> 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) );
I assume you mean isDelegate!(typeof(dp)).
>
> So far so good, but:
>
> void function() fp;
>
> template isFunctionPointer( T )
> {
> const bool isFunctionPointer = ???;
> }
>
> static assert( isFunctionPointer!(fp) );
Try:
template declare(T) { T declare; }
template isFunctionPointer(T) {
const bool isFunctionPointer = is( typeof(*declare!(T)) == function);
}
/Oskar
More information about the Digitalmars-d-bugs
mailing list