Skip to content

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

Open
@mmichel11

Description

          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.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions