Re: How to make a transparent wrapper type?

2015-12-08 Thread Random D user via Digitalmars-d-learn
On Monday, 7 December 2015 at 20:03:07 UTC, Namespace wrote: This seems to work: struct RefVal(T) { private T* ptr; this(T* val) { ptr = val; } ref auto opAssign(U)(auto ref U value) { *ptr = value;

Re: How to make a transparent wrapper type?

2015-12-08 Thread Random D user via Digitalmars-d-learn
On Tuesday, 8 December 2015 at 10:26:18 UTC, Random D user wrote: On Monday, 7 December 2015 at 20:03:07 UTC, Namespace wrote: This seems to work: struct RefVal(T) { private T* ptr; this(T* val) { ptr = val; } ref auto

How to make a transparent wrapper type?

2015-12-07 Thread Random D user via Digitalmars-d-learn
I kind of miss reference values on stack, so I attempted to make one in a struct. Pointers are pretty good (since d doesn't have ->), but it would be nice to avoid dereferencing them explicitly on assignment. Since reference is a pointer that you can't change afterwards. I tried something like

Re: How to make a transparent wrapper type?

2015-12-07 Thread Namespace via Digitalmars-d-learn
This seems to work: struct RefVal(T) { private T* ptr; this(T* val) { ptr = val; } ref auto opAssign(U)(auto ref U value) { *ptr = value; return *ptr; } auto