Want reasonable reference counting? Disable automatic sharing of immutable

Timon Gehr timon.gehr at gmx.ch
Sun Nov 14 20:22:39 UTC 2021


On 14.11.21 21:04, H. S. Teoh wrote:
> 
> So, either (1) we cannot use const/in in generic functions, or (2)
> ref-counted objects cannot be used in generic code.
> 
> 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.

I don't agree that it changes anything for generic code. `const` already 
prevents useful patterns such as lazy initialization.

The issue is that despite all that, people still think D const is 
similar to C++ const. It's really not. Notions such as "const 
correctness" are misguided in D.


More information about the Digitalmars-d mailing list