[PATCH] D27723: ADT: Add OwningArrayRef class.
Peter Collingbourne via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 13 11:21:51 PST 2016
pcc created this revision.
pcc added a reviewer: rjmccall.
pcc added a subscriber: llvm-commits.
This is a MutableArrayRef that owns its array.
I plan to use this in https://reviews.llvm.org/D22296.
https://reviews.llvm.org/D27723
Files:
llvm/include/llvm/ADT/ArrayRef.h
Index: llvm/include/llvm/ADT/ArrayRef.h
===================================================================
--- llvm/include/llvm/ADT/ArrayRef.h
+++ llvm/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.81262.patch
Type: text/x-patch
Size: 1037 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161213/700b7b48/attachment.bin>
More information about the llvm-commits
mailing list