D 2015/2016 Vision?

Adam D. Ruppe via Digitalmars-d digitalmars-d at puremagic.com
Wed Oct 7 09:13:14 PDT 2015


On Wednesday, 7 October 2015 at 15:13:40 UTC, Jonathan M Davis 
wrote:
> std.typecons.RefCounted aside, it's quite possible as-is to 
> implement smart pointers in D with structs, thus providing 
> deterministic destruction for reference types. I don't know why 
> RefCounted wasn't implemented to work with classes, and I don't 
> know why Walter and Andrei think that something like DIP 74 is 
> necessary to support ref-counting.

There's a lot of hassles with a wrapper, the biggest blocker 
being how it interacts with inheritance.

interface Base {}
class Foo : Base {}

void test(RefCounted!Base b) {}

RefCounted!Foo foo = initialized;
test(foo);

What happens? Well, you could alias this to Base... but what 
about to Object? We'd need multiple alias this to get it all 
working right, and then it'd still be kinda a pain.

Also, what about covariant method overriding? Base class returns 
RefCounted!this and child class does too... will it be accepted?


Library refcounting is cool and great for a great many things, 
but it doesn't play well with classes at all, inheritance just 
makes it too complicated.


The magic of dip74 is that most the language remains the same so 
those cases are already covered.



More information about the Digitalmars-d mailing list