@trusted considered harmful

David Nadlinger see at klickverbot.at
Sat Jul 28 13:08:42 PDT 2012


On Saturday, 28 July 2012 at 02:33:54 UTC, Jonathan M Davis wrote:
> @property auto save()
> {
>     import std.conv;
>     alias typeof((*_range).save) S;
>     static assert(isForwardRange!S, S.stringof ~ " is not a 
> forward range.");
>
>     @trusted
>     {
>         auto mem = new void[S.sizeof];`
>         emplace!S(mem, cast(S)(*_range).save);`
>         return RefRange!S(cast(S*)mem.ptr);
>     }
> }
>
> That is _way_ cleaner.

But unfortunately wrong – you call S.save in the @trusted 
block… ;)

David



More information about the Digitalmars-d mailing list