Add llvm::enumerate() to stl extras

Adrian McCarthy via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 29 13:33:13 PDT 2016


I'm looking at http://en.cppreference.com/w/cpp/language/range-for, which
suggests that the range-based for is going to call begin and end on your
range to get the iterators, and then use operator!= and operator++ (prefix)
on the iterators.

Since you're testing only with range-based for loops, perhaps the
unnecessary bits should be cut (like operator== and operator++(int)
(postfix)).  Either that or test those explicitly.

On Thu, Sep 29, 2016 at 1:11 PM, Zachary Turner <zturner at google.com> wrote:

> I don't think so, but someone correct me if I'm wrong.  enumerator works
> with ranges, not iterators.  So by extension enumerate should also be
> considered to return a range, and not an iterator.  The baggage associated
> with ranges are much less than that associated with iterators.  As long as
> you have a begin and an end you're good to go.
>
> But then again who knows, someone with more knowledge than me will have to
> chime in :)
>
> On Thu, Sep 29, 2016 at 1:06 PM Adrian McCarthy <amccarth at google.com>
> wrote:
>
>> Should `enumerator_impl::iterator` have the extra baggage for
>> `std::iterator_traits`, like typedefs for `value_type`,
>> `iterator_category`, and such?
>>
>> On the other hand, if this is strictly for range-based for loops, then
>> perhaps you don't even need the post-fix increment.
>>
>>
>> On Thu, Sep 29, 2016 at 12:34 PM, Zachary Turner via llvm-commits <
>> llvm-commits at lists.llvm.org> wrote:
>>
>> Yes, you beat me to it.  I just used container in my example, but the
>> implementation is supposed to work with any range
>>
>> On Thu, Sep 29, 2016 at 12:33 PM Krzysztof Parzyszek via llvm-commits <
>> llvm-commits at lists.llvm.org> wrote:
>>
>> On 9/29/2016 2:27 PM, Krzysztof Parzyszek via llvm-commits wrote:
>> >
>> > How about enumerate(range) instead of container?
>>
>> Nevermind.  It's the same thing.
>>
>> --
>> Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
>> hosted by The Linux Foundation
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>>
>>
>> _______________________________________________
>> 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/20160929/e26a4722/attachment.html>


More information about the llvm-commits mailing list