Skip to content

Commit da5317a

Browse files
committed
[ADT] Use adl_being/end in map_range
This is to make sure that ADT helpers consistently use argument dependent lookup when dealing with input ranges. This was a part of llvm#87936 but reverted due to buildbot failures.
1 parent bd64f31 commit da5317a

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

llvm/include/llvm/ADT/STLExtras.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,7 @@ inline mapped_iterator<ItTy, FuncTy> map_iterator(ItTy I, FuncTy F) {
375375

376376
template <class ContainerTy, class FuncTy>
377377
auto map_range(ContainerTy &&C, FuncTy F) {
378-
return make_range(map_iterator(std::begin(C), F),
379-
map_iterator(std::end(C), F));
378+
return make_range(map_iterator(adl_begin(C), F), map_iterator(adl_end(C), F));
380379
}
381380

382381
/// A base type of mapped iterator, that is useful for building derived

llvm/unittests/ADT/STLExtrasTest.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,18 @@ TEST(STLExtrasTest, DropEndDefaultTest) {
730730
EXPECT_EQ(i, 4);
731731
}
732732

733+
TEST(STLExtrasTest, MapRangeTest) {
734+
SmallVector<int, 5> Vec{0, 1, 2};
735+
EXPECT_THAT(map_range(Vec, [](int V) { return V + 1; }),
736+
ElementsAre(1, 2, 3));
737+
738+
// Make sure that we use the `begin`/`end` functions
739+
// from `some_namespace`, using ADL.
740+
some_namespace::some_struct S;
741+
S.data = {3, 4, 5};
742+
EXPECT_THAT(map_range(S, [](int V) { return V * 2; }), ElementsAre(6, 8, 10));
743+
}
744+
733745
TEST(STLExtrasTest, EarlyIncrementTest) {
734746
std::list<int> L = {1, 2, 3, 4};
735747

0 commit comments

Comments
 (0)