From a17dfa107bff99a7c51973e854ef51c98baad442 Mon Sep 17 00:00:00 2001 From: Sebastian Junges Date: Thu, 16 Apr 2020 13:23:06 -0700 Subject: [PATCH] iterator over bitvectors added (iterating now mimicks the cpp behavior) --- src/storage/bitvector.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/storage/bitvector.cpp b/src/storage/bitvector.cpp index 7c99036..ef17e6f 100644 --- a/src/storage/bitvector.cpp +++ b/src/storage/bitvector.cpp @@ -30,6 +30,9 @@ void define_bitvector(py::module& m) { }) .def("__setitem__", [](BitVector& b, uint_fast64_t i, bool v) { b.set(i, v); }) + .def("__iter__", [](const BitVector &b) { return py::make_iterator(b.begin(), b.end()); }, + py::keep_alive<0, 1>() /* Essential: keep object alive while iterator exists */) + .def(py::self == py::self) .def(py::self != py::self)