Re: -dip1000 @safe scope wrapper

2018-06-28 Thread Chris M. via Digitalmars-d-learn

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();
scope Wrapper w2 = Wrapper();
}


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?




-dip1000 @safe scope wrapper

2018-06-28 Thread vit via Digitalmars-d-learn

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();
scope Wrapper w2 = Wrapper();
}