PrimitiveRef ?

Namespace via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Mar 23 13:58:47 PDT 2015


Something like that?

struct PrimitiveRef(T)
{
	private T* _value;

	@property
	ref inout(T) get() inout pure nothrow {
		assert(_value);
		
		return *_value;
	}
	
	alias get this;
	
	this(T val) {
		_value = new T(val);
	}
}

alias BoolRef = PrimitiveRef!bool;

void test(BoolRef b)
{
	b = true;
}

void main()
{
	BoolRef b = false;
	test(b);
	assert(b == true);	
}


More information about the Digitalmars-d-learn mailing list