[llvm] [ArrayRef] Add constructor from iterator_range<U*> (NFC). (PR #137796)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 29 09:48:53 PDT 2025


================
@@ -149,6 +149,19 @@ namespace llvm {
                  * = nullptr)
         : Data(Vec.data()), Length(Vec.size()) {}
 
+    /// Construct an ArrayRef<T> from iterator_range<U*>. This uses SFINAE
+    /// to ensure that this is only used for iterator ranges of random access
+    /// iterators that can be converted.
+    template <typename U>
+    ArrayRef(const iterator_range<U *> &Range,
+             std::enable_if_t<std::is_base_of<std::random_access_iterator_tag,
+                                              typename std::iterator_traits<
+                                                  decltype(Range.begin())>::
+                                                  iterator_category>::value &&
+                                  std::is_convertible<U *, T const *>::value,
+                              void> * = nullptr)
+        : Data(Range.begin()), Length(llvm::size(Range)) {}
----------------
fhahn wrote:

Unfortunately there's no `iterator_range::size`, it needs `llvm::` here to not try to use `ArrayRef::size`

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


More information about the llvm-commits mailing list