Challenge: write a reference counted slice that works as much as possible like a built-in slice
Ola Fosheim Grøstad
ola.fosheim.grostad at gmail.com
Tue Nov 9 09:02:32 UTC 2021
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.
Same goes for pure functions. You can imagine that all pure
function calls have a hidden parameter with "ref count storage",
which it is allowed to modify.
So you might be able do this without breaking the type system, if
it is builtin, but you have to prove it.
(Basic implementation is to use fat pointers and keep the counter
in mutable memory, like shared_ptr. Anything beyond that is an
optimization.)
More information about the Digitalmars-d
mailing list