Boost logo

Boost Users :

Subject: [Boost-users] Boost python, unique_ptr and abstract class
From: Maxim Yegorushkin (maxim.yegorushkin_at_[hidden])
Date: 2012-10-19 12:50:04


I am using boost::python to expose a C++ API into Python. Here is what I
am trying to do:

     #include <boost/python.hpp>
     #include <memory>

     struct Subscriber {
         virtual ~Subscriber() = 0;
         static std::unique_ptr<Subscriber> create();
     };

     template<class T>
     inline T* get_pointer(std::unique_ptr<T> const& p) {
         return p.get();
     }

     BOOST_PYTHON_MODULE(subscriber) {
         // Expose the class.
         boost::python::class_<
               Subscriber
             , std::unique_ptr<Subscriber>
             , boost::noncopyable
>("Subscriber");

         // Expose its factory function.
         bp::def("createSubscriber", Subscriber::create);
     }

boost::python::class_<> constructor invocation spits out errors (full
compiler log attached):

/usr/local/ots/boost-1.51.0/include/boost/python/converter/as_to_python_function.hpp:40:75:
error: use of deleted function ‘std::unique_ptr<_Tp,
_Dp>::unique_ptr(const std::unique_ptr<_Tp, _Dp>&) [with _Tp =
Subscriber; _Dp = std::default_delete<Subscriber>; std::unique_ptr<_Tp,
_Dp> = std::unique_ptr<Subscriber>]’

/usr/local/ots/boost-1.51.0/include/boost/python/object/pointer_holder.hpp:194:14:
error: cannot allocate an object of abstract type ‘Subscriber’

How do I make boost::python friendly to std::unique_ptr<> and how do I
wrap an abstract class please?

-- Maxim




Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net