diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2013-07-08 19:12:01 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2013-07-08 19:12:01 +0000 |
commit | 7426a3b5880b68989e49f963229b7731cb36dba7 (patch) | |
tree | 78d2607b507090a48ca25a3ecf02a77770dc1984 /include/llvm | |
parent | ca4ed882f4b0d9ddb0ed49474ae5e217dde3ab5e (diff) | |
download | external_llvm-7426a3b5880b68989e49f963229b7731cb36dba7.zip external_llvm-7426a3b5880b68989e49f963229b7731cb36dba7.tar.gz external_llvm-7426a3b5880b68989e49f963229b7731cb36dba7.tar.bz2 |
[ADT/NullablePtr] Allow implicit conversion of NullablePtr<OtherT> -> NullablePtr<T> if OtherT is derived from T.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@185851 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm')
-rw-r--r-- | include/llvm/ADT/NullablePtr.h | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/include/llvm/ADT/NullablePtr.h b/include/llvm/ADT/NullablePtr.h index 8ddfd5d..e66c1d0 100644 --- a/include/llvm/ADT/NullablePtr.h +++ b/include/llvm/ADT/NullablePtr.h @@ -14,6 +14,7 @@ #ifndef LLVM_ADT_NULLABLEPTR_H #define LLVM_ADT_NULLABLEPTR_H +#include "llvm/Support/type_traits.h" #include <cassert> #include <cstddef> @@ -25,8 +26,17 @@ namespace llvm { template<class T> class NullablePtr { T *Ptr; + struct PlaceHolder {}; + public: NullablePtr(T *P = 0) : Ptr(P) {} + + template<typename OtherT> + NullablePtr(NullablePtr<OtherT> Other, + typename enable_if< + is_base_of<T, OtherT>, + PlaceHolder + >::type = PlaceHolder()) : Ptr(Other.getPtrOrNull()) {} bool isNull() const { return Ptr == 0; } bool isNonNull() const { return Ptr != 0; } |