std.typecons: PrimitiveRef

Andre via Digitalmars-d digitalmars-d at
Tue Mar 24 08:38:02 PDT 2015


Namespace helped me to get following template working.

struct PrimitiveRef(T)
	private T* _value;

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

The use case is a type tuple where you cannot use the keyword ref.

Example usage: ( This is an extract from a little event framework)

Event!(Object, BoolRef) onClose;

onClose.attach(&onFormClose); // function or delegate

void onFormClose(Object o, BoolRef canClose)
     canClose = false;

I think it is useful to add to std.typecons as there is no 
to use ref for type tuples.

Kind regards

More information about the Digitalmars-d mailing list