MCPcopy Create free account
hub / github.com/pybind/pybind11 / PySequenceIterator

Class PySequenceIterator

tests/test_sequences_and_iterators.cpp:505–517  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

503 // are not covered by the much simpler py::make_iterator
504
505 struct PySequenceIterator {
506 PySequenceIterator(const Sequence &seq, py::object ref) : seq(seq), ref(ref) { }
507
508 float next() {
509 if (index == seq.size())
510 throw py::stop_iteration();
511 return seq[index++];
512 }
513
514 const Sequence &seq;
515 py::object ref; // keep a reference
516 size_t index = 0;
517 };
518
519 py::class_<PySequenceIterator>(seq, "Iterator")
520 .def("__iter__", [](PySequenceIterator &it) -> PySequenceIterator& { return it; })

Callers 1

TEST_SUBMODULEFunction · 0.85

Calls

no outgoing calls

Tested by 1

TEST_SUBMODULEFunction · 0.68