From 10a7c3ac834b827b7e0c48a086993ea1469a1883 Mon Sep 17 00:00:00 2001
From: Joris Vaillant <joris.vaillant@inria.fr>
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 f4edf090..cfd2498c 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<TYPE>();
 
diff --git a/include/eigenpy/std_unique_ptr.hpp b/include/eigenpy/std_unique_ptr.hpp
index 4c2185cb..2c1c7bdd 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 <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__
diff --git a/unittest/std_unique_ptr.cpp b/unittest/std_unique_ptr.cpp
index f2419287..bbf8a360 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>("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());
 
-- 
GitLab