diff --git a/include/libpy/from_object.h b/include/libpy/from_object.h index 34c5e779..c085977f 100644 --- a/include/libpy/from_object.h +++ b/include/libpy/from_object.h @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -356,6 +357,15 @@ struct from_object> { } }; +template +struct from_object> { +public: + static std::pair f(PyObject* tup) { + std::tuple tmp = from_object>(tup); + return std::make_pair(std::get<0>(tmp), std::get<1>(tmp)); + } +}; + template struct from_object> { static std::optional f(PyObject* maybe_value) { diff --git a/include/libpy/to_object.h b/include/libpy/to_object.h index e7cac1bc..3414b747 100644 --- a/include/libpy/to_object.h +++ b/include/libpy/to_object.h @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -296,6 +297,16 @@ struct to_object> { } }; +template +struct to_object> { +public: + static PyObject* f(const std::pair& p) { + // Delegate to std::tuple dispatch. + return std::move(py::to_object(std::make_tuple(std::get<0>(p), std::get<1>(p)))) + .escape(); + } +}; + template struct to_object> { static PyObject* f(const std::optional& maybe_value) {