Skip to content

Commit 56963cf

Browse files
committed
[unittest] Show problem with returning reference of std::pair
1 parent 694d996 commit 56963cf

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

unittest/python/test_std_pair.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
from std_pair import copy, std_pair_to_tuple
1+
from std_pair import copy, passthrough, std_pair_to_tuple
22

33
t = (1, 2.0)
44
assert std_pair_to_tuple(t) == t
55
assert copy(t) == t
6+
assert passthrough(t) == t

unittest/std_pair.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
#include <eigenpy/eigenpy.hpp>
55
#include <eigenpy/std-pair.hpp>
6-
#include <iostream>
76

87
namespace bp = boost::python;
98

@@ -17,6 +16,11 @@ std::pair<T1, T2> copy(const std::pair<T1, T2>& pair) {
1716
return pair;
1817
}
1918

19+
template <typename T1, typename T2>
20+
const std::pair<T1, T2>& passthrough(const std::pair<T1, T2>& pair) {
21+
return pair;
22+
}
23+
2024
BOOST_PYTHON_MODULE(std_pair) {
2125
eigenpy::enableEigenPy();
2226

@@ -25,4 +29,6 @@ BOOST_PYTHON_MODULE(std_pair) {
2529

2630
bp::def("std_pair_to_tuple", std_pair_to_tuple<int, double>);
2731
bp::def("copy", copy<int, double>);
32+
bp::def("passthrough", passthrough<int, double>,
33+
bp::return_internal_reference<>());
2834
}

0 commit comments

Comments
 (0)