Skip to content
Snippets Groups Projects
Verified Commit 3d7f588e authored by Justin Carpentier's avatar Justin Carpentier
Browse files

core: add converter to Python for std::pair

parent a0fa42db
No related branches found
No related tags found
No related merge requests found
Pipeline #34137 passed with warnings
......@@ -54,13 +54,13 @@ struct StdPairConverter {
static void registration() {
boost::python::converter::registry::push_back(
&convertible, &construct,
boost::python::type_id<pair_type>()
&convertible, &construct, boost::python::type_id<pair_type>()
#ifndef BOOST_PYTHON_NO_PY_SIGNATURES
,
,
get_pytype
#endif
);
boost::python::to_python_converter<pair_type, StdPairConverter, true>();
}
};
......
from std_pair import std_pair_to_tuple
from std_pair import std_pair_to_tuple, copy
t = (1, 2.0)
assert std_pair_to_tuple(t) == t
assert copy(t) == t
......@@ -12,6 +12,11 @@ bp::tuple std_pair_to_tuple(const std::pair<T1, T2>& pair) {
return bp::make_tuple(pair.first, pair.second);
}
template <typename T1, typename T2>
std::pair<T1, T2> copy(const std::pair<T1, T2>& pair) {
return pair;
}
BOOST_PYTHON_MODULE(std_pair) {
using namespace eigenpy;
......@@ -21,4 +26,5 @@ BOOST_PYTHON_MODULE(std_pair) {
StdPairConverter<PairType>::registration();
bp::def("std_pair_to_tuple", std_pair_to_tuple<int, double>);
bp::def("copy", copy<int, double>);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment