[PATCH] D146231: [ADT] Add `llvm::range_size` function for generic ranges

Jakub Kuderski via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 16 09:13:46 PDT 2023


kuhar created this revision.
kuhar added reviewers: dblaikie, kazu, zero9178, MaskRay, nikic.
Herald added subscribers: hanchung, StephenFan.
Herald added a project: All.
kuhar requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This function follows `std::ranges::size` from C++20. It is intended
mainly for generic code that does not know the exact range type.
I did not modify the existing `llvm::size` function because it has a strict
guarantee of O(1) running time, and we cannot guarantee that when we delegate
size check to user-defined size functions.

Use `range_size` to optimize size checks in `zip`* and `enumerate`
functions. Before that, we would have to perform linear scans for ranges
without random access iterators.

This is the last change I have planned in the series that overhauls
`zip`* and `enumerate`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146231

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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146231.505835.patch
Type: text/x-patch
Size: 5925 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230316/a0ba3de2/attachment.bin>


More information about the llvm-commits mailing list