Head Const

Chris Wright via Digitalmars-d digitalmars-d at puremagic.com
Fri Feb 19 14:04:26 PST 2016


On Fri, 19 Feb 2016 16:09:21 -0500, Andrei Alexandrescu wrote:

> On 02/19/2016 03:46 PM, Iakh wrote:
>> On Thursday, 18 February 2016 at 22:46:04 UTC, Walter Bright wrote:
>>> On 2/18/2016 10:22 AM, Timon Gehr wrote:
>>>> He wanted to embed a mutable reference count literally within a const
>>>> object.
>>>> Not a headconst object.
>>>
>>> I know. I pointed out how it could be done in a way to achieve the
>>> same effect.
>>>
>>> BTW, shared_ptr<> uses a pointer to the ref count.
>>
>> Could D RefCounted!T be splitted into data (possibly immutable) and
>> mutable metadata?
> 
> This is becoming an FAQ. I think someone should write a blog post about
> it. The basic problem here is composability is not possible with this
> approach. -- Andrei

In other words, it works fine if you have a ref-counted string. It works 
fine if you have a ref-counted list of ref-counted strings. But that list 
*must* be mutable.

You could work around this by creating different types for a logically 
immutable / const refcounted list of ref-counted items than for a mutable 
one. But that's ugly, awkward to work with, and annoying to create.


More information about the Digitalmars-d mailing list