C#7 features
Nick Treleaven via Digitalmars-d-announce
digitalmars-d-announce at puremagic.com
Sat May 7 09:36:44 PDT 2016
On Friday, 6 May 2016 at 23:51:59 UTC, Steven Schveighoffer wrote:
>
> Of COURSE D supports local ref variables:
>
> struct RefVar(T)
> {
> private T * var;
> this(ref T v) { var = &v; }
> auto get() { return *var; }
> alias this get;
> }
ref get() return {...
Which is unsafe even if the ctor is marked trusted, the struct
could be moved to a higher scope. But like in another thread, you
can have a ref property in @safe code:
T v;
@property ref myRef(){return v;}
So why are ref locals disallowed? Now we have the return
attribute on functions that take myRef by ref, can it still
escape?
ref myRef = v;
More information about the Digitalmars-d-announce
mailing list