View source code
Display the source code in std/traits.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone.

Template std.traits.SetFunctionAttributes

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

template SetFunctionAttributes(T, string linkage, uint attrs) ;
alias SetFunctionAttributes(T, string linkage, uint attrs) = FunctionTypeOf!(SetFunctionAttributes!(T*,linkage,attrs));

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

Template SetFunctionAttributes

Alias SetFunctionAttributes


T The base type.
linkage The desired linkage of the result type.
attrs The desired FunctionAttributes of the result type.


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);


Walter Bright, Tomasz Stachowiak (isExpressions), Andrei Alexandrescu, Shin Fujishiro, Robert Clipsham, David Nadlinger, Kenji Hara, Shoichi Kato


Boost License 1.0.