Review Queue

Jonathan M Davis jmdavisProg at gmx.com
Sat Jun 9 00:48:25 PDT 2012


On Saturday, June 09, 2012 09:34:51 Johannes Pfau wrote:
> I think the changes to opEquals were rolled back, but what are the
> correct signatures for opEquals and opCmp now?

For the moment, the correct way is to declare two overloads, both with const 
parameters, with one being ref:

bool opEquals(const S rhs) @safe const pure nothrow
{...}

bool opEquals(const ref S rhs) @safe const pure nothrow
{...}

and

int opCmp(const S rhs) @safe const pure nothrow
{...}

int opCmp(const ref S rhs) @safe const pure nothrow
{...}

You _might_ get away with not having the ref version, I don't know, but you 
need the non-ref version, and if you don't make it const but you do make the 
ref version const, then you're going to have problems (especially if you have 
the non-ref version call the ref version as is likely the case - you'd get 
infinite recursion).

- jonathan M Davis


More information about the Digitalmars-d mailing list