www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 3844] New: Require opEquals/opCmp in a class the defines toHash

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3844

           Summary: Require opEquals/opCmp in a class the defines toHash
           Product: D
           Version: 2.040
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc



This code compiles and runs:

class Foo {
    int a, b;
    override hash_t toHash() { return a + b; }
    this(int aa, int bb) { this.a = aa; this.b = bb; }
}
void main() {
    int[Foo] aa1;
    aa1[new Foo(1, 2)] = 10;
}

I think in a class it's not that useful to define toHash and not define
opEquals/opCmp too. So when a toHash is defined, the compiler can raise a
warning to require the definition of an opEquals/opCmp too.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 23 2010
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3844




See also bug 4290

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