@@ -295,6 +295,8 @@ TEST_SUBMODULE(sequences_and_iterators, m) {
295295 public:
296296 explicit IntPairs (std::vector<std::pair<int , int >> data) : data_(std::move(data)) {}
297297 const std::pair<int , int >* begin () const { return data_.data (); }
298+ // .end() only required for py::make_iterator(self) overload
299+ const std::pair<int , int >* end () const { return data_.data () + data_.size (); }
298300 private:
299301 std::vector<std::pair<int , int >> data_;
300302 };
@@ -306,6 +308,17 @@ TEST_SUBMODULE(sequences_and_iterators, m) {
306308 .def (" nonzero_keys" , [](const IntPairs& s) {
307309 return py::make_key_iterator (NonZeroIterator<std::pair<int , int >>(s.begin ()), NonZeroSentinel ());
308310 }, py::keep_alive<0 , 1 >())
311+ .def (" simple_iterator" , [](IntPairs& self) {
312+ return py::make_iterator (self);
313+ }, py::keep_alive<0 , 1 >())
314+ .def (" simple_keys" , [](IntPairs& self) {
315+ return py::make_key_iterator (self);
316+ }, py::keep_alive<0 , 1 >())
317+
318+ // test iterator with keep_alive (doesn't work so not used at runtime, but tests compile)
319+ .def (" make_iterator_keep_alive" , [](IntPairs& self) {
320+ return py::make_iterator (self, py::keep_alive<0 , 1 >());
321+ }, py::keep_alive<0 , 1 >())
309322 ;
310323
311324
0 commit comments