digitalmars.D.learn - ptr wrapper with dip1000
- vit (20/20) Dec 19 2017 How to manualy declare constructor for struct Ptr which work like
- Steven Schveighoffer (7/28) Dec 19 2017 I think this is a limitation of dip1000 that was not foreseen. I think
How to manualy declare constructor for struct Ptr which work like
Ptr.create?
struct Ptr{
int* ptr;
static Ptr create(scope return int* ptr) safe{
Ptr x;
x.ptr = ptr;
return x;
}
/++ This doesn't work:
this(scope return int* ptr)scope safe{
this.ptr = ptr;
}
+/
}
void main() safe{
int i;
auto x = Ptr(&i);
auto y = Ptr.create(&i);
}
Dec 19 2017
On 12/19/17 8:22 AM, vit wrote:
struct Ptr{
int* ptr;
static Ptr create(scope return int* ptr) safe{
Ptr x;
x.ptr = ptr;
return x;
}
/++ This doesn't work:
this(scope return int* ptr)scope safe{
this.ptr = ptr;
}
+/
}
void main() safe{
int i;
auto x = Ptr(&i);
auto y = Ptr.create(&i);
}
I think this is a limitation of dip1000 that was not foreseen. I think
when you mark the parameter `return`, `this` isn't actually considered a
return value, is it? So it doesn't link the lifetime of ptr to the
lifetime of this, which it should.
Please file an enhancement request, this should be allowed.
-Steve
Dec 19 2017








Steven Schveighoffer <schveiguy yahoo.com>