Is @trusted the wrong direction?
Alexandru Ermicioi
alexandru.ermicioi at gmail.com
Sat Nov 9 20:38:47 UTC 2019
On Saturday, 9 November 2019 at 16:22:05 UTC, Dominikus Dittes
Scherkl wrote:
> I always thought trusted functions shouldn't be a thing. Almost
> never a whole function need to be trusted, but only a few lines
> of code. What we need instead are trusted blocks. Those can be
> simulated with anonymous nested functions, but the syntax is
> ugly as hell while complete trusted functions should be
> forbidden.
Had an idea how to make more nice trusted blocks:
```d
import std.stdio;
T trusted (T)(T delegate() @system dg) @trusted {
return dg();
}
void main() @safe
{
writeln("Hello D");
({
writeln("C ", cast(void*) 1);
}).trusted;
}
```
looks a lot better than anonymous functions that are called right
away after being defined.
Best regards,
Alexandru.
More information about the Digitalmars-d
mailing list