Are D classes proper reference types?
kinke
noone at nowhere.com
Sat Jun 26 07:39:44 UTC 2021
On Saturday, 26 June 2021 at 07:00:37 UTC, Ola Fosheim Grøstad
wrote:
>> Weak pointers aren't in the language, so I don't see why they
>> would matter here. I thought you were after replacing
>> GC-allocated class instances by a simple RC scheme.
>
> One goal could be to make a class compatible with C++ or Swift
> on request. Both support weak pointers. You could have multiple
> ref-count layout schemes as long as they all are on negative
> offsets. Just don't mix class hierarchies. So you could mix a
> D class hierarchy, C++ class-hiearchy and Swift class-hierarchy
> in the same codebase?
I'm pretty sure I haven't seen a weak pointer in C++ yet. I don't
look at C++ much anymore, but I suspect they are even a lot rarer
than shared_ptr. Wrt. mixed class hierarchies, being able to
inherit from and instantiate C++ classes in D is of some priority
and mostly works today. (Let's not get into discussing multiple
inheritance here, it's hardly a show-stopper for most use cases.)
Is Swift a thing outside the Apple universe (I admittedly despise
;))? It's surely much better than their Objective-C crap, but
still...
So for rare use cases like shared_ptr/weak pointer interop, a
library solution (just like they are in C++) is IMO enough.
More information about the Digitalmars-d-learn
mailing list