[llvm-commits] [llvm] r126878 - /llvm/trunk/include/llvm/ADT/ArrayRef.h
Chris Lattner
sabre at nondot.org
Wed Mar 2 12:55:51 PST 2011
Author: lattner
Date: Wed Mar 2 14:55:51 2011
New Revision: 126878
URL: http://llvm.org/viewvc/llvm-project?rev=126878&view=rev
Log:
add some slice helper methods.
Modified:
llvm/trunk/include/llvm/ADT/ArrayRef.h
Modified: llvm/trunk/include/llvm/ADT/ArrayRef.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/ArrayRef.h?rev=126878&r1=126877&r2=126878&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/ArrayRef.h (original)
+++ llvm/trunk/include/llvm/ADT/ArrayRef.h Wed Mar 2 14:55:51 2011
@@ -96,10 +96,22 @@
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 @@
/// @}
/// @name Expensive Operations
/// @{
-
std::vector<T> vec() const {
return std::vector<T>(Data, Data+Length);
}
More information about the llvm-commits
mailing list