[llvm-dev] Openness to a "zip_iterator" type?

Keane, Erich via llvm-dev llvm-dev at lists.llvm.org
Wed Dec 14 09:45:21 PST 2016


Inline post, sorry for the formatting, Outlook is terrible for editing mailing lists

-----Original Message-----
From: mehdi.amini at apple.com [mailto:mehdi.amini at apple.com] 
Sent: Wednesday, December 14, 2016 9:41 AM
To: Keane, Erich <erich.keane at intel.com>
Cc: llvm-dev at lists.llvm.org
Subject: Re: [llvm-dev] Openness to a "zip_iterator" type?


> On Dec 14, 2016, at 9:37 AM, Keane, Erich via llvm-dev <llvm-dev at lists.llvm.org> wrote:
> 
> One of my coworkers noticed that we(Clang/LLVM) have quite a few places where we need to iterate through 2 equally sized ranges at the same time, often related to parm/arg relationships.  In a few cases we(Clang/LLVM) use a traditional for-loop with 2 iterators in it.  In a few others, the implementation uses range-for over 1 range with an iterator pattern on the other.
> 
> IMO, the correct solution to this would be a templated 'zip' type (similar, though not identical to http://www.boost.org/doc/libs/1_62_0/libs/iterator/doc/zip_iterator.html) that would permit:
> 
> for (auto&& things : IteratorZip(ParmRange, ArgRange)) { [CurParm, 
> CurArg] = things; // things is a tuple that contains a reference to 
> each value }
> 
> 
> If I were to implement this IteratorZip type for the LLVM codebase, would this be something the community would be interested in/accept/use?  Am I missing an obvious existing implementation somewhere?

Yes: include/llvm/ADT/STLExtras.h has zip.
See also unittests/ADT/IteratorTest.cpp.
[Keane, Erich] Awesome, thank you very much!  I am amazed my search didn't turn this up, but I WAS amazed (apparently incorrectly!) that it was missing.  
Thank you very much!

—
Mehdi



More information about the llvm-dev mailing list