How to assert a function signature in D2.008?

Steven Schveighoffer schveiguy at yahoo.com
Wed Dec 5 10:06:19 PST 2007


"Craig Black" wrote
>
> "Sean Kelly" <sean at f4.ca> wrote in message 
> news:fj4e63$1jaa$1 at digitalmars.com...
>> Walter Bright wrote:
>>> Janice Caron wrote:
>>>> This used to compile under D2.007
>>>>
>>>>     struct A
>>>>     {
>>>>         void f() {}
>>>>
>>>>         static assert(is(typeof(f)==void function()));
>>>>     }
>>>>
>>>> It doesn't under D2.008. The only way I've found to make it compile
>>>> under D2.008 is to change it to
>>>
>>> Change it to:
>>>
>>> is(typeof(&f)==void function())
>>
>> I guess the reason that this matches "void function" rather than "void 
>> delegate" is to avoid the need for handling each separately?
>>
>>
>> Sean
>
> To me this is confusing because you are taking the address of an instance 
> function without specifying the context pointer.  It doesn't result in a 
> delegate but it shouldn't result in a function either.  Maybe there should 
> be another type for "delegate without context pointer".
>
> -Craig

It is consistent with other uses of typeof.  typeof is a special compiler 
directive that says "give me the type of what this instruction would be". 
It doesn't actually execute the instruction.

And I believe the 'is' operation must be executed by the compiler at compile 
time anyways.

-Steve 





More information about the Digitalmars-d mailing list