Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 6605669

Browse files
committed
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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@289579 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 265ab52 commit 6605669

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

include/llvm/ADT/ArrayRef.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,25 @@ namespace llvm {
413413
}
414414
};
415415

416+
/// This is a MutableArrayRef that owns its array.
417+
template <typename T> class OwningArrayRef : public MutableArrayRef<T> {
418+
public:
419+
OwningArrayRef() {}
420+
OwningArrayRef(size_t Size) : MutableArrayRef<T>(new T[Size], Size) {}
421+
OwningArrayRef(ArrayRef<T> Data)
422+
: MutableArrayRef<T>(new T[Data.size()], Data.size()) {
423+
std::copy(Data.begin(), Data.end(), this->begin());
424+
}
425+
OwningArrayRef(OwningArrayRef &&Other) { *this = Other; }
426+
OwningArrayRef &operator=(OwningArrayRef &&Other) {
427+
delete this->data();
428+
this->MutableArrayRef<T>::operator=(Other);
429+
Other.MutableArrayRef<T>::operator=(MutableArrayRef<T>());
430+
return *this;
431+
}
432+
~OwningArrayRef() { delete this->data(); }
433+
};
434+
416435
/// @name ArrayRef Convenience constructors
417436
/// @{
418437

0 commit comments

Comments
 (0)