Temporary @trusted scope
rikki cattermole
rikki at cattermole.co.nz
Tue Dec 18 12:42:12 UTC 2018
On 19/12/2018 1:34 AM, Per Nordlöw wrote:
> On Tuesday, 18 December 2018 at 10:42:51 UTC, Jonathan M Davis wrote:
>> Unfortunately, D does not currently have a way to do that. Only
>> functions can be marked with @trusted. However, the typical approach
>> to this problem is to use a lambda, which is more or less
>> syntactically the same except that it has some extra parens. e.g.
>>
>> () @trusted { doUnsafe(); }();
>
> Is there a performance hit when using this?
Yes except for ldc with -O3.
But it is a function not a delegate so it should be all nicely
prefetched and ready to go. So I wouldn't worry about it too much.
More information about the Digitalmars-d-learn
mailing list