Inability to dup/~ for const arrays of class objects
monarch_dodra
monarchdodra at gmail.com
Wed May 29 05:38:15 PDT 2013
On Wednesday, 29 May 2013 at 12:23:04 UTC, Jakob Ovrum wrote:
> On Wednesday, 29 May 2013 at 09:40:08 UTC, monarch_dodra wrote:
>> whereas D's means "This object's value WILL remain constant,
>> until the end of time, and under no circumstance can it ever
>> be modified. Oh. And so will everything it references".
>
> That's NOT what D's const means! The data may change through
> other, mutable references to it, but not through any const
> references. That's why const data is not implicitly convertible
> to immutable data (unless it has no mutable indirection, in
> which case it would be a deep copy) - there could be mutable
> references out there!
>
> The difference between C++ and D const is that D's const is
> transitive, and mutating it by casting away const can have
> terrible consequences because const is designed to work with
> immutable.
>
>> The fact that *you* are promising to not change it is
>> irrelevant to the concept of D's const. D only knows 2 states:
>> objects that mutate, and objects that don't mutate.
>
> No.
>
>> *Once you've casted something to const, make sure that NOTHING
>> will modify the object via a non-const handle.
>
> This is *perfectly fine* unless the non-const handle was
> acquired by casting away const or immutable.
Hum.
...
Sight. I think I let immutable get to my head again :/
You are right. My point was moot.
More information about the Digitalmars-d
mailing list