Add llvm::enumerate() to stl extras
Krzysztof Parzyszek via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 29 12:27:41 PDT 2016
On 9/29/2016 1:23 PM, Zachary Turner via llvm-commits wrote:
> 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);
> }
>
How about enumerate(range) instead of container?
This way one could write
for (auto X : enumerate(MI.operands())) {
if (interesting(X.Value))
use_op_index(X.Index);
}
-Krzysztof
--
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation
More information about the llvm-commits
mailing list