Function functionsOf

Return an array of Function objects, refracting the functions in Scope for which IncludePredicate evaluates to true, using the value of localName to represent Scope. IncludePredicate is optional; if not specified, refract all the functions. The overloadIndex property of each Function is set to the index of the function in its *entire* overload set (i.e. including the overloads that may have been excluded by IncludePredicate).

auto functionsOf(alias Scope, string localName, alias IncludePredicate)()
if (is(Scope == module) || is(Scope == struct) || is(Scope == class) || is(Scope == interface) || is(Scope == union));

Applying this function to a module, without specifying IncludePredicate, may severely affect compilation time, as *all* the properties of *all* functions in the module will be queried.

Parameters

NameDescription
Scope an aggregate or a module
localName a string mixin that represents Scope
IncludePredicate a template that takes an alias to a function and evaluates to a compile time boolean

Example

static union Answers {
    int answer();
    void answer();
    string answer();
}

alias Container = Answers;

enum NotVoid(alias F) = !is(ReturnType!(F) == void);

enum functions = functionsOf!(Container, "Container", NotVoid);

static assert(functions.length == 2);

static assert(
    functions[0].mixture ==
    q{@system %s.ReturnType!(__traits(getOverloads, Container, "answer")[0]) answer();}
    .format(__MODULE__));
static assert(functions[0].overloadIndex == 0);

static assert(
    functions[1].mixture ==
    q{@system %s.ReturnType!(__traits(getOverloads, Container, "answer")[2]) answer();}
    .format(__MODULE__));
static assert(functions[1].overloadIndex == 2);