[Issue 3433] New: [tdpl] Comparing structs for equality is not member-by-member

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Oct 21 07:40:36 PDT 2009


http://d.puremagic.com/issues/show_bug.cgi?id=3433

           Summary: [tdpl] Comparing structs for equality is not
                    member-by-member
           Product: D
           Version: unspecified
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: andrei at metalanguage.com


--- Comment #0 from Andrei Alexandrescu <andrei at metalanguage.com> 2009-10-21 07:40:35 PDT ---
import std.math, std.stdio;

struct Point { 
   float x = 0, y = 0;
   // /*[\textit{\textbf{Added}}]*/
   bool opEquals(Point rhs) {
      // Perform an approximate comparison
      return approxEqual(x, rhs.x, 1e-3, 1e-5) && approxEqual(y, rhs.y, 1e-3,
1e-5);
   }
}

struct Rectangle {
   Point leftBottom, rightTop;
}

unittest {
   Rectangle a, b;
   assert(a == b);
   a.leftBottom.x = 1e-8;
   assert(a == b);
   a.rightTop.y = 5;
   assert(a != b);
}

This fails because Point.opEquals is never called.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list