digitalmars.D - std.typecons: PrimitiveRef
- Andre (30/30) Mar 24 2015 Hi,
- Andre (2/2) Mar 24 2015 Definition of BoolRef:
- Gary Willoughby (3/5) Mar 24 2015 Could template alias parameters not be used here?
- Andre (14/19) Mar 24 2015 Event is defined as struct Event(T...){}.
- Dicebot (5/8) Mar 24 2015 This sounds like a bad idea because in D `ref` is not a type
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é
Mar 24 2015
Definition of BoolRef: alias BoolRef = PrimitiveRef!bool;
Mar 24 2015
On Tuesday, 24 March 2015 at 15:38:04 UTC, Andre wrote:The use case is a type tuple where you cannot use the keyword ref.Could template alias parameters not be used here? http://dlang.org/template.html#aliasparameters
Mar 24 2015
On Tuesday, 24 March 2015 at 16:58:48 UTC, Gary Willoughby wrote:On Tuesday, 24 March 2015 at 15:38:04 UTC, Andre wrote:Event is defined as struct Event(T...){}. That way the actual number of parameters is very flexible. I just checked template alias parameters. Also here the ref keyword is not allowed: struct Event(alias x) { private void delegate(x)[] _dlgArr; } Event!(ref bool) onEvent; Error is thrown: expression expected not ref. Kind regards AndréThe use case is a type tuple where you cannot use the keyword ref.Could template alias parameters not be used here? http://dlang.org/template.html#aliasparameters
Mar 24 2015
On Tuesday, 24 March 2015 at 15:38:04 UTC, Andre wrote:I think it is useful to add to std.typecons as there is no possibility to use ref for type tuples.This sounds like a bad idea because in D `ref` is not a type qualifier and thus not part of a type. Not though that you can apply ref storage class to type tuple as a whole: void foo(T...)(ref T args) { }
Mar 24 2015









"Andre" <andre s-e-a-p.de> 