opStarAssign?

Janice Caron caron800 at googlemail.com
Fri Nov 23 08:18:11 PST 2007


On 11/23/07, Leonard Dahlmann <leo.dahlmann at gmail.com> wrote:
> What about *p *=, *p /=, *p ~=, ...?
> Wouldn't these need overloads, too?

I don't see why. We've done just fine without a[n]*=, a[n]/=, a[n]~=
and so on, so why should * be any different?

My preference would be to have the compiler rewrite
    *p += n;

as
    p.opDerefAssign(p.opDeref() + n);

(Ditto with .length, [] and so on). That way only two functions are
needed, but you still get the full suite of expressability.

Note that if the compiler is able to inline both opDeref() and
opDerefAssign() then you'd still get the efficiency of ... er ...
opDerefAddAssign ... without having the clutter of a zillion different
functions.

Of course, having functions return references is another approach too.



More information about the Digitalmars-d mailing list