This is an archive of the discontinued LLVM Phabricator instance.

[ADT] Add pointer_iterator, the opposite of pointee_iterator
ClosedPublic

Authored by timshen on Aug 18 2016, 10:25 PM.

Diff Detail

Repository
rL LLVM

Event Timeline

timshen updated this revision to Diff 68647.Aug 18 2016, 10:25 PM
timshen retitled this revision from to [ADT] Add pointer_iterator, the opposite of pointee_iterator.
timshen updated this object.
timshen added a reviewer: dblaikie.
timshen added a subscriber: llvm-commits.
dblaikie added inline comments.Aug 19 2016, 10:32 AM
include/llvm/ADT/iterator.h
269 ↗(On Diff #68647)

This would make a non-conforming iterator (perhaps we should have a static_assert for this in iterator_adapter_base, if possible) - because you should be able to take references and pointers to op* and get the same thing back the next time you call op*, etc.

So, at least in theory/to be conforming, the iterator would need a pointer member that it initializes in op* (or op++/ctor) and returns a reference to that.

What do you think? Do we already have enough non-conforming iterators that this technicality isn't worth worrying about? Or is the extra contortion worthwhile? Is there a nice way to do it? (I suppose you have to do it in op*, because you don't know if the iterator is valid any other time so you can't pre-emptively initialize the pointer member)

timshen updated this revision to Diff 68726.Aug 19 2016, 1:39 PM

Locally cache the pointer, so that we can return a reference from operator*().

timshen marked an inline comment as done.Aug 19 2016, 1:39 PM
dblaikie accepted this revision.Aug 19 2016, 2:08 PM
dblaikie edited edge metadata.
This revision is now accepted and ready to land.Aug 19 2016, 2:08 PM
This revision was automatically updated to reflect the committed changes.