diff options
Diffstat (limited to 'include/llvm/ADT/OwningPtr.h')
-rw-r--r-- | include/llvm/ADT/OwningPtr.h | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/include/llvm/ADT/OwningPtr.h b/include/llvm/ADT/OwningPtr.h index 6b9e42e..034bcfd 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 { @@ -32,13 +33,22 @@ class OwningPtr { public: explicit OwningPtr(T *P = 0) : Ptr(P) {} -#if LLVM_HAS_RVALUE_REFERENCES OwningPtr(OwningPtr &&Other) : Ptr(Other.take()) {} OwningPtr &operator=(OwningPtr &&Other) { reset(Other.take()); 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() { @@ -63,6 +73,10 @@ public: return Tmp; } + T *release() { return take(); } + + std::unique_ptr<T> take_unique() { return std::unique_ptr<T>(take()); } + T &operator*() const { assert(Ptr && "Cannot dereference null pointer"); return *Ptr; @@ -96,14 +110,12 @@ class OwningArrayPtr { public: explicit OwningArrayPtr(T *P = 0) : Ptr(P) {} -#if LLVM_HAS_RVALUE_REFERENCES OwningArrayPtr(OwningArrayPtr &&Other) : Ptr(Other.take()) {} OwningArrayPtr &operator=(OwningArrayPtr &&Other) { reset(Other.take()); return *this; } -#endif ~OwningArrayPtr() { delete [] Ptr; |