mirror of
https://github.com/RPCS3/llvm.git
synced 2025-01-26 12:46:00 +00:00
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:
parent
22b4918557
commit
38dbb0292d
@ -147,6 +147,12 @@ namespace llvm {
|
||||
return ArrayRef<T>(data()+N, M);
|
||||
}
|
||||
|
||||
// \brief Drop the last \p N elements of the array.
|
||||
ArrayRef<T> drop_back(unsigned N = 1) const {
|
||||
assert(size() >= N && "Dropping more elements than exist");
|
||||
return slice(0, size() - N);
|
||||
}
|
||||
|
||||
/// @}
|
||||
/// @name Operator Overloads
|
||||
/// @{
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user