Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2002-11-17 08:59:07

"Peter Dimov" <pdimov_at_[hidden]> writes:

> From: "David Abrahams" <dave_at_[hidden]>
>> In Boost.Python, I am going to start using custom deleters to enable
>> me to produce shared_ptr<T> from any Python object which contains a T,
>> while keeping the Python object alive. I can't believe I didn't think
>> of this earlier, and I want to thank Peter Dimov for putting me onto
>> the idea.
>> Each such shared_ptr<T> contains a pointer to the owning Python
>> object, whose identity is associated with that of the T object it
>> contains. When these shared_ptrs are converted back to Python, I
>> currently have to build a new Python object around a copy of the
>> shared_ptr<T>, so that now there are two Python objects using the same
>> C++ object's "guts". It would be very useful if I could introspect
>> about the deleter, and find out that it was using my custom deleter,
>> extract the Python object pointer, and simply return that instead of
>> building a new Python object.
>> Looking at the code, I can see a few ways to hack that functionality
>> in, but I wonder if we should think about making it part of the public
>> interface? After all, the deleter is part of the public interface for
>> shared_ptr creation...
> shared_ptr introspection is something that I've been considering lately. In
> particular:
> void const * shared_ptr::get_original_pointer() const;
> std::type_info const & shared_ptr::get_element_type_info() const;
> I haven't encountered a need to inspect the deleter yet... what interface
> are you suggesting?

How about:

    // attempt to extract a deleter of type D
    D* d = boost::get_deleter<D>(p);
    if (d)
        // that was the deleter type used.


                       David Abrahams
   dave_at_[hidden] *
Boost support, enhancements, training, and commercial distribution

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