Unofficial wish list status.(Nov 2008)

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Sat Nov 1 12:42:00 PDT 2008


Andrei Alexandrescu wrote:
> I've been thinking of defining a simple function that binds to variable 
> addresses and allows assignment from a tuple, in which case the code 
> would be:
> 
> group(&code, &msg) = getError;
> 
> In "the future" we'll have variadic ref arguments, in which case the 
> "&"s can be dropped:
> 
> group(code, msg) = getError;

I've managed to make this work right now:
	group!(code, msg) = getError();

as well as (with a different function):
	group_!(code, msg) = getError();
	auto myGroup = group_!(code, msg);
	myGroup = getError();
(The second example has several implementations in fact. Unfortunately, 
all of them currently allocate a closure for the variables if they're 
local. The first one doesn't have that problem)

All of this is D2+Phobos, by the way. Though something similar could 
likely be made in D1 (minus the closure issues, obviously).


Unfortunately it does have a severe limitation: it only works on 
straight variables because it uses alias template parameters.
You can't assign to *b or foo.a, for instance (unless it's static).

See attachment for code.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: group.d
Type: text/x-dsrc
Size: 3694 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20081101/ed13ffcb/attachment.d>


More information about the Digitalmars-d mailing list