Boost Python No to_python for std::unique_ptr

2019-06-05 02:06发布

问题:

I have a problem with boost.python that I can't solve. I tried to expose a class including a function that returns a std::unique_ptr.

The signature looks like: std::unique_ptr<MyClass> myFunc() const;

I exposed the function and got the following error when calling myFunc() in python:

TypeError: No to_python (by-value) converter found for C++ type: std::unique_ptr<MyClass, std::default_delete<MyClass> >

I tried to solve the error by also exposing the pointer with the following code:

class_<std::unique_ptr<MyClass, std::default_delete<MyClass> >, boost::noncopyable ("MyClass", init<>());

Which compiles without any errors, but still produces the same error.

Am I missing something?