summaryrefslogtreecommitdiff
path: root/include/llvm/ADT/OwningPtr.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/llvm/ADT/OwningPtr.h')
-rw-r--r--include/llvm/ADT/OwningPtr.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/include/llvm/ADT/OwningPtr.h b/include/llvm/ADT/OwningPtr.h
index 3347ccd4a4..4ee00ef6e8 100644
--- a/include/llvm/ADT/OwningPtr.h
+++ b/include/llvm/ADT/OwningPtr.h
@@ -17,6 +17,7 @@
#include "llvm/Support/Compiler.h"
#include <cassert>
#include <cstddef>
+#include <memory>
namespace llvm {
@@ -39,6 +40,17 @@ public:
return *this;
}
+ OwningPtr(std::unique_ptr<T> &&Other) : Ptr(Other.release()) {}
+
+ OwningPtr &operator=(std::unique_ptr<T> &&Other) {
+ reset(Other.release());
+ return *this;
+ }
+
+#if LLVM_HAS_RVALUE_REFERENCE_THIS
+ operator std::unique_ptr<T>() && { return std::unique_ptr<T>(take()); }
+#endif
+
~OwningPtr() {
delete Ptr;
}
@@ -61,6 +73,8 @@ public:
return Tmp;
}
+ std::unique_ptr<T> take_unique() { return std::unique_ptr<T>(take()); }
+
T &operator*() const {
assert(Ptr && "Cannot dereference null pointer");
return *Ptr;