On Thu, May 28, 2009 at 9:48 AM, Frank Mori Hess
On Wednesday 27 May 2009, Dominique Devienne wrote:
I was thinking of using the new make_shared, but I'm already using a custom deleter (shared instances have private destructors and declare the custom deleter as a friend, and new instances are returned wrapped in shared_ptr, thus no explicit new or delete should be possible).
Looking at make_shared, I can't see a way to use both at the same time. Am I out of luck? Thanks, --DD
You can't, not even with boost::allocate_shared since it doesn't use the allocator for in-place construction. See ticket #2481:
https://svn.boost.org/trac/boost/ticket/2481
In theory you should be able to use std::allocate_shared in c++0x mode if your compiler provides it. Define your own allocator (a bit of a pain) and make it a friend of your class. Then add a static factory function to your class with calls allocate_shared with your friend allocator.
I'm not quite following everything but sounds like I can't have it both ways for now. And I can't use C++0x, so I'll forget about make_shared for the moment. Thanks for answering though. --DD