opIndexAddAssign? ...

Andrei Alexandrescu (See Website For Email) SeeWebsiteForEmail at erdani.org
Fri Feb 9 11:55:50 PST 2007


Stewart Gordon wrote:
> 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.

Same with .length.

arr.length += 2;


Andrei



More information about the Digitalmars-d mailing list