FunctionTypeOf

Get the function type from a callable object func, or from a function pointer/delegate type.

Using builtin typeof on a property function yields the types of the property value, not of the property function itself. Still, FunctionTypeOf is able to obtain function types of properties.

Note: Do not confuse function types with function pointer types; function types are usually used for compile-time reflection purposes.

template FunctionTypeOf (
alias func
) if (
isCallable!func
) {}

Examples

class C
{
    int value() @property => 0;
    static string opCall() => "hi";
}
static assert(is( typeof(C.value) == int ));
static assert(is( FunctionTypeOf!(C.value) == function ));
static assert(is( FunctionTypeOf!C == typeof(C.opCall) ));

int function() fp;
alias IntFn = int();
static assert(is( typeof(fp) == IntFn* ));
static assert(is( FunctionTypeOf!fp == IntFn ));

Meta