No household is perfect
Marco Leise
Marco.Leise at gmx.de
Wed Dec 4 23:15:13 PST 2013
Am Tue, 03 Dec 2013 23:23:07 +0100
schrieb "monarch_dodra" <monarchdodra at gmail.com>:
> 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.
In this case I agree, but when porting some vector/matrix
code from C++ I found it hard to reproduce everything in D.
I can't quite remember the details, but I think it had to do
with mutual opOpAssign of classes in separate modules.
--
Marco
More information about the Digitalmars-d
mailing list