mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-22 02:33:06 +01:00
[ADT] Move drop_begin from iterator_range.h into STLExtras.
Summary: 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. Reviewers: dblaikie Subscribers: dexonsmith, ributzka, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D70189
This commit is contained in:
parent
3d7a4708cc
commit
2b37eeb76e
@ -198,6 +198,15 @@ constexpr bool empty(const T &RangeOrContainer) {
|
||||
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.
|
||||
|
||||
|
@ -59,11 +59,6 @@ template <typename T> iterator_range<T> make_range(std::pair<T, T> p) {
|
||||
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
|
||||
|
@ -449,17 +449,4 @@ 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
|
||||
|
@ -380,6 +380,19 @@ TEST(STLExtrasTest, EmptyTest) {
|
||||
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};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user