mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-23 11:13:28 +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:
parent
87a2fe46d9
commit
7ff136c7ac
@ -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
|
||||
/// @{
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user