Operator overloading -- lets collect some use cases

Weed resume755 at mail.ru
Thu Jan 1 14:25:36 PST 2009


Don пишет:
> Weed wrote:
>> Frits van Bommel пишет:
>>> 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:
>>
>> The += operator too should return the object (usually "this")
> 
> ALWAYS 'this'. It's another feature of operator overloading which is
> redundant.


Not always. Can be more convenient to create the new object and to
return it.

For example: if it is necessary to return the object containing the
sorted data those sorting hurriedly at creation of the returned object
can give a scoring in performance than if the data is sorted in the
current object after their change.



More information about the Digitalmars-d mailing list