What's the correct opEquals signature for structs?

Johannes Pfau nospam at example.com
Wed Mar 14 08:11:07 PDT 2012


Am Tue, 13 Mar 2012 19:31:45 +0100
schrieb Alex Rønne Petersen <xtzgzorex at gmail.com>:

> On 13-03-2012 19:28, Johannes Pfau wrote:
> > My std.uuid module doesn't compile with the latest dmd. I guess it's
> > because of a wrong opEquals signature, this is what I have now:
> >
> > ----------
> > @safe pure nothrow bool opEquals(ref const UUID s) const
> > {
> >      return s.data == this.data;
> > }
> > ----------
> >
> > and
> >
> > ----------
> > assert(UUID("00000000-0000-0000-0000-000000000000") == nilUUID);
> > ----------
> > The complete code is here:
> > https://github.com/jpf91/phobos/blob/std.uuid/std/uuid.d
> >
> > What's the best way to solve this issue?
> 
> Welcome to opEquals/opCmp/toHash hell. ;)
> 
> Try removing the ref on the parameter.
> 
> (Stylistic note: use equals_t instead of bool.)
> 

Thanks all for your answers!
Removing the ref / adding an overload without the ref indeed fixed this
problem.
I didn't change bool to equals_t yet, that's probably a
question for the review.



More information about the Digitalmars-d-learn mailing list