* bogus codegen with static opAssign() usage *
kris
foo at bar.com
Mon Feb 19 10:00:11 PST 2007
kris wrote:
> Walter Bright wrote:
>
>> a = b;
>>
>> is replaced with:
>>
>> a.opAssign(b);
>>
>> not:
>>
>> a = a.opAssign(b);
>>
>> The return value of opAssign comes in to play with:
>>
>> c = a = b;
>>
>> which is rewritten as:
>>
>> c = a.opAssign(b);
>
>
>
> Doh! Doh! Doh!
>
> My bad; I saw this elsewhere and just assumed it would operate correctly.
>
> The syntax, however, is very clean. Importantly, it supports the
> unification or /centralization/ of all those 'new' invocations. I'd go
> so far as to say such a syntax could represent a bridge between OO and
> scripting:
>
> ----
> String s = "mystring";
> ----
>
> ----
> File f = "/foo/bar.d";
> ----
>
> ----
> Regex r = "^(.*)$";
> ----
>
> There's a fairly wide range of simple applicability for this kinda'
> thing. Would be great if static opAssign() could support this, or some
> other operator were enabled?
>
> How about it?
One note: an operator is suggested so that structs could take advantage
of this also. Otherwise, some kind of 'property' assignment for a ctor
might have done the trick?
More information about the Digitalmars-d
mailing list