[PATCH] D70189: [ADT] Move drop_begin from iterator_range.h into STLExtras.
Lang Hames via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 13 09:23:15 PST 2019
lhames created this revision.
lhames added a reviewer: dblaikie.
Herald added subscribers: ributzka, dexonsmith.
Herald added a project: LLVM.
drop_begin depends on adl_begin/adl_end, which are defined in STLExtras.h,
but we can't just #include STLExtras.h in iterator_range.h as that would
introduce a circular reference (STLExtras.h already depends on
iterator_range.h). The simplest solution is to move drop_begin into
STLExtras.h, which is a reasonable home for it anyway.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D70189
Files:
llvm/include/llvm/ADT/STLExtras.h
llvm/include/llvm/ADT/iterator_range.h
llvm/unittests/ADT/IteratorTest.cpp
llvm/unittests/ADT/STLExtrasTest.cpp
Index: llvm/unittests/ADT/STLExtrasTest.cpp
===================================================================
--- llvm/unittests/ADT/STLExtrasTest.cpp
+++ llvm/unittests/ADT/STLExtrasTest.cpp
@@ -380,6 +380,19 @@
EXPECT_FALSE(llvm::empty(R1));
}
+TEST(STLExtrasTest, DropBeginTest) {
+ 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);
+ }
+}
+
TEST(STLExtrasTest, EarlyIncrementTest) {
std::list<int> L = {1, 2, 3, 4};
Index: llvm/unittests/ADT/IteratorTest.cpp
===================================================================
--- llvm/unittests/ADT/IteratorTest.cpp
+++ llvm/unittests/ADT/IteratorTest.cpp
@@ -449,17 +449,4 @@
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
Index: llvm/include/llvm/ADT/iterator_range.h
===================================================================
--- llvm/include/llvm/ADT/iterator_range.h
+++ llvm/include/llvm/ADT/iterator_range.h
@@ -59,11 +59,6 @@
return iterator_range<T>(std::move(p.first), std::move(p.second));
}
-template <typename T>
-iterator_range<decltype(adl_begin(std::declval<T>()))> drop_begin(T &&t,
- int n) {
- return make_range(std::next(adl_begin(t), n), adl_end(t));
-}
}
#endif
Index: llvm/include/llvm/ADT/STLExtras.h
===================================================================
--- llvm/include/llvm/ADT/STLExtras.h
+++ llvm/include/llvm/ADT/STLExtras.h
@@ -198,6 +198,15 @@
return adl_begin(RangeOrContainer) == adl_end(RangeOrContainer);
}
+/// Return a range covering \p RangeOrContainer with the first N elements
+/// excluded.
+template <typename T>
+auto drop_begin(T &&RangeOrContainer, size_t N) ->
+ iterator_range<decltype(adl_begin(RangeOrContainer))> {
+ return make_range(std::next(adl_begin(RangeOrContainer), N),
+ adl_end(RangeOrContainer));
+}
+
// mapped_iterator - This is a simple iterator adapter that causes a function to
// be applied whenever operator* is invoked on the iterator.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70189.229120.patch
Type: text/x-patch
Size: 2457 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191113/dbe9b0e4/attachment.bin>
More information about the llvm-commits
mailing list