mirror of
https://github.com/pybind/pybind11.git
synced 2026-04-20 06:49:25 +00:00
Make py::iterator compatible with std algorithms
The added type aliases are required by `std::iterator_traits`. Python iterators satisfy the `InputIterator` concept in C++.
This commit is contained in:
committed by
Wenzel Jakob
parent
f7685826e2
commit
1fac1b9f5f
@@ -290,4 +290,14 @@ test_initializer sequences_and_iterators([](py::module &pm) {
|
||||
}
|
||||
return l;
|
||||
});
|
||||
|
||||
// Make sure that py::iterator works with std algorithms
|
||||
m.def("count_none", [](py::object o) {
|
||||
return std::count_if(o.begin(), o.end(), [](py::handle h) { return h.is_none(); });
|
||||
});
|
||||
|
||||
m.def("find_none", [](py::object o) {
|
||||
auto it = std::find_if(o.begin(), o.end(), [](py::handle h) { return h.is_none(); });
|
||||
return it->is_none();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user