From bb6e6a15f1f1a061f4b59c3eddd3430d57681c6d Mon Sep 17 00:00:00 2001 From: David Shah Date: Fri, 24 Jul 2020 16:27:47 +0100 Subject: pycontainers: Fix kv-pair-iter type Signed-off-by: David Shah --- common/pycontainers.h | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/common/pycontainers.h b/common/pycontainers.h index 0a5092a3..d0d7d92a 100644 --- a/common/pycontainers.h +++ b/common/pycontainers.h @@ -70,6 +70,16 @@ template struct iter_pair { + iter_pair() {}; + iter_pair(const Ta &first, const Tb &second) : first(first), second(second) {}; + Ta first; + Tb second; +}; + /* A wrapper for a nextpnr Range. Ranges should have two functions, begin() and end() which return iterator-like objects supporting ++, * and != @@ -184,7 +194,7 @@ template struct pair_wrapper struct pair_iterator_wrapper { - static py::object next(std::pair &iter) + static py::object next(iter_pair &iter) { if (iter.second == 0) { iter.second++; @@ -200,7 +210,7 @@ template struct pair_wrapper static void wrap(py::module &m, const char *python_name) { - py::class_>(m, python_name).def("__next__", next); + py::class_>(m, python_name).def("__next__", next); } }; @@ -223,7 +233,7 @@ template struct pair_wrapper static int len(T &x) { return 2; } - static std::pair iter(T &x) { return std::make_pair(boost::ref(x), 0); }; + static iter_pair iter(T &x) { return iter_pair(boost::ref(x), 0); }; static void wrap(py::module &m, const char *pair_name, const char *iter_name) { @@ -249,7 +259,7 @@ template struct map_pair_wrapper struct pair_iterator_wrapper { - static py::object next(std::pair &&iter) + static py::object next(iter_pair &iter) { if (iter.second == 0) { iter.second++; @@ -266,7 +276,7 @@ template struct map_pair_wrapper static void wrap(py::module &m, const char *python_name) { - py::class_>(m, python_name).def("__next__", next); + py::class_>(m, python_name).def("__next__", next); } }; @@ -281,7 +291,7 @@ template struct map_pair_wrapper static int len(wrapped_pair &x) { return 2; } - static std::pair iter(wrapped_pair &x) { return std::make_pair(boost::ref(x), 0); }; + static iter_pair iter(wrapped_pair &x) { return iter_pair(boost::ref(x), 0); }; static std::string first_getter(wrapped_pair &t) { @@ -372,7 +382,7 @@ template struct map_pair_wrapper_uptr struct pair_iterator_wrapper { - static py::object next(std::pair &&iter) + static py::object next(iter_pair &iter) { if (iter.second == 0) { iter.second++; @@ -389,7 +399,7 @@ template struct map_pair_wrapper_uptr static void wrap(py::module &m, const char *python_name) { - py::class_>(m, python_name).def("__next__", next); + py::class_>(m, python_name).def("__next__", next); } }; @@ -404,7 +414,7 @@ template struct map_pair_wrapper_uptr static int len(wrapped_pair &x) { return 2; } - static std::pair iter(wrapped_pair &x) { return std::make_pair(boost::ref(x), 0); }; + static iter_pair iter(wrapped_pair &x) { return iter_pair(boost::ref(x), 0); }; static std::string first_getter(wrapped_pair &t) { -- cgit v1.2.3