Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2001-08-17 08:10:17

From: "Murray Cumming" <murrayc_at_[hidden]>
> Peter Dimov wrote:
> > The variant in can do
> >
> > shared_ptr<my_type> p(my_alloc(), &my_drop);
> No, I think that's enough because allocation/deallocation is rarely that
> simple.
> For instance, for the freaky Sybase client library that I'm wrapping:
> - The allocation functions don't just return the instance. The instance
> pointer is an input argument and the result is a success/error code.
> - Some allocation functions require extra data/instances, so my smart
> pointer has a non-default constructor that actually allows me to specify
> an *instance* of an allocator. e.g.:

Can't you just wrap the creation function?

int sybase_create_connection(sybase_context * ctx, args);

sybase_context * my_create_connection(args)
   std::auto_ptr<sybase_context> ctx(new sybase_context);
   int err = sybase_create_connection(ctx.get(), args);
   return ctx.release();

It's not as elegant as a dedicated smart handle class, granted. If you
decide to go that route you'll find that detail/shared_count.hpp does most
of the work for you. :-)

Peter Dimov
Multi Media Ltd.

Boost list run by bdawes at, gregod at, cpdaniel at, john at