November 21, 2004
Say I have the following interfaces:

  interface Locus {
   int opEquals(Locus that);
  }
  interface Extents {
   int opEquals(Extents that);
  }
  interface Rectangle : Locus, Extents {
   int opEquals(Rectangle that);
  }

Given two objects that implement Rectangle, is there some syntax in D to allow me to compare their Extents or Locus?  Maybe something along the lines of:

    Rectangle r1, r2;
    ...
    if (r1 == cast(Extents)r2) {
        // r1 has the same Extents as r2
        ...

This seems right to me, but I haven't written any OO in D yet.

Thanks,
Garett


November 22, 2004
Garett Bass wrote:
> Say I have the following interfaces:
> 
>   interface Locus {
>    int opEquals(Locus that);
>   }
>   interface Extents {
>    int opEquals(Extents that);
>   }
>   interface Rectangle : Locus, Extents {
>    int opEquals(Rectangle that);
>   }
> 
> Given two objects that implement Rectangle, is there some syntax in D to allow me to compare their Extents or Locus?  Maybe something along the lines of:
> 
>     Rectangle r1, r2;
>     ...
>     if (r1 == cast(Extents)r2) {
>         // r1 has the same Extents as r2
>         ...
> 
> This seems right to me, but I haven't written any OO in D yet.

I haven't actually tried compiling the code above, but it certainly seems reasonable to me.  Try compiling it, and tell us what you find!