From: Chris Lattner Date: Wed, 2 Mar 2011 20:55:51 +0000 (+0000) Subject: add some slice helper methods. X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=fa09685a9aa17dbdd4c72ad032684debb25feb0b;p=oota-llvm.git add some slice helper methods. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@126878 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/ADT/ArrayRef.h b/include/llvm/ADT/ArrayRef.h index 711470bf56a..ebddb1287eb 100644 --- a/include/llvm/ADT/ArrayRef.h +++ b/include/llvm/ADT/ArrayRef.h @@ -96,10 +96,22 @@ namespace llvm { return Data[Length-1]; } + /// slice(n) - Chop off the first N elements of the array. + ArrayRef slice(unsigned N) { + assert(N <= size() && "Invalid specifier"); + return ArrayRef(data()+N, size()-N); + } + + /// slice(n, m) - Chop off the first N elements of the array, and keep M + /// elements in the array. + ArrayRef slice(unsigned N, unsigned M) { + assert(N+M <= size() && "Invalid specifier"); + return ArrayRef(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 vec() const { return std::vector(Data, Data+Length); }