From 30532c677187b3c6e58c6ab73f70af50ee5bea82 Mon Sep 17 00:00:00 2001 From: Joris Vaillant Date: Fri, 2 Feb 2024 10:06:13 +0100 Subject: [PATCH] unique_ptr: Specialize to_python_value to manage unique_ptr in the default_call_policies --- include/eigenpy/eigenpy.hpp | 3 +++ include/eigenpy/std_unique_ptr.hpp | 11 +++++++++++ unittest/std_unique_ptr.cpp | 6 ++---- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/include/eigenpy/eigenpy.hpp b/include/eigenpy/eigenpy.hpp index f4edf090d..cfd2498c2 100644 --- a/include/eigenpy/eigenpy.hpp +++ b/include/eigenpy/eigenpy.hpp @@ -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(); diff --git a/include/eigenpy/std_unique_ptr.hpp b/include/eigenpy/std_unique_ptr.hpp index 4c2185cbc..2c1c7bdd9 100644 --- a/include/eigenpy/std_unique_ptr.hpp +++ b/include/eigenpy/std_unique_ptr.hpp @@ -130,4 +130,15 @@ struct ReturnInternalStdUniquePtr : bp::return_internal_reference<> { } // namespace eigenpy +namespace boost { +namespace python { + +template +struct to_python_value&> + : eigenpy::details::StdUniquePtrResultConverter::apply< + std::unique_ptr >::type {}; + +} // namespace python +} // namespace boost + #endif // ifndef __eigenpy_utils_std_unique_ptr_hpp__ diff --git a/unittest/std_unique_ptr.cpp b/unittest/std_unique_ptr.cpp index f2419287f..bbf8a3605 100644 --- a/unittest/std_unique_ptr.cpp +++ b/unittest/std_unique_ptr.cpp @@ -35,10 +35,8 @@ BOOST_PYTHON_MODULE(std_unique_ptr) { bp::class_("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());