The base type.
The desired linkage of the result type.
The desired FunctionAttributes of the result type.
1 alias ExternC(T) = SetFunctionAttributes!(T, "C", functionAttributes!T); 2 3 auto assumePure(T)(T t) 4 if (isFunctionPointer!T || isDelegate!T) 5 { 6 enum attrs = functionAttributes!T | FunctionAttribute.pure_; 7 return cast(SetFunctionAttributes!(T, functionLinkage!T, attrs)) t; 8 } 9 10 int f() 11 { 12 import core.thread : getpid; 13 return getpid(); 14 } 15 16 int g() pure @trusted 17 { 18 auto pureF = assumePure(&f); 19 return pureF(); 20 } 21 assert(g() > 0);
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.