add some slice helper methods.

llvm-svn: 126878
This commit is contained in:
Chris Lattner 2011-03-02 20:55:51 +00:00
parent 43e587c1f6
commit 836dff0f1c
1 changed files with 13 additions and 2 deletions

View File

@ -96,10 +96,22 @@ namespace llvm {
return Data[Length-1];
}
/// slice(n) - Chop off the first N elements of the array.
ArrayRef<T> slice(unsigned N) {
assert(N <= size() && "Invalid specifier");
return ArrayRef<T>(data()+N, size()-N);
}
/// slice(n, m) - Chop off the first N elements of the array, and keep M
/// elements in the array.
ArrayRef<T> slice(unsigned N, unsigned M) {
assert(N+M <= size() && "Invalid specifier");
return ArrayRef<T>(data()+N, M);
}
/// @}
/// @name Operator Overloads
/// @{
const T &operator[](size_t Index) const {
assert(Index < Length && "Invalid index!");
return Data[Index];
@ -108,7 +120,6 @@ namespace llvm {
/// @}
/// @name Expensive Operations
/// @{
std::vector<T> vec() const {
return std::vector<T>(Data, Data+Length);
}