0

Duplicate: https://stackoverflow.com/a/61819663/11998382

This should be possible if we know the size of the outer vector at compile time.

You just have to write the c++ variadic-template equivalent of the following python code:

def transpose(rng_of_rng):
    return zip(*rng_of_rng)
Tom Huntington
  • 2,260
  • 10
  • 20

1 Answers1

0
template <std::size_t N, typename T>
auto transpose(std::span<T, N> rng_rng)
{
    return [&] <std::size_t... I>(std::index_sequence<I...>)
    {
        return  ranges::views::zip( rng_rng[I]... );
    }(std::make_integer_sequence<std::size_t, N>{});
}

And here it is in action: https://godbolt.org/z/oPdn89qnT

I found barry's answer really useful when trying to convert a vector into a static-extent span.


On second thought, maybe this idea isn't so great because be get out a range of tuples. I'm only working with N=10, but I doubt it would be good to have really big tuple sizes.

Tom Huntington
  • 2,260
  • 10
  • 20