The OpenD Programming Language

SetFunctionAttributes

Constructs a new function or delegate type with the same basic signature as the given one, but different attributes (including linkage).

This is especially useful for adding/removing attributes to/from types in generic code, where the actual type name cannot be spelt out.

  1. template SetFunctionAttributes(T, string linkage, uint attrs)
  2. template SetFunctionAttributes(T, string linkage, uint attrs)
    template SetFunctionAttributes (
    T
    string linkage
    uint attrs
    ) if (
    is(T == function)
    ) {}

Parameters

T

The base type.

linkage

The desired linkage of the result type.

attrs

The desired FunctionAttributes of the result type.

Examples

alias ExternC(T) = SetFunctionAttributes!(T, "C", functionAttributes!T);

auto assumePure(T)(T t)
if (isFunctionPointer!T || isDelegate!T)
{
    enum attrs = functionAttributes!T | FunctionAttribute.pure_;
    return cast(SetFunctionAttributes!(T, functionLinkage!T, attrs)) t;
}

int f()
{
    import core.thread : getpid;
    return getpid();
}

int g() pure @trusted
{
    auto pureF = assumePure(&f);
    return pureF();
}
assert(g() > 0);

Meta