ADT: Add a drop_back() helper to ArrayRef

The slice(N, M) interface is powerful but not concise when wanting to
drop a few elements off of an ArrayRef, fix this by adding a drop_back
method.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@212370 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
David Majnemer
2014-07-05 06:12:30 +00:00
parent 22b4918557
commit 38dbb0292d
2 changed files with 13 additions and 0 deletions

View File

@@ -29,5 +29,12 @@ TEST(ArrayRefTest, AllocatorCopy) {
EXPECT_NE(Array2.data(), Array2c.data());
}
TEST(ArrayRefTest, DropBack) {
static const int TheNumbers[] = {4, 8, 15, 16, 23, 42};
ArrayRef<int> AR1(TheNumbers);
ArrayRef<int> AR2(TheNumbers, AR1.size() - 1);
EXPECT_TRUE(AR1.drop_back().equals(AR2));
}
} // end anonymous namespace