Does is(f == function) work?

Boris Carvajal boris2.9 at gmail.com
Tue Mar 9 18:53:06 UTC 2021


On Tuesday, 9 March 2021 at 11:58:45 UTC, Andrey Zherikov wrote:
> On Tuesday, 9 March 2021 at 02:57:46 UTC, Adam D. Ruppe wrote:
>> try
>>
>> is(typeof(f) == function)
>>
>> it is kinda weird but that's the trick
>
> Thanks!
> Should it work for in this case as well?
>
> alias f = (){};
>
> writeln(typeof(f).stringof);        // prints "void function() 
> pure nothrow @nogc @safe"
>
> writeln(is(typeof(f) == function)); // prints "false"

Not quite straightforward, but "void function()" is actually a 
pointer to function, you need to dereference it first:

is(typeof(*f) == function)


More information about the Digitalmars-d-learn mailing list