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

Ramkumar Ramachandra via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 29 10:19:57 PDT 2025


================
@@ -149,6 +149,20 @@ 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,
+              typename = std::enable_if<
+                  std::is_base_of<
+                      std::random_access_iterator_tag,
+                      typename std::iterator_traits<
+                          decltype(std::declval<const iterator_range<U *> &>()
+                                       .begin())>::iterator_category>::value &&
----------------
artagnon wrote:

So what I meant is that we can factor this typename into a new template parameter, say IT, and then use IT here to keep this template parameter readable?

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


More information about the llvm-commits mailing list