diff options
author | Stephen Hines <srhines@google.com> | 2014-04-23 16:57:46 -0700 |
---|---|---|
committer | Stephen Hines <srhines@google.com> | 2014-04-24 15:53:16 -0700 |
commit | 36b56886974eae4f9c5ebc96befd3e7bfe5de338 (patch) | |
tree | e6cfb69fbbd937f450eeb83bfb83b9da3b01275a /include/llvm/ADT/OwningPtr.h | |
parent | 69a8640022b04415ae9fac62f8ab090601d8f889 (diff) | |
download | external_llvm-36b56886974eae4f9c5ebc96befd3e7bfe5de338.zip external_llvm-36b56886974eae4f9c5ebc96befd3e7bfe5de338.tar.gz external_llvm-36b56886974eae4f9c5ebc96befd3e7bfe5de338.tar.bz2 |
Update to LLVM 3.5a.
Change-Id: Ifadecab779f128e62e430c2b4f6ddd84953ed617
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; |