isFunction

Detect whether symbol or type X is a function. This is different from finding if a symbol is callable or satisfying is(X == return). It finds specifically if the symbol represents a normal function (or method) declaration, i.e. not a delegate or a function pointer.

template isFunction () {
static if(is(typeof(&X) U : U*) && is(U == function) || is(typeof(&X) U == delegate))
enum isFunction;
static if(!(is(typeof(&X) U : U*) && is(U == function) || is(typeof(&X) U == delegate)))
static if(is(X))
enum isFunction;
static if(!(is(typeof(&X) U : U*) && is(U == function) || is(typeof(&X) U == delegate)))
static if(!(is(X)))
enum isFunction;
}

Return Value

true if X is a function, false otherwise

Examples

static void func(){}
static assert(isFunction!func);
static assert(isFunction!(typeof(func)));

auto fp = &func; // function pointer
static assert(!isFunction!fp);

int i;
int f2() => i; // nested function
static assert(isFunction!f2);

struct S
{
    void func(){}
}
static assert(isFunction!(S.func));

See Also

Use isFunctionPointer or isDelegate for detecting those types respectively.

Meta