Want reasonable reference counting? Disable automatic sharing of immutable
Ola Fosheim Grøstad
ola.fosheim.grostad at gmail.com
Mon Nov 15 08:38:07 UTC 2021
On Monday, 15 November 2021 at 07:14:12 UTC, Walter Bright wrote:
> On 11/14/2021 12:04 PM, H. S. Teoh wrote:
>> Given D's emphasis on generic code, (1) seems like the only
>> viable
>> option. Which makes const in D even narrower in scope than
>> ever.
>
> C++ const doesn't actually work, which is why C++ ref counted
> objects can be const.
Uh? C++ shared_ptr stores the count in a separate object.
The reason you can cast away const is so that you can call C-APIs
that actually have const-behaviour, but not a const signature.
You have to be able to do this in D to.
More information about the Digitalmars-d
mailing list