No household is perfect

monarch_dodra monarchdodra at gmail.com
Tue Dec 3 14:23:07 PST 2013


On Tuesday, 3 December 2013 at 20:09:52 UTC, Ary Borenszweig 
wrote:
> On 12/3/13 4:53 PM, Andrei Alexandrescu wrote:
>> On 12/3/13 4:41 AM, Russel Winder wrote:
>>> On Tue, 2013-12-03 at 13:29 +0100, Tobias Pankrath wrote:
>>> […]
>>>> Does scala have arbitrary operators like Haskell? Looks 
>>>> useless
>>>> in D. If you have an operator '+' that should not be 
>>>> pronounced
>>>> 'plus' you are doing it wrong.
>>>
>>> Yes.
>>>
>>>    a + b
>>>
>>> could be set union, logic and, string concatenation. The + is 
>>> just a
>>> message to the LHS object
>>
>> or RHS :o).
>
> How come?

"opBinaryRight":
http://dlang.org/operatoroverloading.html

It's a "neat" feature that allows operators being member 
functions, yet still resolve to the right hand side if needed. 
For example:
auto result = 1 + complex(1, 1);

Will compile, and be re-written as:
auto result = complex(1, 1).opBinaryRight!"+"(1);

In contrast, C++ has to resort to non-member friend operators to 
make this work.


More information about the Digitalmars-d mailing list