View source code Display the source code in std/traits.d from which this page was generated on github. 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. Page wiki View or edit the community-maintained wiki page associated with this page.

std.traits.set_function_attributes - multiple declarations

Template 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.

Arguments

template SetFunctionAttributes(T, string linkage, uint attrs);

Parameters

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

Example

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

Alias 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.

Declaration

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

Parameters

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

Example

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

Authors

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

License

Boost License 1.0.

Comments