[PATCH] D17870: [ADT] Add an 'llvm::seq' function which produces an iterator range over a sequence of values. It increments through the values in the half-open range: [Begin, End), producing those values when indirecting the iterator. It should support integers...
Chandler Carruth via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 7 00:44:20 PST 2016
On Sun, Mar 6, 2016 at 11:45 PM Justin Bogner <mail at justinbogner.com> wrote:
> Chandler Carruth via llvm-commits <llvm-commits at lists.llvm.org> writes:
> > This came up in the C++ standards committee meeting, and it seemed like
> > a useful construct that LLVM might want as well, and I wanted to
> > understand how easily we could solve it. I suspect this can be used to
> > write simpler counting loops even in LLVM along the lines of:
> >
> > for (int i : seq(0, v.size())) {
> > ...
> > };
>
> I don't get how this gains us anything. this adds a bunch of code to
> save, well, three characters over a regular loop:
>
> for (int i = 0; i < v.size(); ++i) {
> ...
> }
>
Well it avoids the common mistake made here. ;] The correct comparison
would be:
for (int i = 0, Size = v.size(); i < Size; ++i) {
...
}
Which is a decent bit longer and requires us to come up with a name for
Size. Sometimes, that's really nice, but sometimes its a pain.
I'm still actually torn on whether this is a useful idiom. But others
seemed to think it was in committee, and I was curious what folks in LLVM
land think, so figured I'd write it up and see. So hopefully we'll get a
few more comments before moving forward.
-Chandler
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160307/735fef95/attachment.html>
More information about the llvm-commits
mailing list