Persistent list

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Sun Nov 15 06:23:03 PST 2015


On Sunday, 15 November 2015 at 12:56:27 UTC, Andrei Alexandrescu 
wrote:
> On 11/14/2015 05:49 PM, Timon Gehr wrote:
>> List uses RC internally. I don't think the UB casts will stay 
>> for the
>> final version, unless you are willing to completely dilute the 
>> meaning
>> of const in ways that Walter has explicitly expressed will not 
>> be done
>> in the past.
>
> As I mentioned, he's okay with changing the language to make 
> the casts well defined. -- Andrei

Well, that's a big change, since it pretty much means that D's 
const isn't physical const anymore, and Walter has been _very_ 
insistent about that in the past - to the point that he's argued 
that C++'s const is outright useless because it isn't physical 
const. If casting away const and mutating is well-defined 
behavior, then we basically have C++'s const except that it's 
transitive, and you have to be careful to make sure that the 
object isn't actually immutable underneath the hood instead of 
mutable, whereas C++ doesn't have immutable.

But if we go that route, personally, I think that it would be far 
better to do something like @mutable and leave mutating const and 
undefined outside of @mutable, particularly since if we can 
implement @mutable properly, then the compiler can guarantee that 
the object being mutated isn't actually immutable, and it avoids 
the need for casting altogether, which reduces the risk of bugs 
even when immutable isn't involved. It also means that the 
programmer can determine whether an object is really only 
logically const rather than physically const by looking at its 
member variables rather than having to dig through all of its 
code to see whether it ever casts away const.

- Jonathan M Davis


More information about the Digitalmars-d mailing list