[PATCH] D27723: ADT: Add OwningArrayRef class.
Peter Collingbourne via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 13 12:34:45 PST 2016
This revision was automatically updated to reflect the committed changes.
Closed by commit rL289579: ADT: Add OwningArrayRef class. (authored by pcc).
Changed prior to commit:
https://reviews.llvm.org/D27723?vs=81262&id=81283#toc
Repository:
rL LLVM
https://reviews.llvm.org/D27723
Files:
llvm/trunk/include/llvm/ADT/ArrayRef.h
Index: llvm/trunk/include/llvm/ADT/ArrayRef.h
===================================================================
--- llvm/trunk/include/llvm/ADT/ArrayRef.h
+++ llvm/trunk/include/llvm/ADT/ArrayRef.h
@@ -413,6 +413,25 @@
}
};
+ /// 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
/// @{
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27723.81283.patch
Type: text/x-patch
Size: 1055 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161213/711dd6d4/attachment.bin>
More information about the llvm-commits
mailing list