1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 03:02:36 +01:00

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

llvm-svn: 289579
This commit is contained in:
Peter Collingbourne 2016-12-13 20:24:24 +00:00
parent 87a2fe46d9
commit 7ff136c7ac

View File

@ -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
/// @{