On 3/3/15 12:53 AM, Volodymyr wrote:
On Thursday, 26 February 2015 at 21:50:56 UTC, Andrei Alexandrescu wrote:
http://wiki.dlang.org/DIP74 got to reviewable form. Please destroy and
discuss.
Thanks,
Andrei
With opAddRef/opRelease class does respondible for its dealocation and
its own payload so breaks SOLID's single responsibility principle.
Correct. That's a tactical matter that can be addressed e.g. with mixin
templates.
As
for me better design will be to do it closer to C++'s shared_ptr.
e.g:
// maybe with @arc
struct RefCounter(T)
{
void opAddRef();
void opRelease();
ref T obj;
ref size_t count;
}
}
RefCounter!Widged myRefToWidget;
RefCounter with default ctor/dtor. opAddRef and opRelease is for
compiler optimtimisation and elimination of redunadant ref counter
increment/decrement.
We couldn't make that work with safety.
Andrei