You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[FEA]: Understand if fancy iterator unpacking is a sound default #11916
Is your feature request related to a problem? Please describe.
It's not clear if we can unpack iterators and load efficiently in all cases. For instance, in some algorithms this will lead to loading from one iterator twice. Is this sound?
Describe the solution you'd like
Answering if unpacking is performant or not is outside of the scope for this issue.
This issue can be closed with comment on the issue with a list of iterators for which we can do unpacking automatically without breaking functionality (correctness) and a list of iterators for which we need user to proclaim it's safe to do.
I have been looking into this and I believe that it can be implemented sound but not without nontrivial code changes.
Using a trait that detects whether a type is unwrappable is relatively straightforward to implement in a recursive fashion so that we can easily unwrap nested iterators.
Importantly we can leverage that recursive exploration to also extract the base iterator through the base() const& member method that all our iterators as well as the C++ standard iterators have.
Because we only ever unwrap if the ultimate base iterator is a pointer unwrapping by const& is valid as it ultimately only copies a pointer which is free and has no side effects.
The interesting part is how to "rebase" a pointer onto a new base. This is slightly more complicated and presents some issues that we need to consider.
We cannot simply copy the iterator with the new pointer because the iterator might be nested
We must assure that we do not invalidate other parts of the iterator, e.g copying a an iterator should not be necessary
For now I went with adding a private __rebase(T*) & member function on the fancy iterators. This allows us to recursively call that member until we arrive at a base iterator and simply assign the pointer.
It also allows us to mutate the iterator in place without changing any other part of the iterator. At the same time we can simply just copy + rebase if the algorithm requires that so that is still valid.
The catch are transformations that rely on argument addresses. Those are rare, but we need to consider those
For now this is intended as an opt-in so we can control which iterators we unwrap.
Activity
miscco commentedon Oct 9, 2026
I have been looking into this and I believe that it can be implemented sound but not without nontrivial code changes.
Using a trait that detects whether a type is unwrappable is relatively straightforward to implement in a recursive fashion so that we can easily unwrap nested iterators.
Importantly we can leverage that recursive exploration to also extract the base iterator through the
base() const&member method that all our iterators as well as the C++ standard iterators have.Because we only ever unwrap if the ultimate base iterator is a pointer unwrapping by
const&is valid as it ultimately only copies a pointer which is free and has no side effects.The interesting part is how to "rebase" a pointer onto a new base. This is slightly more complicated and presents some issues that we need to consider.
For now I went with adding a private
__rebase(T*) &member function on the fancy iterators. This allows us to recursively call that member until we arrive at a base iterator and simply assign the pointer.It also allows us to mutate the iterator in place without changing any other part of the iterator. At the same time we can simply just copy + rebase if the algorithm requires that so that is still valid.
The catch are transformations that rely on argument addresses. Those are rare, but we need to consider those
For now this is intended as an opt-in so we can control which iterators we unwrap.