[PATCH] D144834: [ADT] Fix const-correctness issues in `zippy`

Jakub Kuderski via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Feb 26 15:43:32 PST 2023


kuhar created this revision.
kuhar added reviewers: dblaikie, kazu, zero9178, bkramer, mehdi_amini, zturner, antiagainst, beanz.
Herald added a subscriber: hanchung.
Herald added a project: All.
kuhar requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This defines the iterator tuple based on the storage type of `zippy`,
instead of its type arguments. This way, we can support temporaries that
gets passed in and allow for them to be modified during iteration.

Because the iterator types to the tuple storage can have different types
when the storage is and isn't const, this defines a const iterator type
and non-const `begin`/`end` functions. This way we avoid unintentional
casts, e.g., trying to cast `vector<bool>::reference` to
`vector<bool>::const_reference`, which may be unrelated types that are
not convertible.

This patch is a general and free-standing improvement but my primary use
is in the implemention a version of `enumerate` that accepts multiple ranges:
D144583 <https://reviews.llvm.org/D144583>.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144834

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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D144834.500632.patch
Type: text/x-patch
Size: 7418 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230226/3ef33d31/attachment.bin>


More information about the llvm-commits mailing list