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

H. S. Teoh hsteoh at quickfur.ath.cx
Tue Nov 9 05:30:53 UTC 2021


On Mon, Nov 08, 2021 at 10:38:59PM -0500, Steven Schveighoffer via Digitalmars-d wrote:
> On 11/8/21 8:04 PM, deadalnix wrote:
> > On Monday, 8 November 2021 at 22:40:03 UTC, Andrei Alexandrescu wrote:
> > > On 2021-11-08 17:26, rikki cattermole wrote:
> > > > a reference counted struct should never be const
> > > 
> > > So then we're toast. If that's the case we're looking at the most
> > > important challenge to the D language right now.
> > 
> > Not necessarily, but this is in fact the same problem as the head
> > mutable problem.
> > 
> > If `const RCSlice!(const T)` can convert to `RCSlice!(const T)`,
> > which it should to have the same semantic as slice.
> > 
> > The reference counting problem goes away if you can mutate the head.
> 
> The reference count cannot be in the head, it has to be in the block.
> So this conversion is actually unsound.
[...]

It could work if the block has a mutable counter at the top and the rest
is immutable/const.  But the current type system cannot express such a
thing; if the head is const, then it's const all the way down.


T

-- 
Two wrongs don't make a right; but three rights do make a left...


More information about the Digitalmars-d mailing list