diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index 8fcdc493b..c34c1ed6d 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -1117,8 +1117,10 @@ PYBIND11_NOINLINE inline void keep_alive_impl(int Nurse, int Patient, handle arg keep_alive_impl(nurse, patient); } -template struct iterator_state { - Iterator it, end; +template +struct iterator_state { + Iterator it; + Sentinel end; bool first; }; @@ -1127,10 +1129,11 @@ NAMESPACE_END(detail) template detail::init init() { return detail::init(); } template ()), typename... Extra> -iterator make_iterator(Iterator first, Iterator last, Extra &&... extra) { - typedef detail::iterator_state state; +iterator make_iterator(Iterator first, Sentinel last, Extra &&... extra) { + typedef detail::iterator_state state; if (!detail::get_type_info(typeid(state))) { class_(handle(), "") @@ -1149,10 +1152,11 @@ iterator make_iterator(Iterator first, Iterator last, Extra &&... extra) { return (iterator) cast(state { first, last, true }); } template ()).first), typename... Extra> -iterator make_key_iterator(Iterator first, Iterator last, Extra &&... extra) { - typedef detail::iterator_state state; +iterator make_key_iterator(Iterator first, Sentinel last, Extra &&... extra) { + typedef detail::iterator_state state; if (!detail::get_type_info(typeid(state))) { class_(handle(), "") diff --git a/include/pybind11/stl_bind.h b/include/pybind11/stl_bind.h index a67f3ca0e..9434510e0 100644 --- a/include/pybind11/stl_bind.h +++ b/include/pybind11/stl_bind.h @@ -245,7 +245,7 @@ pybind11::class_, holder_type> bind_vector(pybind11::m cl.def("__iter__", [](Vector &v) { - return pybind11::make_iterator(v.begin(), v.end()); + return pybind11::make_iterator(v.begin(), v.end()); }, pybind11::keep_alive<0, 1>() /* Essential: keep list alive while iterator exists */ );