How will we fix opEquals?

so so at so.so
Thu Feb 10 03:18:26 PST 2011


On Thu, 10 Feb 2011 10:58:25 +0200, Peter Alexander  
<peter.alexander.au at gmail.com> wrote:

> On 10/02/11 8:19 AM, Don wrote:
>> Andrei once stated a worthy goal: as far as possible, const should be
>> opt-in: it should be possible to code without requiring const on
>> everything.
>>
>> opEquals() is in conflict with this, since it is a member function of
>> Object.
>>
>> (1) If it is a const member function, then it will have a viral effect
>> on all objects -- any function called by opEquals will have to be marked
>> const.
>> (2) If it is not const, then const objects cannot be compared!
>>
>> Currently, it's not const, but the problem isn't visible because of
>> compiler bug 5080. (Same problem applies to opCmp).
>>
>> How will we break this dilemma?
>
> It's not possible. You need logical const to make const opt-in. This has  
> been argued many times by several people.

There might be a way involving something like inout attribute for  
functions.
It would solve these problems and wouldn't intrude those that don't care  
constness.


More information about the Digitalmars-d mailing list