[llvm] r289579 - ADT: Add OwningArrayRef class.
Peter Collingbourne via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 13 12:24:25 PST 2016
Author: pcc
Date: Tue Dec 13 14:24:24 2016
New Revision: 289579
URL: http://llvm.org/viewvc/llvm-project?rev=289579&view=rev
Log:
ADT: Add OwningArrayRef class.
This is a MutableArrayRef that owns its array.
I plan to use this in D22296.
Differential Revision: https://reviews.llvm.org/D27723
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=289579&r1=289578&r2=289579&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/ArrayRef.h (original)
+++ llvm/trunk/include/llvm/ADT/ArrayRef.h Tue Dec 13 14:24:24 2016
@@ -413,6 +413,25 @@ namespace llvm {
}
};
+ /// This is a MutableArrayRef that owns its array.
+ template <typename T> class OwningArrayRef : public MutableArrayRef<T> {
+ public:
+ OwningArrayRef() {}
+ OwningArrayRef(size_t Size) : MutableArrayRef<T>(new T[Size], Size) {}
+ OwningArrayRef(ArrayRef<T> Data)
+ : MutableArrayRef<T>(new T[Data.size()], Data.size()) {
+ std::copy(Data.begin(), Data.end(), this->begin());
+ }
+ OwningArrayRef(OwningArrayRef &&Other) { *this = Other; }
+ OwningArrayRef &operator=(OwningArrayRef &&Other) {
+ delete this->data();
+ this->MutableArrayRef<T>::operator=(Other);
+ Other.MutableArrayRef<T>::operator=(MutableArrayRef<T>());
+ return *this;
+ }
+ ~OwningArrayRef() { delete this->data(); }
+ };
+
/// @name ArrayRef Convenience constructors
/// @{
More information about the llvm-commits
mailing list