operator overloading rewrite rules

Timon Gehr timon.gehr at gmx.ch
Wed Jan 15 11:31:57 PST 2014


On 01/15/2014 07:36 PM, Daniel Kozak wrote:
> On this page http://dlang.org/operatoroverloading.html#Binary, is this
> statement:
>
> "The expression:
>
> a op b
> is rewritten as both:
>
> a.opBinary!("$(METACODE op)")(b)
> b.opBinaryRight!("$(METACODE op)")(a)"
>
> Which is true when a or b is object or struct, but it doesn't work for
> basic type or arrays wih ufcs.

It is this bug: https://d.puremagic.com/issues/show_bug.cgi?id=8062

The problem is that the spec is not explicit about this: "Operator 
overloading is accomplished by rewriting operators whose operands are 
class or struct objects into calls to specially named _member functions_."

http://dlang.org/operatoroverloading.html

Some consider it expected behaviour, based on the explicit mention of 
'member function' in the spec.


More information about the Digitalmars-d mailing list