On 05/05/2015 04:30 PM, Manfred Nowak wrote:
> On Tuesday, 5 May 2015 at 05:26:17 UTC, anonymous wrote:
>
>> because `c is c`
>
> Thanks. One can see this documented in
>    http://dlang.org/operatoroverloading.html#equals
>
> But
> 1: how can one override this behavior

There is now way in D other than changing the implementation:


https://github.com/D-Programming-Language/druntime/blob/master/src/object_.d#L141

(There is also object.di there but I think changing the function above should be sufficient.)

> 2: what is the design reason for this

I am guessing:

- For correctness, an object should be equal to itself

- Preventing memory errors when the left-hand side object is null.

- Reducing boilerplate

> Especially: how can one implement side effects on invoking `==' or `!='?
>
> -manfred

Can you use a member function instead as in c.eq(c)?

Ali

Reply via email to