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

Michael Kruse via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 25 17:40:48 PDT 2018


Meinersbur added a comment.

Is the following what you are thinking about?

An `zip_infinite` begin-iterator, that never reaches the end (maybe with two flavors: `zip_infinite_default` and `zip_infinite_optional`) and return a `None`/value-initialized value for any iterator past the list. Then one can use that with an end iterator, such as `end_any` (-> zip_shortest) or `end_all` (-> `zip_longest`).

Unfortunately, in the `zip_infinite_default`-case, we cannot distinguish between the default value end the end of the list. We'd have to look into the iterator's list of iterators, which makes this implementation-specific again.

Alternatively, `zip_infinite` could return tuples of iterators, which `end_any`/`end_all` could compare to the end iterators. However, the current implementation of `zip_shortest` does not need to store the end-iterators for `operator++` (because in contrast to the others, it does not need to check whether one of the sequences is past the the end), making the implementation less efficient than it needs to. (template specialization of `shortest_iterator<zip_infinite<T>>` maybe?)



================
Comment at: include/llvm/ADT/STLExtras.h:757-785
+template <typename... Args> class zip_longest_default_range {
+public:
+  using iterator = zip_longest_default_iterator<decltype(
+      std::begin(std::declval<Args>()))...>;
+  using iterator_category = typename iterator::iterator_category;
+  using value_type = typename iterator::value_type;
+  using difference_type = typename iterator::difference_type;
----------------
The `zip_*_range` classes (including `zippy`) might no be needed: `iterator_range` could be used as well.


Repository:
  rL LLVM

https://reviews.llvm.org/D48348





More information about the llvm-commits mailing list