Re: smart pointer for interior pointers

2015-05-28 Thread Steven Schveighoffer via Digitalmars-d
On 5/27/15 6:21 PM, Artur Skawina via Digitalmars-d wrote: But with alias this, we can define a way to solve all these problems. struct SPtr(T) { ptrdiff_t _offset; void opAssign(T *orig) { _offset = cast(void *)orig - cast(void *)this;} inout(T) *_get() inout { return

Re: smart pointer for interior pointers

2015-05-28 Thread Steven Schveighoffer via Digitalmars-d
On 5/27/15 9:13 PM, ketmar wrote: On Wed, 27 May 2015 17:31:32 -0600, Steven Schveighoffer wrote: But we can solve this with a postblit: seems that you forgot about move semantics for structs. under some conditions struct can be moved, not copied, so it `memcpy`ed and no postblit will be

Re: smart pointer for interior pointers

2015-05-27 Thread ketmar via Digitalmars-d
On Wed, 27 May 2015 17:31:32 -0600, Steven Schveighoffer wrote: But we can solve this with a postblit: seems that you forgot about move semantics for structs. under some conditions struct can be moved, not copied, so it `memcpy`ed and no postblit will be called. signature.asc Description:

Re: smart pointer for interior pointers

2015-05-27 Thread Artur Skawina via Digitalmars-d
On 05/28/15 01:31, Steven Schveighoffer via Digitalmars-d wrote: I just was working on a project, and I had a need for two members of a struct to share state. How could this work? A simple example: struct S { int x; int *y; // should refer to x this(int v) { x = v;

smart pointer for interior pointers

2015-05-27 Thread Steven Schveighoffer via Digitalmars-d
I just was working on a project, and I had a need for two members of a struct to share state. How could this work? A simple example: struct S { int x; int *y; // should refer to x this(int v) { x = v; y = x; } } But this doesn't work on copying, because when you