How to make a transparent wrapper type?

Random D user via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Dec 8 02:26:18 PST 2015


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;
> 		
> 		return *ptr;
> 	}
> 	
> 	auto get() inout {
> 		return ptr;
> 	}
> }
> ----

Yes. It works for assignment as expected. Thanks. I don't know 
why I didn't try that. I mean I tried something like this:

struct RefVal(T)
{

}


More information about the Digitalmars-d-learn mailing list