PrimitiveRef ?

Andre via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Mar 23 09:58:48 PDT 2015


Hi,

I read that if a structure only contains a reference, it will 
behave like a reference type in function calls (needed for 
specifying reference behavior in a type tuple).
I need exactly that behavior. I am currently unsure whether it is 
possible at all to have such a construct which works at user side 
exactly like a boolean (booleans can be assigned and directly 
compared with ==) but internally are pointers...

(The coding does not compile)

Kind regards
André


struct PrimitiveRef(T)
{
	private T* _value;

	alias  _value this;
	
	void opAssign(T v)
	{
		_value = v;
	}
	
}
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