Why struct opEquals must be const?

Steven Schveighoffer schveiguy at yahoo.com
Mon Oct 18 08:55:58 PDT 2010


On Mon, 18 Oct 2010 11:19:54 -0400, Pelle <pelle.mansson at gmail.com> wrote:

> On 10/18/2010 05:07 PM, Steven Schveighoffer wrote:

>> What case were you thinking of for requiring mutablity for equality
>> testing?
>>
>> -Steve
>
> I was thinking along the lines of not enforcing unexpected restrictions  
> on programmers because we couldn't think of a use case. This isn't an  
> enabler.

But D also has a good goal of not enabling bad design.  Even if through  
convention.  I personally don't see how opEquals can be forced into a  
particular signature (the current rules are too strict), but a philosophy  
that opEquals should refrain from changing the objects in question is a  
good one to have.

> Today, the check isn't very intelligent, which makes immutable structs  
> unusable.

Absolutely, hence the bug report.

-Steve


More information about the Digitalmars-d mailing list