Skip to content

ENH: Makeiterator_policies::sequence_fast_readonly satisfy ranges concept. #4127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Skylion007 opened this issue Aug 9, 2022 Discussed in #3850 · 1 comment
Closed

ENH: Makeiterator_policies::sequence_fast_readonly satisfy ranges concept. #4127

Skylion007 opened this issue Aug 9, 2022 Discussed in #3850 · 1 comment

Comments

@Skylion007
Copy link
Collaborator

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?

@Skylion007
Copy link
Collaborator Author

Actually, turns it out this is no longer an issue as per this standard update: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2325r3.html. The standard has been updated so ranges no longer need to be default_initializable at all at all.

@zwhfly just update the compiler and it should work without any changes to pybind11 from my understanding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant