Replies: 1 comment 1 reply
-
Just following up to see if there is any interest in this idea. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I wanted to inquire as to whether there would be interest in adding a
make_iterator_range
utility function similar tomake_iterator
except thatmake_iterator_range
would operate on ranges instead of iterators. The idea is to be able to return ranges local to a function w/out requiring a caster definition or a copy into a Python sequence.make_iterator_range
enables code like this (pardon the pseudo-code).Accomplishing the same thing w/
make_iterator
is more difficult b/c the iterator for atransform_view
is invalid after the lifetime of thetransform_view
ends. For example, this will not work.The
make_iterator_range
utility I'm proposing would not suffer this issue because it would store the range internally in its private state, and the__iter__
function would be implemented with akeep_alive<0,1>()
in order to keep the underlying range alive as long as necessary. In addition, the binding returned bymake_iterator_range
would provide different methods depending on whether the underlying range is an input range, a forward range, etc.I also wanted to know if pybind11 code is allowed to make use of feature macros in order to make some functionality conditionally available. For the current proposal,
make_iterator_range
would require a C++20 compiler w/__cpp_lib_ranges
defined.If this is something the project would be interested in, please let me know and I will prepare a PR.
Beta Was this translation helpful? Give feedback.
All reactions