How to distinguish a delegate from a function?
Moritz Warning
moritzwarning at web.de
Sat Jul 12 19:34:35 PDT 2008
On Sun, 13 Jul 2008 03:38:36 +0200, Oliver Dathe wrote:
> This works here:
>
> template isCallableStatically(T)
> {
> static if (is(T==function) || is(typeof(*T)==function))
> const bool isCallableStatically = true;
> else static if (is(T==delegate))
> const bool isCallableStatically = false;
> else static assert (false);
> }
>
> template isCallableStatically(alias T) {
> const isCallableStatically = isCallableStatically!(typeof(&T));
> }
>
> void fn() {}
>
> void main()
> {
> void dg() {}
>
> static assert (isCallableStatically!(fn)); static assert
> (!isCallableStatically!(dg)); static assert
> (isCallableStatically!(typeof(&fn))); static assert
> (!isCallableStatically!(typeof(&dg)));
> }
Doesn't work for A.bar and A.foo (where foo is static and therefore don't
need an object)
More information about the Digitalmars-d
mailing list