opIndexAddAssign? ...
Stewart Gordon
smjg_1998 at yahoo.com
Fri Feb 9 08:25:34 PST 2007
Manfred Nowak Wrote:
> On writing the implementation of a map, where the Valuetype is a
> set, I had to stop on recognizing, that only opIndexAssign is
> permitted.
To add opIndexAddAssign et al would be a step back towards the old C++ nightmare of providing lots of operator overloads where just one should suffice.
> I.e.:
> map[key]+= element;
> has no possible overload.
>
> OpIndex delivers an rvalue and the only possibility to get an
> lvalue is in conjunction with a plain assignment.
>
> Why arbitrary restrictions when the goal is to have great
> expressiveness?
I agree. It's been said about properties enough times, and the same should apply to array indexes. That is,
qwert[yuiop] op= asdfg
should be, in the lack of any overriding alternative (such as an op<op>Assign on the type of qwert[yuiop]), equivalent to
qwert[yuiop] = qwert[yuiop] op asdfg
except that qwert and yuiop are evaluated only once.
Stewart.
More information about the Digitalmars-d
mailing list