@trusted AKA most useless statement ever

Satoshi via Digitalmars-d digitalmars-d at puremagic.com
Fri Nov 25 02:14:46 PST 2016


Simply, it should be replaced by:

void safeFunc() @safe {
     unsafe {
         auto vi = doUnsafeCall();
     }
}

@trusted functions are prohibited by d-idiom (so I don't know why 
are still in D).
So, when I need to create a simple window with OpenGL context I 
need to write about 10-15 calls to system functions. But 
D-idiom[1] for @trusted tells me to make @trusted functions as 
small as possible. OK, it makes sense.

but writing 20 times something like:
auto vi = (() @trusted => glXChooseXFBConfig(...))();

or:
auto vi = () @trusted { return glXChooseXFBConfig(...); }();

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



[1] 
https://dlang.org/blog/2016/09/28/how-to-write-trusted-code-in-d/


More information about the Digitalmars-d mailing list