struct opEquals

Steven Schveighoffer schveiguy at yahoo.com
Wed Mar 9 09:24:39 PST 2011


On Wed, 09 Mar 2011 12:15:26 -0500, SiegeLord <none at none.com> wrote:

> Steven Schveighoffer Wrote:
>
>> It's a mis-designed feature of structs.  There is a bug report on it:
>>
>> http://d.puremagic.com/issues/show_bug.cgi?id=3659
>
> It worked fine in D1. Or did you mean that the mis-designed feature is  
> the const system?

No, the mis-designed feature is the compiler requiring that specific  
signature in D2.  Const is not the mis-designed feature.

It works in D1 because D1 doesn't generate intelligent opEquals for  
structs that do not have them, it just does a bit compare.

For example, if you did this in D1, it fails the assert:

struct S
{
    string name;
}

void main()
{
    S s1, s2;
    s1.name = "hello".dup;
    s2.name = "hello".dup;
    assert(s1 == s2); // fails in D1, should pass on D2.
}

-Steve


More information about the Digitalmars-d-learn mailing list