diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2011-05-02 19:34:44 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2011-05-02 19:34:44 +0000 |
commit | 6b943ff3a3f8617113ecbf611cf0f8957e4e19d2 (patch) | |
tree | fc5f365fb9035b2d0c622bbf06c9bbe8627d7279 /include/llvm/ADT/ArrayRef.h | |
parent | d0e4e96dc17a6c1c6de3340842c80f0e187ba349 (diff) |
Notes
Diffstat (limited to 'include/llvm/ADT/ArrayRef.h')
-rw-r--r-- | include/llvm/ADT/ArrayRef.h | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/include/llvm/ADT/ArrayRef.h b/include/llvm/ADT/ArrayRef.h index d3ea9c0f03b7..97e42cb26602 100644 --- a/include/llvm/ADT/ArrayRef.h +++ b/include/llvm/ADT/ArrayRef.h @@ -22,8 +22,8 @@ namespace llvm { /// /// This class does not own the underlying data, it is expected to be used in /// situations where the data resides in some other buffer, whose lifetime - /// extends past that of the StringRef. For this reason, it is not in general - /// safe to store a ArrayRef. + /// extends past that of the ArrayRef. For this reason, it is not in general + /// safe to store an ArrayRef. /// /// This is intended to be trivially copyable, so it should be passed by /// value. @@ -79,6 +79,8 @@ namespace llvm { /// empty - Check if the array is empty. bool empty() const { return Length == 0; } + const T *data() const { return Data; } + /// size - Get the array size. size_t size() const { return Length; } @@ -94,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]; @@ -106,7 +120,6 @@ namespace llvm { /// @} /// @name Expensive Operations /// @{ - std::vector<T> vec() const { return std::vector<T>(Data, Data+Length); } |