[shared_ptr] utility for shared-only classes

I find myself often writing some boilerplate stuff to make a class usable and creatable only with shared_ptr's. For example, stuff of the form: struct A : private boost::noncopyable { static boost::shared_ptr<A> create(int); // ... private: explicit A(int); }; Anyway, I made a little utility to simplify this, which looks like: struct A : private boost::noncopyable { // ... private: friend class shared_new_access; explicit A(int); ~A(); // only shared_new_access can delete us, also }; And then later: boost::shared_ptr<A> pa = shared_new<A>(some_int); The shared_new function template also works generally as a way to create new shared_ptr's, since shared_new_access will still have access to public constructors and destructors also. It also has the same forwarding problem thing that people have run into when making auto_ptr_new() or other such utilities. So anyway: is there any interest in this for boost? It is pretty small and straight-forward, but I can post an implementation of it to the vault (or to this list, if that is preferred for something this small), if there is some interest. -- Jordan DeLong fracture@allusion.net

Hello Jordan, Jordan DeLong wrote:
I find myself often writing some boilerplate stuff to make a class usable and creatable only with shared_ptr's. [snip] So anyway: is there any interest in this for boost? It is pretty small and straight-forward, but I can post an implementation of it to the vault (or to this list, if that is preferred for something this small), if there is some interest.
I'm definitely interested. We use shared_ptr a lot at work and have a lot of boiler-plate code like the one you posted. I find having a 'standard' implementation for this pattern desirable and would appreciate it if you could upload your implementation to the vault. Best Regards, Martin

On Sun, Feb 19, 2006 at 09:04:56AM +0100, martin.ecker@tab.at wrote: [...]
I'm definitely interested. We use shared_ptr a lot at work and have a lot of boiler-plate code like the one you posted. I find having a 'standard' implementation for this pattern desirable and would appreciate it if you could upload your implementation to the vault.
Just uploaded it in the "Memory" directory as `shared_new.zip'. -- Jordan DeLong fracture@allusion.net
participants (2)
-
Jordan DeLong
-
martin.ecker@tab.at