Re: Workaround for RefCounted with classes would work?

2016-06-19 Thread cym13 via Digitalmars-d

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.


Workaround for RefCounted with classes would work?

2016-06-19 Thread Bienlein via Digitalmars-d

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