[phobos] Issue with opEquals(Object, Object)

Andrei Alexandrescu andrei at erdani.com
Tue Apr 27 12:45:03 PDT 2010


On 04/27/2010 06:55 AM, Steve Schveighoffer wrote:
> Following the example in the book, let's say I make my own widget,
> called StevesTextWidget, which inherits Widget, not TextWidget.  It
> has some of the same functionality as TextWidget, but it's not a
> TextWidget.  If I want to be able to compare StevesTextWidget to a
> TextWidget, it's not possible, because the TextWidget will veto every
> time, even though StevesTextWidget has total understanding of
> TextWidget and can correctly do the comparison.  On the other hand,
> if || was used, comparing StevesTextWidget to a Widget will allow
> Widget's routine to override the opEquals of StevesTextWidget, and
> like the example in the book, could possibly cause an invalid equal
> response.

Let's suppose we allow the feature above. Then a StevesTextWidget can 
claim equality with a TextWidget in spite of the latter's opposition. 
But then a WaltersTextWidget could also claim equality with the same 
TextWidget, again in spite of the latter's opposition. But then 
StevesTextWidget may not compare equal with WaltersTextWidget, which 
would break transitivity.

Andrei


More information about the phobos mailing list