[Issue 1429] New: Equality for associative arrays doesn't work

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Aug 18 02:13:52 PDT 2007


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

           Summary: Equality for associative arrays doesn't work
           Product: D
           Version: unspecified
          Platform: Macintosh
        OS/Version: Mac OS X
            Status: NEW
          Keywords: spec
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: josh at besquared.net


Sample code below along with a basic equals implementation to show they are
equal in content.

import std.stdio;

bool equals(T, U)(T[U] container, T[U] other) {
        T[U] tmp = container;
        foreach(U key, T value; other) {
                if(!(key in container && value == container[key])) {
                        return false;
                }
        }
        return true;
}

void main() {
        int[char[]] a = ["hello"[]:1, "test"[]:2];
        int[char[]] b = ["hello"[]:1, "test"[]:2];

        writefln( a == a ); //=> true
        writefln( a == b ); //=> false
        writefln( a.equals(b) ); //=> true

        writefln( ["hello"[]:1, "test"[]:2] == ["hello"[]:1, "test"[]:2] );
//=> false
        writefln( ["hello"[]:1, "test"[]:2].equals(["hello"[]:1, "test"[]:2])
); //=> true

        writefln( a is a ); //=> obviously true 
        writefln( a is b ); //=> obviously false just checking
}

looks like equality is linked with identity. Is this a bug?


-- 



More information about the Digitalmars-d-bugs mailing list