Discussed in #3850
Originally posted by zwhfly April 7, 2022
I found out that pybind11::detail::iterator_policies::sequence_fast_readonly is not default constructible.
This makes the type returned by pybind11::args::begin() not satisfying the std::input_or_output_iterator concept.
I added the default ctor directly in the header file: zwhfly@bfa326a, and made a test.
Given using Iter = decltype(std::declval<pybind11::args>().begin());, this change makes std::constructible_from<Iter> true, which makes std::default_initializable<Iter> true, which makes std::weakly_incrementable<Iter> true, which makes std::input_or_output_iterator<Iter> true, which makes pybind11::args satisfy std::ranges::range concept, which makes the following code work:
void f(pb11::args args)
{
namespace views = std::ranges::views;
auto vu = args | views::transform(
[](pybind11::handle const & h) -> MyClass const & { return h.cast<MyClass const &>(); });
some_library_function(vu.begin(), vu.end());
}
I'm not familiar with the source code of pybind11, so I wonder would this change cause any bad effect that I don't know of?
Could it be added?
Discussed in #3850
Originally posted by zwhfly April 7, 2022
I found out that
pybind11::detail::iterator_policies::sequence_fast_readonlyis not default constructible.This makes the type returned by
pybind11::args::begin()not satisfying thestd::input_or_output_iteratorconcept.I added the default ctor directly in the header file: zwhfly@bfa326a, and made a test.
Given
using Iter = decltype(std::declval<pybind11::args>().begin());, this change makesstd::constructible_from<Iter>true, which makesstd::default_initializable<Iter>true, which makesstd::weakly_incrementable<Iter>true, which makesstd::input_or_output_iterator<Iter>true, which makespybind11::argssatisfystd::ranges::rangeconcept, which makes the following code work:I'm not familiar with the source code of pybind11, so I wonder would this change cause any bad effect that I don't know of?
Could it be added?