Challenge: write a reference counted slice that works as much as possible like a built-in slice
Timon Gehr
timon.gehr at gmx.ch
Tue Nov 9 00:29:48 UTC 2021
On 09.11.21 01:12, H. S. Teoh wrote:
> On Mon, Nov 08, 2021 at 10:15:09PM +0000, deadalnix via Digitalmars-d wrote:
> [...]
>> I think however, you missed several massive problems:
>> 4. Type qualifier transitivity. const RCSlice!T -> const
>> RCSlice!(const T) conversion needs to happen transparently.
>
> The only way this can happen is via a language change. The only way
> arrays get to enjoy such benefits is because the necessary implicit
> conversion rules are baked into the language. User-defined types do not
> have such privileges, and there is currently no combination of language
> constructs that can express such a thing.
>
>
>> 5. Head mutability. const RCSlice!(const T) -> RCSlice!(const T)
>> conversion needs to happen transparently.
> [...]
>
> Ditto.
>
> Basically, for something to be ref-counted, you need:
>
> 1) To attach a counter to the type that remains mutable in spite of the
> payload being possibly const or immutable.
> ...
And to do that, you have to explicitly specify the semantics of
qualifiers based on a set of allowed rewrites, and there needs to be a
way to ensure low-level bookkeeping does not get elided. This was the
__mutable proposal.
More information about the Digitalmars-d
mailing list