[llvm] [ADT] Use `adl_being`/`end` in `concat` (PR #130520)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Mar 9 14:41:30 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-adt
Author: Jakub Kuderski (kuhar)
<details>
<summary>Changes</summary>
This is to make sure that ADT helpers consistently use argument dependent lookup when dealing with input ranges.
This was a part of #<!-- -->87936 but reverted due to buildbot failures.
---
Full diff: https://github.com/llvm/llvm-project/pull/130520.diff
2 Files Affected:
- (modified) llvm/include/llvm/ADT/STLExtras.h (+8-9)
- (modified) llvm/unittests/ADT/STLExtrasTest.cpp (+10)
``````````diff
diff --git a/llvm/include/llvm/ADT/STLExtras.h b/llvm/include/llvm/ADT/STLExtras.h
index fe1d010574e31..59becba6373d4 100644
--- a/llvm/include/llvm/ADT/STLExtras.h
+++ b/llvm/include/llvm/ADT/STLExtras.h
@@ -1112,8 +1112,8 @@ class concat_iterator
/// We need the full range to know how to switch between each of the
/// iterators.
template <typename... RangeTs>
- explicit concat_iterator(RangeTs &&... Ranges)
- : Begins(std::begin(Ranges)...), Ends(std::end(Ranges)...) {}
+ explicit concat_iterator(RangeTs &&...Ranges)
+ : Begins(adl_begin(Ranges)...), Ends(adl_end(Ranges)...) {}
using BaseT::operator++;
@@ -1142,13 +1142,12 @@ template <typename ValueT, typename... RangeTs> class concat_range {
public:
using iterator =
concat_iterator<ValueT,
- decltype(std::begin(std::declval<RangeTs &>()))...>;
+ decltype(adl_begin(std::declval<RangeTs &>()))...>;
private:
std::tuple<RangeTs...> Ranges;
- template <size_t... Ns>
- iterator begin_impl(std::index_sequence<Ns...>) {
+ template <size_t... Ns> iterator begin_impl(std::index_sequence<Ns...>) {
return iterator(std::get<Ns>(Ranges)...);
}
template <size_t... Ns>
@@ -1156,12 +1155,12 @@ template <typename ValueT, typename... RangeTs> class concat_range {
return iterator(std::get<Ns>(Ranges)...);
}
template <size_t... Ns> iterator end_impl(std::index_sequence<Ns...>) {
- return iterator(make_range(std::end(std::get<Ns>(Ranges)),
- std::end(std::get<Ns>(Ranges)))...);
+ return iterator(make_range(adl_end(std::get<Ns>(Ranges)),
+ adl_end(std::get<Ns>(Ranges)))...);
}
template <size_t... Ns> iterator end_impl(std::index_sequence<Ns...>) const {
- return iterator(make_range(std::end(std::get<Ns>(Ranges)),
- std::end(std::get<Ns>(Ranges)))...);
+ return iterator(make_range(adl_end(std::get<Ns>(Ranges)),
+ adl_end(std::get<Ns>(Ranges)))...);
}
public:
diff --git a/llvm/unittests/ADT/STLExtrasTest.cpp b/llvm/unittests/ADT/STLExtrasTest.cpp
index e107cb570641b..2b2b4ae9b9e9e 100644
--- a/llvm/unittests/ADT/STLExtrasTest.cpp
+++ b/llvm/unittests/ADT/STLExtrasTest.cpp
@@ -504,6 +504,16 @@ TEST(STLExtrasTest, ConcatRange) {
EXPECT_EQ(Expected, Test);
}
+TEST(STLExtrasTest, ConcatRangeADL) {
+ // Make sure that we use the `begin`/`end` functions from `some_namespace`,
+ // using ADL.
+ some_namespace::some_struct S0;
+ S0.data = {1, 2};
+ some_namespace::some_struct S1;
+ S1.data = {3, 4};
+ EXPECT_THAT(concat<const int>(S0, S1), ElementsAre(1, 2, 3, 4));
+}
+
template <typename T> struct Iterator {
int i = 0;
T operator*() const { return i; }
``````````
</details>
https://github.com/llvm/llvm-project/pull/130520
More information about the llvm-commits
mailing list