@trusted AKA most useless statement ever

Kagamin via Digitalmars-d digitalmars-d at puremagic.com
Fri Nov 25 14:56:17 PST 2016


On Friday, 25 November 2016 at 10:14:46 UTC, Satoshi wrote:
> but writing 20 times something like:
> auto vi = (() @trusted => glXChooseXFBConfig(...))();
>
> or:
> auto vi = () @trusted { return glXChooseXFBConfig(...); }();

Trusted blocks are used for safety inference in generic code, so 
that only code outside trusted blocks affects inferred safety of 
the generic function. Normally you should be fine by marking the 
trusted function with one @trusted attribute and be done with it, 
that's what it was designed for.

> is annoying and just forced me to mark whole class with 
> @trusted...

And it also made code cleaner than with unsafe blocks sprinkled 
everywhere.


More information about the Digitalmars-d mailing list