Skip to content

Commit 09c3a46

Browse files
committed
[unittest] Test returning reference of std::pair
1 parent 694d996 commit 09c3a46

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
88

99
### Added
1010

11+
- Add test returning reference of std::pair ([#503](https://github.com/stack-of-tasks/eigenpy/pull/503))
1112
- 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))
1213
- 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))
1314
- Add type_info helpers ([#502](https://github.com/stack-of-tasks/eigenpy/pull/502))

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_value_policy<bp::reference_existing_object>());
2834
}

0 commit comments

Comments
 (0)