Rebooting the __metada/__mutable discussion
vit
vit at vit.vit
Sat Apr 9 06:25:10 UTC 2022
On Friday, 8 April 2022 at 18:00:14 UTC, rikki cattermole wrote:
> Here is my test code that I used to determine what I needed to
> do to make const RC types useless (and hopefully safe).
>
> ```d
> ...
> ```
I implemented shared_ptr/rc_ptr with this functionality (non
copyable const rc ptr):
https://github.com/submada/btl/blob/master/source/btl/autoptr/shared_ptr.d
https://github.com/submada/btl/blob/master/source/btl/autoptr/rc_ptr.d
It is in package btl:autoptr
(https://code.dlang.org/packages/btl).
Example:
```d
SharedPtr!(const int) sp = SharedPtr!int.make(42);
const SharedPtr!(const int) csp1 = sp; //OK
const SharedPtr!(int) csp2 = sp; //OK
sp = csp1; //ERROR
sp = csp2; //ERROR
//RcPtr is same.
```
Ref counted pointers in D have problem:
RAII in D is bad: move ctor are not implemented, overloading copy
ctors sometimes crash dmd, copy ctors are not called from GC
slices, dtors have bad interaction with stack tuples/value
sequences and opCast, emplace...
Simple ref counted pointers have also this problem:
```d
Rc!(const int) rc1 = Rc!(int).make(42);
Rc!(const int) rc2 = Rc!(immutable int).make(42);
```
Has `Rc!(const int)` atomic counting or not? :)
More information about the Digitalmars-d
mailing list