Skip to content
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

Consider combining implementations of walk*_vectors_or_scalars with fold instructions #2006

Open
mmichel11 opened this issue Jan 17, 2025 · 0 comments

Comments

@mmichel11
Copy link
Contributor

mmichel11 commented Jan 17, 2025

          I *think* it should be possible to combine `walk*_vectors_or_scalars` together with some complicated fold instructions, lambdas, tuples, and std::apply.  

Take a look at the first answer of https://stackoverflow.com/questions/7230621/how-can-i-iterate-over-a-packed-variadic-template-argument-list. I think you should do something similar, chaining together instructions by returning tuples and then with std::apply.

Here is an example I was playing with.
https://godbolt.org/z/vc8dK4ed6

In the end, I'm not sure if (1) its actually possible and (2) its worth the complexity to consolidate these structs, but its worth considering...

Originally posted by @danhoeflinger in #1976 (comment)

The current implementation of walk*_vectors_or_scalars introduced in #1976 manually implements each path separately. This is due to the difficulty of combining the separate vector paths in a single unified implementation. However, there is a common structure shared among all three functors and @danhoeflinger's recommendation looks implementable.

When exploring combining the implementations, we should consider readability / complexity of the fold instruction approach when determining if we should adopt it. Additionally, the walk1_vector_or_scalar implementation should avoid explicit copying (as currently implemented), so the user's unary functor in std::for_each can still directly modify the reference.

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

No branches or pull requests

1 participant