[PATCH] D131486: [llvm][ADT] Allow using structured bindings with `llvm::enumerate`
Markus Böck via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 9 08:41:51 PDT 2022
zero9178 marked an inline comment as done.
zero9178 added inline comments.
================
Comment at: llvm/unittests/ADT/STLExtrasTest.cpp:142
+
+ for (auto [index, value] :
+ llvm::enumerate(std::vector<char>{'1', '2', '3'})) {
----------------
kuhar wrote:
> I'm surprised this doesn't require `auto&& [index, value]`, but this seems consistent with the existing behavior with `X.value()`
The part before the structured bindings (here the `auto`) surprisingly does not apply to the destructed elements (`index` and `value`) but to the unnamed variable that the range assigns to.
This unnamed variable is essentially equal to what was `X` in the loop above, hence it also works with `auto` without issues.
The types of `index` and `value` are actually derived from the `std::tuple_element` specializations and the return type of `get`.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D131486/new/
https://reviews.llvm.org/D131486
More information about the llvm-commits
mailing list