Skip to content

Commit

Permalink
[unittest] Show problem with returning reference of std::pair
Browse files Browse the repository at this point in the history
  • Loading branch information
ManifoldFR committed Sep 18, 2024
1 parent 694d996 commit 56963cf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion unittest/python/test_std_pair.py
Original file line number Diff line number Diff line change
@@ -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
8 changes: 7 additions & 1 deletion unittest/std_pair.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include <eigenpy/eigenpy.hpp>
#include <eigenpy/std-pair.hpp>
#include <iostream>

namespace bp = boost::python;

Expand All @@ -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();

Expand All @@ -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_internal_reference<>());
}

0 comments on commit 56963cf

Please sign in to comment.