With block proposal
Bill Baxter
wbaxter at gmail.com
Thu Aug 27 11:27:38 PDT 2009
On Thu, Aug 27, 2009 at 10:13 AM, Michiel
Helvensteijn<m.helvensteijn.remove at gmail.com> wrote:
> Daniel Keep wrote:
>
>>> you can also say
>>>
>>> { auto w = a; w.x = f(); w.x = g(); }
>>>
>>> or similar.
>>
>> Unless a is a value-type member of something else.
>
> That's why I said 'or similar'. Doesn't D have anything to create an
> alias/reference to a value-type variable?
Yes you can do
alias a w; w.x = f(); w.x = g();
But you can't do
alias a.b.c w; ...
And you can't create a ref local variable.
But you can make a pointer local variable, of course, and for most
purposes that's just as good since there's no need for -> in D.
If structs get real constructors I'll be ok with saying goodbye to with().
It's just too useful for writing opCall pseudo-constructors:
static T opCall() {
T R; with(R) {
x = 0;
y = 1;
z = getZValue();
} return R;
}
--bb
More information about the Digitalmars-d
mailing list