From 9b01d56a35924b6bd4d301d798a892e8482f50cf Mon Sep 17 00:00:00 2001 From: ManifoldFR Date: Tue, 17 Sep 2024 17:23:50 +0200 Subject: [PATCH] [unittest] Test returning reference of std::pair --- unittest/python/test_std_pair.py | 3 ++- unittest/std_pair.cpp | 8 +++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/unittest/python/test_std_pair.py b/unittest/python/test_std_pair.py index 4b95e5ef9..f1f1b0524 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 70771c291..f32ff4ef4 100644 --- a/unittest/std_pair.cpp +++ b/unittest/std_pair.cpp @@ -3,7 +3,6 @@ #include #include -#include namespace bp = boost::python; @@ -17,6 +16,11 @@ std::pair copy(const std::pair& pair) { return pair; } +template +const std::pair& passthrough(const std::pair& 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); bp::def("copy", copy); + bp::def("passthrough", passthrough, + bp::return_value_policy()); }