[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 11:19:43 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<
----------------
fhahn wrote:
> I think we can drop the typename =.
I tried but it complained.
> Probably still worth using std::enable_if_t here, but without explicitly specifying a type parameter (the default is void, so that's fine) - if you are using std::enable_if then I think you have to add the ::type at the end (that's where the SFINAE is - std::enable_if<false> has no nested type member, but std::enable_if<true> does)
thanks, switched back to `std::enable_if_t`. The original checks were more complex and maybe too lax than needed; I think we are only guaranteed to iterate over a continous range, if the iterator is a plain pointer (e.g. `int *` as in the test case or something like `int **`.
The new check just enforces that the iterator is same as `T *`. I think that should be sufficient?
I also added some `static_assert` to check some invalid combinations.
https://github.com/llvm/llvm-project/pull/137796
More information about the llvm-commits
mailing list