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

David Blaikie via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 25 18:01:27 PDT 2018


dblaikie added a subscriber: Meinersbur.
dblaikie added a comment.

Nah - I was thinking of something where zip wouldn't need any changes,
potentially. One possibility:

- iterator adapter that takes a (potentially finite) range of T and

produces an infinite range of Optional<T> (with elements beyond the
original range being empty Optionals)

- same as the above, except potentially finite range of T to an

infinite range of T where the elements beyond the original range are
default constructed

- A range truncation helper that just does something like:

iterator_range trunc(R r, size_t t) { return {adl_begin(r),
std::next(adl_end(r), t)}; }

- then you do something like: trunc(zip(inf_opt(https://reviews.llvm.org/diffusion/L/), inf_opt(https://reviews.llvm.org/source/clang-tools-extra/)),

max(size(https://reviews.llvm.org/diffusion/L/), size(https://reviews.llvm.org/source/clang-tools-extra/)))

This allows the use of these infinite/padded ranges in other situations
apart from zipping.

But maybe that's niche enough/not worth generalizing over pre-emptively.
I'm not sure. Just a thought.


Repository:
  rL LLVM

https://reviews.llvm.org/D48348





More information about the llvm-commits mailing list