Skip to content

Commit 3d7f588

Browse files
committed
core: add converter to Python for std::pair
1 parent a0fa42d commit 3d7f588

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

include/eigenpy/std-pair.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ struct StdPairConverter {
5454

5555
static void registration() {
5656
boost::python::converter::registry::push_back(
57-
&convertible, &construct,
58-
boost::python::type_id<pair_type>()
57+
&convertible, &construct, boost::python::type_id<pair_type>()
5958
#ifndef BOOST_PYTHON_NO_PY_SIGNATURES
60-
,
59+
,
6160
get_pytype
6261
#endif
6362
);
63+
boost::python::to_python_converter<pair_type, StdPairConverter, true>();
6464
}
6565
};
6666

unittest/python/test_std_pair.py

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

33
t = (1, 2.0)
44
assert std_pair_to_tuple(t) == t
5+
assert copy(t) == t

unittest/std_pair.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ bp::tuple std_pair_to_tuple(const std::pair<T1, T2>& pair) {
1212
return bp::make_tuple(pair.first, pair.second);
1313
}
1414

15+
template <typename T1, typename T2>
16+
std::pair<T1, T2> copy(const std::pair<T1, T2>& pair) {
17+
return pair;
18+
}
19+
1520
BOOST_PYTHON_MODULE(std_pair) {
1621
using namespace eigenpy;
1722

@@ -21,4 +26,5 @@ BOOST_PYTHON_MODULE(std_pair) {
2126
StdPairConverter<PairType>::registration();
2227

2328
bp::def("std_pair_to_tuple", std_pair_to_tuple<int, double>);
29+
bp::def("copy", copy<int, double>);
2430
}

0 commit comments

Comments
 (0)