[C++11] Add support for OwningPtr<T> to be converted to and from
[oota-llvm.git] / include / llvm / ADT / OwningPtr.h
index 3347ccd4a4216daa0294b93e8b38291e56fa25ce..4ee00ef6e804ff39e01cf376ade8cf0c106f0886 100644 (file)
@@ -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;