Function

Meta-class Function

  1. template Function(Props...)
  2. alias Function(alias Fun, string Source = __traits(identifier, Fun), int Index = 0) = Function!(Fun, functionAttributes!Fun | (__traits(isStaticFunction, Fun) ? ExtendedFunctionAttribute.static_ : 0), Type!(ReturnType!Fun, "std.traits.ReturnType!(%s)".format(Source)), __traits(identifier, Fun), Index, reflectParameterList!(Fun, Source), UDAList!(makeUDAs!(Source, 0, __traits(getAttributes, Fun))))
  3. alias Function(alias Fun, string Aggregate, string Member, int Index) = Function!(Fun, `__traits(getOverloads, %s, "%s")[%d]`.format(Aggregate, Member, Index), Index)

Members

Aliases

FA
alias FA = FunctionAttribute
Undocumented in source.
Properties
alias Properties = withDefaults!(AliasPack!(Props), PropertyDefaults)
Undocumented in source.
XA
alias XA = ExtendedFunctionAttribute
Undocumented in source.
appendParameter
alias appendParameter(NewParameter...) = insertParameter!(arity, NewParameter)
Undocumented in source.
insertParameter
alias insertParameter(int Position, NewParameter...) = setParameters!(parameters[0..Position], NewParameter, parameters[Position..$])
Undocumented in source.
parameters
alias parameters = parameterList.Unpack
Undocumented in source.
setBody
alias setBody(string newBody) = setBody_!(["{", newBody, "}"])

setBody

setParameters
alias setParameters(NewParameters...) = Function!(aliasSeqReplace!(Property.parameterList, ParameterList!(NewParameters), Properties))
Undocumented in source.
udas
alias udas = udaList.Unpack
Undocumented in source.

Enums

argumentMixtureAt
eponymoustemplate argumentMixtureAt(int i)
Undocumented in source.
hasUDA
eponymoustemplate hasUDA(UDA...)
Undocumented in source.
isSameUDA
eponymoustemplate isSameUDA(alias UDA, alias Meta)
Undocumented in source.

Manifest constants

argumentMixture
enum argumentMixture;
Undocumented in source.
argumentMixtureArray
enum argumentMixtureArray;
Undocumented in source.
arity
enum arity;
Undocumented in source.
attributeMixture
enum attributeMixture;
Undocumented in source.
attributeMixtureArray
enum attributeMixtureArray;
Undocumented in source.
declarationMixture
enum declarationMixture;
Undocumented in source.
declarationMixtureArray
enum declarationMixtureArray;
Undocumented in source.
mixture
enum mixture;
Undocumented in source.
mixtureArray
enum mixtureArray;
Undocumented in source.
mutabilityAttribute
enum mutabilityAttribute;
Undocumented in source.
mutabilityAttributeArray
enum mutabilityAttributeArray;
Undocumented in source.
parameterMixture
enum parameterMixture;
Undocumented in source.
parameterMixtureArray
enum parameterMixtureArray;
Undocumented in source.
pointerMixture
enum pointerMixture;
Undocumented in source.
udaMixture
enum udaMixture;
Undocumented in source.
udaMixtureArray
enum udaMixtureArray;
Undocumented in source.

Examples

Examining a function

struct small;
pure int add(@small int a, @small int b) { return a + b; }
static assert(Function!add.isPure);
static assert(Function!add.isNothrow);
static assert(Function!add.isNogc);
static assert(Function!add.parameters.length == 2);
static assert(is(Function!add.parameters[0].type.origin == int));
static assert(Function!add.parameters[0].UDAs.length == 1);
static assert(is(Function!add.parameters[0].UDAs[0].origin == small));

Generating a function

pure int f() { return 42; }

template plus1(alias F)
{
  alias NewFunction = Function!(f, "F").setName!"plus1".setBody!("return F() + 1;");
  static assert(
    NewFunction.mixture ==
    "pure nothrow @safe @nogc std.traits.ReturnType!(F) plus1() { return F() + 1; }");
  mixin(NewFunction.mixture);
}
Assert.equal(plus1!f, 43);

Meta