Workaround for RefCounted with classes would work?
cym13 via Digitalmars-d
digitalmars-d at puremagic.com
Sun Jun 19 12:48:23 PDT 2016
On Sunday, 19 June 2016 at 19:39:05 UTC, Bienlein wrote:
> Hello,
>
> RefCounted so far works well with structs, but not with classes
> (see http://wiki.dlang.org/DIP74). I have now set up a little
> kludge where a struct takes a class as a template parameter.
> The struct with the containing object, which is of the type of
> the struct's template type, is handed over to the RefCounted
> instance. When RefCounted calls the destructor of the contained
> struct, the destructor of the object contained by the struct is
> also called.
>
> I have tried this out and it works fine. It seems to be good
> enough for my purposes. Question is whether there is some
> hidden problem with this approach. Anything I need to be aware
> of? I'm not proficient with D. So I thought it's better to ask
> ;-).
>
> Regards, Bienlein
The idea of encapsulating a class in a struct is known, good, and
it's all already in the standard library : have a look at
std.typecons.scoped.
More information about the Digitalmars-d
mailing list