[llvm] [ADT] Make concat able to handle ranges with iterators that return by value (such as zip) (PR #112783)

Jakub Kuderski via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 17 18:07:28 PDT 2024


================
@@ -1065,27 +1075,30 @@ class concat_iterator
   /// Returns null if the specified iterator is at the end. Otherwise,
   /// dereferences the iterator and returns the address of the resulting
   /// reference.
-  template <size_t Index> ValueT *getHelper() const {
+  template <size_t Index> handle_type getHelper() const {
     auto &Begin = std::get<Index>(Begins);
     auto &End = std::get<Index>(Ends);
     if (Begin == End)
-      return nullptr;
+      return {};
----------------
kuhar wrote:

I think we could emit the extra optional by changing this helper a bit, and, e.g., having one helper for begin and one helper for end.

Then the loop that uses would look something like:
```c++
    // Loop over them, and return the first result we find.
    for (auto [GetBeginHelperFn, GetEndHelperFn] : GetHelperFns)
      auto &B = GetBeginHelperFn();
      auto &E = GetEndHelperFn();
      if (B != E)
        ...
```

But now I wrote it doesn't it doesn't seem any cleaner than the optional.

https://github.com/llvm/llvm-project/pull/112783


More information about the llvm-commits mailing list