Challenge: write a reference counted slice that works as much as possible like a built-in slice

deadalnix deadalnix at gmail.com
Tue Nov 9 11:19:38 UTC 2021


On Tuesday, 9 November 2021 at 09:02:32 UTC, Ola Fosheim Grøstad 
wrote:
> On Monday, 8 November 2021 at 22:07:46 UTC, Adam Ruppe wrote:
>> On Monday, 8 November 2021 at 21:42:12 UTC, Andrei 
>> Alexandrescu wrote:
>>> - work with qualifiers like T[] does, both RCSlice!(qual T) 
>>> and qual(RCSlice!T)
>>
>> I think this is an incorrect requirement. A const(T) is now 
>> allowed to increase a reference count by definition.
>
> This is technically true, but he wrote "built in", so then you 
> don't have to heed the same constraints. You only have to 
> require that acquire()/release() match up, so how that is 
> accounted for is an implementation detail since you don't 
> provide any access to the count.
>

Yes. In addition, it is worth mentioning that many functional 
programming languages are using reference counting internally. It 
is so that they can do copy on write instead of copying 
everything all the time for no reason.


More information about the Digitalmars-d mailing list