[PATCH] D48348: [ADT] Add zip_longest iterators.

David Blaikie via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 26 13:57:31 PDT 2018


dblaikie added a comment.

In https://reviews.llvm.org/D48348#1143128, @Meinersbur wrote:

> Getting the size may require iterating the sequence in advance, which I tried to avoid in https://reviews.llvm.org/D48100.


Yeah, it's a tradeoff there, to be sure. Not sure if anyone else has thoughts on the design tradeoffs here - would hope other folks might chime in.

> The current `zip_shortest` also does not require a value-initializable type and returns references to elements in the container, both of which would not be possible.

I believe returning references to elements is necessary to implement the iterator concept, unfortunately. This is usually dealt with in cases where there's no underlying sequence, by having the iterator contain a member of the desired type and returning references to that (with the restriction that references and pointers to that element are invalidated when the iterator is incremented - not sure if that requires downgrading the iterator category because of this, I don't think so though (I don't think the categories enshrine the invalidation semantics)).

I believe this requirement comes from the need for "i->x" to be valid when "(*i).x" is valid, and operator-> returns a pointer, so it has to have some storage to back it.


Repository:
  rL LLVM

https://reviews.llvm.org/D48348





More information about the llvm-commits mailing list