On Wednesday, 27 February 2019 at 20:03:15 UTC, Q. Schroll wrote:
For any type constructors like const, I can use ConstOf!T to
get `T` with const attached. For a delegate/function type DG,
e.g. int delegate(int), how can I get the @safe version of that
type, i.e. int delegate(int) @safe?
I tried
alias SafeOf(DG) = DG @safe;
but it didn't compile.
The case is not @safe-specific; it's the same for all function
attributes.
At https://p0nce.github.io/d-idioms/
there is a demonstration for @nogc:
´´´
import std.traits;
// Casts @nogc out of a function or delegate type.
auto assumeNoGC(T) (T t) if (isFunctionPointer!T || isDelegate!T)
{
enum attrs = functionAttributes!T | FunctionAttribute.nogc;
return cast(SetFunctionAttributes!(T, functionLinkage!T,
attrs)) t;
}
´´´
Didn't try this for other cases, however...