Reference Counting Template

2009-12-13 Thread dsimcha
I'm starting to think it would be both useful and feasible to have a general reference counting template struct in Phobos: struct RefCounted(T, alias onZero) { // Implementation } Basically, you would provide it with a type T that it's supposed to count references to and an

Re: Reference Counting Template

2009-12-13 Thread bearophile
dsimcha: > Reference counting is a pretty useful general technique for managing resources > that can't have cycles and I think it makes sense to have a generic template > for it instead of having people reimplement the same code over and over for > file handles, large arrays of primitives that the

Re: Reference Counting Template

2009-12-13 Thread Lutger
dsimcha wrote: ... > Does this sound worthwhile? Yes, we need this.

Re: Reference Counting Template

2009-12-13 Thread Andrei Alexandrescu
dsimcha wrote: I'm starting to think it would be both useful and feasible to have a general reference counting template struct in Phobos: struct RefCounted(T, alias onZero) { // Implementation } Basically, you would provide it with a type T that it's supposed to count references

Re: Reference Counting Template

2009-12-14 Thread Lutger
What are you planning to with multithreading? With the current type system, is it possible to statically detect inside the template if the refcount is used in shared scenario's, and base the implementation on that information? That would be ideal, if it is indeed possible. std.stdio.File is r

Re: Reference Counting Template

2009-12-14 Thread Denis Koroskin
On Mon, 14 Dec 2009 11:04:15 +0300, Lutger wrote: What are you planning to with multithreading? With the current type system, is it possible to statically detect inside the template if the refcount is used in shared scenario's, and base the implementation on that information? That would b

Re: Reference Counting Template

2009-12-14 Thread dsimcha
== Quote from Lutger (lutger.blijdest...@gmail.com)'s article > What are you planning to with multithreading? > With the current type system, is it possible to statically detect inside the > template if the refcount is used in shared scenario's, and base the > implementation on that information? Th

Re: Reference Counting Template

2009-12-14 Thread LMB
dsimcha Wrote: > I'm starting to think it would be both useful and feasible to have a general > reference counting template struct in Phobos: > [...] > Does this sound > worthwhile? Yes it does :-) I believe this would be great for working with many C-based APIs. I recent

Re: Reference Counting Template

2009-12-14 Thread Lutger
Denis Koroskin wrote: > On Mon, 14 Dec 2009 11:04:15 +0300, Lutger > wrote: > >> What are you planning to with multithreading? >> >> With the current type system, is it possible to statically detect inside >> the >> template if the refcount is used in shared scenario's, and base the >> implement