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

Michael Kruse via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 19 22:39:44 PDT 2018


Meinersbur created this revision.
Meinersbur added reviewers: bryant, mehdi_amini, hfinkel, aaron.ballman.

Like the already existing zip_shortest/zip_first iterators, zip_longest iterates over multiple iterators at once, but has as many iterations as the longest sequence.

This means some iterators may reach the end before others do. There are two variants: zip_longest_optional uses `llvm::Optional`'s None value to mark a past-the-end value. zip_longest_default uses the type's default-initialized value for this purpose (which means one cannot distinguish the default value from being in the list and having reached the end). I included both variants in this patch, but we may use only one of the variants.

Neither variant is reverse-iteratable because the tuples iterated over would be different for different length sequences (IMHO for the same reason neither zip_shortest nor zip_first should be reverse-iteratable; one can still reverse the ranges individually if that's the expected behavior).

In contrast to zip_shortest/zip_first, zip_longest tuples contain rvalues instead of references. This is because `llvm::Optional` cannot contain reference types and the value-initialized default does not have a memory location a reference could point to.

The motivation for these iterators is to use C++ foreach to compare two lists of ordered attributes in https://reviews.llvm.org/D48100 (`SemaOverload.cpp` and `ASTReaderDecl.cpp`).

Idea by @hfinkel.


Repository:
  rL LLVM

https://reviews.llvm.org/D48348

Files:
  include/llvm/ADT/STLExtras.h
  unittests/ADT/IteratorTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D48348.152021.patch
Type: text/x-patch
Size: 13531 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180620/96a57138/attachment.bin>


More information about the llvm-commits mailing list