A fresh look at comparisons
Scott S. McCoy
tag at cpan.org
Tue Apr 15 02:42:49 PDT 2008
I agree that's tricky, but isn't it infact true that opEquals is defined
as a multimethod?
It appears to be, please follow this link: http://codepad.org/z09oUtB4
So maybe you would just like it to return bool, as opposed to int? Or
maybe it needs better documentation?
Cheers,
Scott S. McCoy
On Tue, 2008-04-15 at 07:49 +0100, Janice Caron wrote:
>
> As you know, in existing D, opEquals(), at least for classes, is
> defined to take an Object parameter, not a C parameter, so even
> ignoring the inheritance rules, allowing opEquals to compare against
> multiple types is tricky. You end up writing code like
>
> int opEquals(Object o)
> {
> A a = cast(A)o;
> B b = cast(B)o;
> C c = cast(C)o;
>
> if (c !is null)
> {
> ...
> }
> else if (b !is null)
> {
> ...
> }
> else if (a !is null)
> {
> ...
> }
> }
>
> which is not ideal
>
More information about the Digitalmars-d
mailing list