summaryrefslogtreecommitdiff
path: root/unittests/ADT/IteratorTest.cpp
diff options
context:
space:
mode:
authorMichael Kruse <llvm@meinersbur.de>2018-06-27 19:39:03 +0000
committerMichael Kruse <llvm@meinersbur.de>2018-06-27 19:39:03 +0000
commit857aa39725c787e928a3c3971d1b9f758bd61950 (patch)
tree0264112227fcee193460334682adb35c23528b81 /unittests/ADT/IteratorTest.cpp
parentd7295192d1a84a6110ff4ff5d9adb8451d7af1c8 (diff)
[ADT] drop_begin: use adl_begin/adl_end. NFC.
Summary: The instantiation of the drop_begin function template usually fails because the functions begin() and end() do not exist. Only when using on a container from the std namespace (or `llvm::iterator_range`s of something derived from `std::iterator`), they are matched to std::begin() and std::end() due to Koenig-lookup. Explicitly use llvm::adl_begin and llvm::adl_end to make drop_begin applicable to anything iterable (including C-style arrays). A solution for general `llvm::iterator_range`s was already tried in r244620, but got reverted in r244621 due to MSVC not liking it. Reviewers: dblaikie, grosbach, aaron.ballman, ruiu Reviewed By: dblaikie, aaron.ballman Subscribers: aaron.ballman, llvm-commits Differential Revision: https://reviews.llvm.org/D48598 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@335772 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/ADT/IteratorTest.cpp')
-rw-r--r--unittests/ADT/IteratorTest.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/unittests/ADT/IteratorTest.cpp b/unittests/ADT/IteratorTest.cpp
index 3bcdfa90846..50c3b01bbc7 100644
--- a/unittests/ADT/IteratorTest.cpp
+++ b/unittests/ADT/IteratorTest.cpp
@@ -387,4 +387,17 @@ TEST(RangeTest, Distance) {
EXPECT_EQ(std::distance(v2.begin(), v2.end()), size(v2));
}
+TEST(IteratorRangeTest, DropBegin) {
+ SmallVector<int, 5> vec{0, 1, 2, 3, 4};
+
+ for (int n = 0; n < 5; ++n) {
+ int i = n;
+ for (auto &v : drop_begin(vec, n)) {
+ EXPECT_EQ(v, i);
+ i += 1;
+ }
+ EXPECT_EQ(i, 5);
+ }
+}
+
} // anonymous namespace