[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...

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 7 06:25:12 PST 2016


On Mon, Mar 7, 2016 at 12:44 AM, Chandler Carruth via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

> 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.
>

Ah, figured you had a use case so I was just reviewing the mechanics.

I agree with Justin that it'll be more useful when we have some kind of
pairwise join (though in that case we might want an unbounded version of
this - seq<>() that has an end at INT_MAX or whatever and can be paired
with any shorter sequence to add indicies to a range-for iteration), but
chicken-and-egg problem, partly, so I'd be happy to see any of these pieces
go in in pretty much any order myself.


>
> -Chandler
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160307/4dab8360/attachment.html>


More information about the llvm-commits mailing list