Inherited const when you need to mutate

Timon Gehr timon.gehr at gmx.ch
Tue Jul 10 16:16:01 PDT 2012


On 07/11/2012 12:39 AM, Walter Bright wrote:
> On 7/10/2012 3:13 PM, H. S. Teoh wrote:
>> I don't think they were rushed. There's been a push for making druntime
>> and Phobos const-correct for a while now. I don't think this change is a
>> _mistake_ per se, but it does expose a flaw in the language: const is
>> too limited in scope, and we need something else to fill in for use
>> cases where const isn't good enough.
>
>
> There's a gigantic problem with logical const. It is completely
> unenforceable - it is documentation only. All the reasoning and
> mechanical guarantees that come with const, immutable, and purity fall
> apart.
>

Const is stronger than what is required to bridge the gap between
mutable and immutable. It guarantees that a reference cannot be used to
mutate the receiver regardless of whether or not the receiver is
immutable underneath. That is unnecessary as far as immutable is
concerned. It only needs to guarantee that the receiver does not change
if it is immutable underneath.


More information about the Digitalmars-d mailing list