On Tuesday, 18 December 2018 at 10:14:50 UTC, Per Nordlöw wrote:
What's the preferred way of creating a temporary @trusted scope without writing a separate function?

Jonathan's idea might also be encapsulated in a function, just like assumeUnique in Phobos:

import std.stdio;

template unsafe(alias fn) {
    @trusted auto unsafe(T...)(T args) {
        return fn(args);
    }
}

@system void fun(int n) {
    writeln("foo!");
}

@safe unittest {
    unsafe!({
        fun(2);
    });

    unsafe!fun(2);
}

--
  Simen

Reply via email to