On 02/08/2015 05:21 AM, Danny wrote:

The obvious
     bool opEquals(immutable(C) b) immutable {
         return value == b.value;
     }
doesn't work. Probably have to override the one from Object ? Even
though I don't really use polymorphism here.

     override bool opEquals(Object b) immutable {
         return value == (cast(immutable(C)) b).value;
     }

Nope. Doesn't work (or compile) either.

Yes, opEquals for classes has a particular syntax:

  http://ddili.org/ders/d.en/object.html#ix_object.opEquals

Remember that 'const' binds to immutable as well. The following works with at least git head:

    override bool opEquals(Object b) const {
        auto rhs = cast(C)b;
        return rhs && (value == rhs.value);
    }

Ali

Reply via email to