Hi,

Namespace helped me to get following template working.

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);
        }
}

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 possibility
to use ref for type tuples.

Kind regards
André


Reply via email to