Why hide a trusted function as safe?
anonymous via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Jul 26 04:52:22 PDT 2015
On Sunday, 26 July 2015 at 11:38:31 UTC, simendsjo wrote:
> Is there a reason why you would hide the fact that a function
> is trusted rather than safe? Technically it doesn't matter,
> right? To me, it seems like this would give wrong assumptions
> to the caller.
>
> The reason I ask is because I found the following in
> std.concurrency:
>
> @property Tid thisTid() @safe
> {
> // TODO: remove when concurrency is safe
> auto trus = delegate() @trusted
> {
> if( thisInfo.ident != Tid.init )
> return thisInfo.ident;
> thisInfo.ident = Tid( new MessageBox );
> return thisInfo.ident;
> };
>
> return trus();
> }
As far as I know, it doesn't matter. Both @safe and @trusted
functions must be memory safe. So I don't see a point in doing
that delegate dance.
But it doesn't make a difference to the caller either. They can't
assume any more or less about an @safe function than about an
@trusted one.
More information about the Digitalmars-d-learn
mailing list