[PATCH] D144503: [WIP][STLExtras] Allow `llvm::enumerate` to enumerate over multiple ranges

David Blaikie via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 21 14:08:09 PST 2023


dblaikie added a comment.

In D144503#4142807 <https://reviews.llvm.org/D144503#4142807>, @kuhar wrote:

> In D144503#4142656 <https://reviews.llvm.org/D144503#4142656>, @dblaikie wrote:
>
>>> C++17 does not allow for recursive expansion of structured bindings.
>>
>> Could we address this issue more directly, perhaps - like having a "flatten" (maybe it only goes one level deep - a range over pair or tuple and any of the elements of that tuple that are themselves tuples would be flattened into one big tuple (but only that one layer deep - could use the wrapper multiple times if you wanted to flatten even deeper))?
>
> Can you give an example? I don't see how this would work. My starting point is that I would like to enable this: `for (auto [Idx, X, Y, Z] : ...(Xs, Ys, Zs)...)`.
>
> If we tried to compose `enumerate` and `zip_equal`, we would end up with `flatten` used like this: `for (auto [Idx, X, Y, Z] : flatten(enumerate(zip_equal(Xs, Ys, Zs))))`. Here flatten would have to a `map_range`-style range adaptor, and I think we would lose `it.index()`?

Yep, something along those lines - yep, would lose a nice spelling for `index` on the iterator (it'd just be a tuple) - but given structured bindings, do people much want/need that naming anyway?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144503/new/

https://reviews.llvm.org/D144503



More information about the llvm-commits mailing list