[llvm] [ADT] Use `adl_being`/`end` in `concat` (PR #130520)
Jakub Kuderski via llvm-commits
llvm-commits at lists.llvm.org
Sun Mar 9 14:40:59 PDT 2025
https://github.com/kuhar created https://github.com/llvm/llvm-project/pull/130520
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.
>From 27ddb001b14928854f0a36d3681fd9ad27db1389 Mon Sep 17 00:00:00 2001
From: Jakub Kuderski <jakub at nod-labs.com>
Date: Sun, 9 Mar 2025 17:40:06 -0400
Subject: [PATCH] [ADT] Use `adl_being`/`end` in `concat`
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.
---
llvm/include/llvm/ADT/STLExtras.h | 17 ++++++++---------
llvm/unittests/ADT/STLExtrasTest.cpp | 10 ++++++++++
2 files changed, 18 insertions(+), 9 deletions(-)
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; }
More information about the llvm-commits
mailing list