Skip to content

Commit

Permalink
unique_ptr: Specialize to_python_value to manage unique_ptr in the de…
Browse files Browse the repository at this point in the history
…fault_call_policies
  • Loading branch information
jorisv committed Feb 2, 2024
1 parent 673c80c commit 30532c6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
3 changes: 3 additions & 0 deletions include/eigenpy/eigenpy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#include "eigenpy/eigen-typedef.hpp"
#include "eigenpy/expose.hpp"

/// Custom CallPolicies
#include "eigenpy/std_unique_ptr.hpp"

#define ENABLE_SPECIFIC_MATRIX_TYPE(TYPE) \
::eigenpy::enableEigenPySpecific<TYPE>();

Expand Down
11 changes: 11 additions & 0 deletions include/eigenpy/std_unique_ptr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,15 @@ struct ReturnInternalStdUniquePtr : bp::return_internal_reference<> {

} // namespace eigenpy

namespace boost {
namespace python {

template <typename T>
struct to_python_value<const std::unique_ptr<T>&>
: eigenpy::details::StdUniquePtrResultConverter::apply<
std::unique_ptr<T> >::type {};

} // namespace python
} // namespace boost

#endif // ifndef __eigenpy_utils_std_unique_ptr_hpp__
6 changes: 2 additions & 4 deletions unittest/std_unique_ptr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@ BOOST_PYTHON_MODULE(std_unique_ptr) {

bp::class_<V1>("V1", bp::init<>()).def_readwrite("v", &V1::v);

bp::def("make_unique_int", make_unique_int,
eigenpy::StdUniquePtrCallPolicies());
bp::def("make_unique_v1", make_unique_v1,
eigenpy::StdUniquePtrCallPolicies());
bp::def("make_unique_int", make_unique_int);
bp::def("make_unique_v1", make_unique_v1);
bp::def("make_unique_null", make_unique_null,
eigenpy::StdUniquePtrCallPolicies());

Expand Down

0 comments on commit 30532c6

Please sign in to comment.