Boost logo

Boost Users :

Subject: Re: [Boost-users] make_shared and custom deleter
From: Frank Mori Hess (frank.hess_at_[hidden])
Date: 2009-05-28 10:48:22

Hash: SHA1

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 destructora 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:

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.
Version: GnuPG v1.4.9 (GNU/Linux)


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at