Add llvm::enumerate() to stl extras

Zachary Turner via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 29 11:23:13 PDT 2016


I frequently find myself resorting to index based enumeration because
ranged based fors do not allow you to access the index.  With
llvm::enumerate(), you can write something like this:

for (auto X : enumerate(my_container)) {
  if (X.Index == 1)
    continue;
  printf("%d", X.Value);
}

It handles both const and non-const containers, so that for non-const
containers you can modify the underlying sequence item (e.g. the `Value`
member of the returned enumerator is a reference).

Phab is down for now so I'm using a regular email, but if this is too
inconvenient i can wait for Phab to come back up and resubmit.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160929/b714b950/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Add-llvm-enumerate-to-STLExtras.patch
Type: application/octet-stream
Size: 27548 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160929/b714b950/attachment.obj>


More information about the llvm-commits mailing list