[Bug 31] Keyword 'function' and pointer test broken for IsExpression
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Apr 26 11:43:19 PDT 2006
http://d.puremagic.com/bugzilla/show_bug.cgi?id=31
bugzilla at digitalmars.com changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |INVALID
------- Comment #4 from bugzilla at digitalmars.com 2006-04-26 13:43 -------
>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'.
>template isPointer( T )
>{
> const bool isPointer = is( T : T* );
>}
>static if( isPointer!(int*) ) printf( "8. pointer passes\n" );
Here, int* is passed as T to isPointer. The is(T:T*) is evaluated as
is(int*:int**), and so it fails. To detect a pointer, use is(T:void*).
>class C { void fn() {} }
> static if( is( typeof(C.fn) == function ) )
> pragma( msg, "is function\n" );
> static if( is( typeof(C.fn) == delegate ) )
> pragma( msg, "is delegate\n" );
>prints "is function" if compiled. Aren't non-static class functions
>actually delegates?
No. Class functions are functions. A delegate is a pointer to a class function.
--
More information about the Digitalmars-d-bugs
mailing list