Temporary @trusted scope

Simen Kjærås simen.kjaras at gmail.com
Tue Dec 18 11:29:42 UTC 2018


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


More information about the Digitalmars-d-learn mailing list