[C++-sig] boost::python handles boost::shared_ptr specially...
Jim Bosch
talljimbo at gmail.com
Sun Feb 12 19:31:49 CET 2012
On 02/12/2012 01:01 PM, VáclavŠmilauer wrote:
>> Will std::shared_ptr just work also?
> I asked this question some time ago here:
> http://stackoverflow.com/questions/6568952/c0x-stdshared-ptr-vs-boostshared-ptr
>
> To summarize: you need to define free get_pointer<T> functions for T=your
> shared_ptr type and it will work. I eventyallu did not go that way because
> boost::serialization (which I also needed) will not work with std::shared_ptr.
>
This would be a good start; it would make the std::shared_ptr support at
least as good as, say, std::auto_ptr. It wouldn't be quite enough in
some cases, though, because Boost.Python does a lot of special things
for boost::shared_ptr, related to fact that it can have custom deleters.
In particular, if you have a Boost.Python-wrapped C++ object that is
held *by-value* inside a PyObject*, you can actually pass that to a C++
function by boost::shared_ptr, because Boost.Python creates that
shared_ptr on the fly with a custom deleter that holds the PyObject*.
That's should also be possible with std::shared_ptr, and Boost.Python
would need to be told about that too.
Jim
More information about the Cplusplus-sig
mailing list