Operator overloading -- lets collect some use cases

Don nospam at nospam.com
Tue Dec 30 09:54:26 PST 2008


Frits van Bommel wrote:
> Don wrote:
>> Frits van Bommel wrote:
>>> Don wrote:
>>>> A straightforward first step would be to state in the spec that "the 
>>>> compiler is entitled to assume that X+=Y yields the same result as 
>>>> X=X+Y"
>>>
>>> That doesn't hold for reference types, does it?
>>
>> I thought it does? Got any counter examples?
> 
> For any class type, with += modifying the object and + returning a new one:

Sure, you can do it (behaviour inherited from C++), but is that _EVER_ a 
good idea? I can't think of any cases where that's anything other than a 
bug-breeder.

> You can't just arbitrarily substitute between these two.
I'm still looking for a use case where that substitution doesn't make 
sense. No-one has yet come up with such a use case. I postulate that it 
doesn't exist.




More information about the Digitalmars-d mailing list