const ref in opAssign

Timon Gehr timon.gehr at gmx.ch
Tue Jun 26 11:54:30 PDT 2012


On 06/26/2012 08:40 PM, Jonathan M Davis wrote:
> On Tuesday, June 26, 2012 20:10:59 Timon Gehr wrote:
>> On 06/26/2012 02:44 PM, monarch_dodra wrote:
>>> Is there any way to enforce const correctness, ...
>>
>> Note that 'const correctness' is a C++ term that does not really have
>> an obvious counterpart in D.
>
> Really? I'd have said that a type was const correct if every one of its
> functions that could be const was const, and that applies to D as much as C++.

In C++ _every_ method can be const -- it is not more than 
conventionalised interface documentation.

In D, there is no way to tell whether some virtual method can be const 
without taking into account the entire code base.

This makes this definition of const correctness moot immediately for 
both C++ and D.

> It's just that you don't have the same issues with types subverting const in D
> that you have in C++, since there is no mutable keyword and casting away const
> and mutating the object is undefined.
>
> - Jonathan M Davis

Exactly, there is no obvious counterpart.


More information about the Digitalmars-d mailing list