What's the correct opEquals signature for structs?

Alex Rønne Petersen xtzgzorex at gmail.com
Tue Mar 13 14:03:45 PDT 2012


On 13-03-2012 21:55, Jonathan M Davis wrote:
> On Tuesday, March 13, 2012 19:28:26 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?
>
> At present, I believe that the correct solution is to have two opEquals.
> That's what Kenji did when he fixed the various structs in Phobos recently. For
> instane, std.datetime.SysTime's opEquals now looks like this:
>
> bool opEquals(const SysTime rhs) const pure nothrow
> {
>   return opEquals(rhs);
> }
>
> /// ditto
> bool opEquals(const ref SysTime rhs) const pure nothrow
> {
>   return _stdTime == rhs._stdTime;
> }
>
> Ideally, auto ref would work, but it currently only works with templates. I
> believe that that's supposed to be changed, but it hasn't been yet.
>
> - Jonathan M Davis

Did you see my other post? Maybe we could do something like this:

equals_t opEquals()(const auto ref SysTime rhs) const pure nothrow

-- 
- Alex


More information about the Digitalmars-d-learn mailing list