[llvm-commits] PATCH: Add an indexed iterator utility to the ADT library, and expose it for SmallVector

Chandler Carruth chandlerc at gmail.com
Fri Aug 3 13:11:27 PDT 2012


On Fri, Aug 3, 2012 at 11:33 AM, Chris Lattner <clattner at apple.com> wrote:

>
> On Aug 3, 2012, at 2:46 AM, Chandler Carruth <chandlerc at gmail.com> wrote:
>
> > Hello!
> >
> > This adds a handy little iterator wrapper I ended up wanting when
> writing several algorithms that build up and transform data stored in a
> SmallVector (or any vector-like container). I'm still writing a basic test
> of the functionality, but wanted to get any feedback on the idea and rough
> patch.
> >
> > More details about the semantics and use case are in the comments in the
> patch.
>
> I don't really see what this is doing, can you give an example use-case?
>

Yea, I'll try to distill my real world code that is using this into a test
case for the iterator itself and post an updated patch.

The gist of it is this:

Imagine you have a sorted vector, and are processing each element. One step
of the processing has the option of producing new values that should be
inserted into the vector. Because they are already processed, they don't
need to be visited again, and so you simple push_back everything new, and
sort the vector again at the end.

Each push_back invalidates all of the vector iterators, and so now all of
the code involved in "processing" the elements has to be written in terms
of indexes instead of iterators. =/ This iterator wrapper allows you to use
slightly heavier weight iterators (the same weight as an index), and get
all of the stability of an index -- push_back doesn't invalidate or change
any of the iterators valid before the push_back occurs.

Anyways, not sure if English is the right way to explain this. ;] An
updated patch when I can swap this change back in...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20120803/2312c02a/attachment.html>


More information about the llvm-commits mailing list