Skip to content

[ADT] Use adl_being/adl_end in make_early_inc_range #130518

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions llvm/include/llvm/ADT/STLExtras.h
Original file line number Diff line number Diff line change
Expand Up @@ -657,8 +657,8 @@ iterator_range<early_inc_iterator_impl<detail::IterOfRange<RangeT>>>
make_early_inc_range(RangeT &&Range) {
using EarlyIncIteratorT =
early_inc_iterator_impl<detail::IterOfRange<RangeT>>;
return make_range(EarlyIncIteratorT(std::begin(std::forward<RangeT>(Range))),
EarlyIncIteratorT(std::end(std::forward<RangeT>(Range))));
return make_range(EarlyIncIteratorT(adl_begin(Range)),
EarlyIncIteratorT(adl_end(Range)));
}

// Forward declarations required by zip_shortest/zip_equal/zip_first/zip_longest
Expand Down
10 changes: 9 additions & 1 deletion llvm/unittests/ADT/STLExtrasTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ TEST(STLExtrasTest, EarlyIncrementTest) {
#endif

// Inserting shouldn't break anything. We should be able to keep dereferencing
// the currrent iterator and increment. The increment to go to the "next"
// the current iterator and increment. The increment to go to the "next"
// iterator from before we inserted.
L.insert(std::next(L.begin(), 2), -1);
++I;
Expand All @@ -781,6 +781,14 @@ TEST(STLExtrasTest, EarlyIncrementTest) {
EXPECT_EQ(EIR.end(), I);
}

TEST(STLExtrasTest, EarlyIncADLTest) {
// Make sure that we use the `begin`/`end` functions from `some_namespace`,
// using ADL.
some_namespace::some_struct S;
S.data = {1, 2, 3};
EXPECT_THAT(make_early_inc_range(S), ElementsAre(1, 2, 3));
}

// A custom iterator that returns a pointer when dereferenced. This is used to
// test make_early_inc_range with iterators that do not return a reference on
// dereferencing.
Expand Down
Loading