Boost logo

Boost :

Subject: Re: [boost] Is there a way to specialize how a smart_ptr<T> releases the T?
From: TONGARI (tongari95_at_[hidden])
Date: 2012-10-23 22:16:24


2012/10/24 David Hagood <david.hagood_at_[hidden]>

> I am trying to wrapper around a C library (specifically, libxml2) so that
> I can use it within a C++ program. (yes, I am aware of libxml++ - but it
> doesn't play nice with libxslt).
>
> If the core libxml2 objects were internally reference counted, I could use
> an intrusive_ptr, and have the friend intrusive_ptr_release call libxml2's
> release function, and all would be well - but unfortunately libxml2 does
> not internally reference count the objects (at least, not in a way I have
> seen).
>
> If there were a way to specialize smart_ptr<T> such that instead of the
> destructor calling delete(), it called what I wanted, I'd be set, but I see
> no way to easily specialize smart_ptr<xmlDoc> in that way - or am I missing
> something?
>

Just provide it with your custom Deleter in the ctor.

template<class Y, class D> shared_ptr(Y * p, D d);


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk