why are opCmp and opEquals not pure.

Timon Gehr via Digitalmars-d digitalmars-d at puremagic.com
Thu Sep 17 12:47:04 PDT 2015


On 09/17/2015 08:37 PM, Stefan Koch wrote:
> Hi,
> is there any reason why opCmp and opEquals are not pure ?

Not all reasonable implementation are. Arguably, the methods shouldn't 
even be on Object.

> I would argue it is very counter-intuitive to mutate any state when
> comparing objects.
> ...

Not if it is done to improve performance, but not visible semantics.

> opCmp and opEquals not being annotated pure is a major problem for me in
> writing ctfe-able code.
>
> since any call to Object.opEquals need to be warped in another function
> to be able to cast the Function pure.
>

I don't get this point. You don't need any annotations to write 
ctfe-able code. Also, I think there were some efforts to make a template 
out of core.object.opEquals, in order to preserve the attributes. (Such 
that, as long as one doesn't work with plain Objects, the missing pure 
annotation would have no influence.)


More information about the Digitalmars-d mailing list