why are opCmp and opEquals not pure.

Steven Schveighoffer via Digitalmars-d digitalmars-d at puremagic.com
Thu Sep 17 13:48:10 PDT 2015


On 9/17/15 4:24 PM, Stefan Koch wrote:
> On Thursday, 17 September 2015 at 19:47:05 UTC, Timon Gehr wrote:
>
>> I don't get this point. You don't need any annotations to write
>> ctfe-able code.

> ctfe only works with pure functions.

This is not a requirement of ctfe, although the set of functions that 
can be pure I think encloses the set of ctfe-able functions (there may 
be some exceptions, I'm not sure). The requirements are listed here: 
http://dlang.org/function.html#interpretation

But you don't actually have to mark them pure, and a virtual pure 
function cannot be CTFE anyways, so this doesn't make a difference.

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

Then surely you meant const? pure functions can mutate state. I agree 
with your statement, though.

I think Object.opEquals and Object.opCmp are going to eventually be 
removed, so you can define them however you want.

-Steve


More information about the Digitalmars-d mailing list