diff options
Diffstat (limited to 'include/llvm/ADT/ArrayRef.h')
-rw-r--r-- | include/llvm/ADT/ArrayRef.h | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/include/llvm/ADT/ArrayRef.h b/include/llvm/ADT/ArrayRef.h index e5562c3..fcf280d 100644 --- a/include/llvm/ADT/ArrayRef.h +++ b/include/llvm/ADT/ArrayRef.h @@ -12,6 +12,7 @@ #include "llvm/ADT/None.h" #include "llvm/ADT/SmallVector.h" +#include "llvm/Support/Allocator.h" #include <vector> namespace llvm { @@ -76,7 +77,7 @@ namespace llvm { /// Construct an ArrayRef from a std::vector. template<typename A> /*implicit*/ ArrayRef(const std::vector<T, A> &Vec) - : Data(Vec.empty() ? (T*)0 : &Vec[0]), Length(Vec.size()) {} + : Data(Vec.data()), Length(Vec.size()) {} /// Construct an ArrayRef from a C array. template <size_t N> @@ -120,6 +121,13 @@ namespace llvm { return Data[Length-1]; } + // copy - Allocate copy in BumpPtrAllocator and return ArrayRef<T> to it. + ArrayRef<T> copy(BumpPtrAllocator &Allocator) { + T *Buff = Allocator.Allocate<T>(Length); + std::copy(begin(), end(), Buff); + return ArrayRef<T>(Buff, Length); + } + /// equals - Check for element-wise equality. bool equals(ArrayRef RHS) const { if (Length != RHS.Length) |