function is not function

bearophile bearophileHUGS at lycos.com
Fri Sep 21 13:17:26 PDT 2012


Ellery Newcomer:

> import std.stdio;
>
> void main() {
>     auto a = {
>         writeln("hi");
>     };
>     pragma(msg, typeof(a)); // void function()
>     pragma(msg, is(typeof(a) == delegate)); // nope!
>     pragma(msg, is(typeof(a) == function)); // nope!
> }

There is a subtle difference between function type, type of
function pointer and delegate type.


int foo1() { return 0; }
void main() {
      static assert(is(typeof(foo1) == function));
      auto foo2 = { return 0; };
      static assert(is(typeof(*foo2) == function));
}

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list