June 28, 2018 -dip1000 @safe scope wrapper | ||||
---|---|---|---|---|
| ||||
Hello, Is it possible to create scope wrapper initialized by non default constructor with scope parameter? something like this: struct Wrapper{ int* p; static Wrapper create(scope return int* p)@safe{ Wrapper w; w.p = p; return w; } /++ This doesn't work: this(scope return int* p)@safe scope{ this.p = p; }+/ } void main()@safe{ scope int i; scope Wrapper w1 = Wrapper.create(&i); scope Wrapper w2 = Wrapper(&i); } |
June 28, 2018 Re: -dip1000 @safe scope wrapper | ||||
---|---|---|---|---|
| ||||
Posted in reply to vit | On Thursday, 28 June 2018 at 13:29:58 UTC, vit wrote:
> Hello,
> Is it possible to create scope wrapper initialized by non default constructor with scope parameter?
> something like this:
>
> struct Wrapper{
> int* p;
>
> static Wrapper create(scope return int* p)@safe{
> Wrapper w;
> w.p = p;
> return w;
> }
>
> /++ This doesn't work:
> this(scope return int* p)@safe scope{
> this.p = p;
> }+/
> }
>
> void main()@safe{
> scope int i;
> scope Wrapper w1 = Wrapper.create(&i);
> scope Wrapper w2 = Wrapper(&i);
> }
I'm not sure why create works in this case either. I get the following when I uncomment the constructor
test.d(12): Error: scope variable p assigned to this with longer lifetime
Is there a subtle difference I'm missing?
|
Copyright © 1999-2021 by the D Language Foundation