[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 04:45:31 PDT 2022


zero9178 created this revision.
zero9178 added reviewers: dblaikie, bkramer, MaskRay, kuhar.
Herald added a subscriber: StephenFan.
Herald added a project: All.
zero9178 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This patch adds the ability to deconstruct the `value_type` returned by `llvm::enumarate` into index and value of the wrapping range. Main use case is the common occurence of using it during loop iteration. After this patch it'd then be possible to write code such as:

  for (auto [index, value] : enumerate(container)) {
     ...
  }

where `index` is the current index and `value` a reference to elements in the given container.

-----

The order of index first, before value was mainly chosen to stay consistent with the current documentation of `llvm::enumerate`, but I'd personally be open to (and would have a slight preference of) swapping the order of the two as well.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D131486

Files:
  llvm/include/llvm/ADT/STLExtras.h
  llvm/unittests/ADT/STLExtrasTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D131486.451109.patch
Type: text/x-patch
Size: 3059 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220809/d4e6703d/attachment.bin>


More information about the llvm-commits mailing list