@trusted and return ref
via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Feb 24 22:48:16 PST 2015
On Tuesday, 24 February 2015 at 22:49:17 UTC, w0rp wrote:
> In general, @trusted means "I have proven myself that this code
> is actually safe, eeven though it uses unsafe features." The
> compiler has to be pessimistic and assume that everything which
> can be used unsafely will be used unsafely. @trusted, as it is
> used here, is used to say, "I assure you I have used this in a
> safe manner."
From http://dlang.org/function.html#trusted-functions :
«Trusted functions are guaranteed by the programmer to not
exhibit any undefined behavior if called by a safe function.»
I take this to mean that anything that is wrapped up in @trusted
should not violate memory safety when in injected into any
arbitrary context marked as @safe.
> I would like to see @trusted blocks, although I can see
> Andrei's argument of not making it easy to do intentionally.
If @trusted is meant to be used the way he is doing it in this
example then there is no reason to not provide @trusted-blocks.
An inlined lambda is a block...
But it provides poor encapsulation and makes for weak typing.
More information about the Digitalmars-d-learn
mailing list