Daniel Gibson:

That would be too much magic => special cases one has to know about.

What special cases? It works for POD structs. If you want a different hashing behavior (example: you want to ignore some fields), you define the two methods.


struct Foo {
    double x;
    int y;
    string s;
}

void main() {
    import std.stdio;

    bool[Foo] aa;
    aa[Foo(1.0, 2, "hello".idup)] = true;
    aa[Foo(1.0, 1, "hello".idup)] = false;
    aa[Foo(1.0, 2, "hello".idup)] = false;
    aa.writeln;
}


Outputs:

[Foo(1, 1, "hello"):false, Foo(1, 2, "hello"):false]

This was a very old large bug of D. Now it's fixed. Rejoice.

Bye,
bearophile

Reply via email to