isSomeFunction

Detect whether symbol or type T is a function, a function pointer or a delegate.

template isSomeFunction (
T...
) if (
T.length == 1
) {
enum bool isSomeFunction;
enum bool isSomeFunction;
enum bool isSomeFunction;
enum bool isSomeFunction;
}

Parameters

T

The type to check

Return Value

A bool

Examples

1 static real func(ref int) { return 0; }
2 static void prop() @property { }
3 class C
4 {
5     real method(ref int) { return 0; }
6     real prop() @property { return 0; }
7 }
8 auto c = new C;
9 auto fp = &func;
10 auto dg = &c.method;
11 real val;
12 
13 static assert( isSomeFunction!func);
14 static assert( isSomeFunction!prop);
15 static assert( isSomeFunction!(C.method));
16 static assert( isSomeFunction!(C.prop));
17 static assert( isSomeFunction!(c.prop));
18 static assert( isSomeFunction!(c.prop));
19 static assert( isSomeFunction!fp);
20 static assert( isSomeFunction!dg);
21 
22 static assert(!isSomeFunction!int);
23 static assert(!isSomeFunction!val);

Meta

Suggestion Box / Bug Report