inline @trusted code

kinke kinke at libero.it
Tue Jan 30 15:23:24 UTC 2018


On Tuesday, 30 January 2018 at 15:05:38 UTC, ikod wrote:
> Hello,
>
> Several times I faced with next problem: I have "@safe" routine 
> with few calls to @system functions inside: OS calls (recv, 
> send, kqueue) os some phobos unsafe functions like 
> assumeUnique. I'd like not to wrap these @system functions in 
> @trusted wrappers, but somehow mark these calls @trusted inline.
>
> In ideal case this should look like
>
> import std.exception;
>
> void main() @safe
> {
>     ubyte[] a;
>     @trusted {
>     	auto b = assumeUnique(a);
>     };
> }
>
> But the closest variant is
>
> import std.exception;
>
> void main() @safe
> {
>     ubyte[] a;
>     delegate void() @trusted {
>     	auto b = assumeUnique(a);
>     }();
> }
>
> Which looks a bit verbose.
>
> How do you solve this problem?
>
> Thanks!

ubyte[] a;
auto b = (() @trusted => assumeUnique(a))();


More information about the Digitalmars-d-learn mailing list