default '==' on structs

bearophile bearophileHUGS at lycos.com
Wed Feb 2 10:05:36 PST 2011


spir:

> * The issue reported is about '==' on structs not using member opEquals when 
> defined, instead performing bitwise comparison. This is not my case: Lexeme 
> members are plain strings and an uint. They should just be compared as is. 
> Bitwise comparison should just work fine.
> Also, this issue is marked solved for dmd 2.037 (I use 2.051).

Lars is right, the == among structs is broken still:

struct Foo { string s; }
void main() {
    string s1 = "he";
    string s2 = "llo";
    string s3 = "hel";
    string s4 = "lo";
    auto f1 = Foo(s1 ~ s2);
    auto f2 = Foo(s3 ~ s4);
    assert((s1 ~ s2) == (s3 ~ s4));
    assert(f1 == f2);
}

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list