From 468409565bfa4d076772f8674a39325375499bf9 Mon Sep 17 00:00:00 2001
From: ManifoldFR <wilson.jallet@polytechnique.org>
Date: Tue, 17 Sep 2024 17:23:50 +0200
Subject: [PATCH] [unittest] Test returning reference of std::pair

---
 CHANGELOG.md                     | 1 +
 unittest/python/test_std_pair.py | 3 ++-
 unittest/std_pair.cpp            | 8 +++++++-
 3 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 14daba35..4f435697 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
 
 ### Added
 
+- Add test returning reference of std::pair ([#503](https://github.com/stack-of-tasks/eigenpy/pull/503))
 - Add more general visitor `GenericMapPythonVisitor` for map types test `boost::unordered_map<std::string, int>` ([#504](https://github.com/stack-of-tasks/eigenpy/pull/504))
 - Support for non-[default-contructible](https://en.cppreference.com/w/cpp/named_req/DefaultConstructible) types in map types ([#504](https://github.com/stack-of-tasks/eigenpy/pull/504))
 - Add type_info helpers ([#502](https://github.com/stack-of-tasks/eigenpy/pull/502))
diff --git a/unittest/python/test_std_pair.py b/unittest/python/test_std_pair.py
index 4b95e5ef..f1f1b052 100644
--- a/unittest/python/test_std_pair.py
+++ b/unittest/python/test_std_pair.py
@@ -1,5 +1,6 @@
-from std_pair import copy, std_pair_to_tuple
+from std_pair import copy, passthrough, std_pair_to_tuple
 
 t = (1, 2.0)
 assert std_pair_to_tuple(t) == t
 assert copy(t) == t
+assert passthrough(t) == t
diff --git a/unittest/std_pair.cpp b/unittest/std_pair.cpp
index 70771c29..f32ff4ef 100644
--- a/unittest/std_pair.cpp
+++ b/unittest/std_pair.cpp
@@ -3,7 +3,6 @@
 
 #include <eigenpy/eigenpy.hpp>
 #include <eigenpy/std-pair.hpp>
-#include <iostream>
 
 namespace bp = boost::python;
 
@@ -17,6 +16,11 @@ std::pair<T1, T2> copy(const std::pair<T1, T2>& pair) {
   return pair;
 }
 
+template <typename T1, typename T2>
+const std::pair<T1, T2>& passthrough(const std::pair<T1, T2>& pair) {
+  return pair;
+}
+
 BOOST_PYTHON_MODULE(std_pair) {
   eigenpy::enableEigenPy();
 
@@ -25,4 +29,6 @@ BOOST_PYTHON_MODULE(std_pair) {
 
   bp::def("std_pair_to_tuple", std_pair_to_tuple<int, double>);
   bp::def("copy", copy<int, double>);
+  bp::def("passthrough", passthrough<int, double>,
+          bp::return_value_policy<bp::copy_const_reference>());
 }
-- 
GitLab