From: Argyrios Kyrtzidis Date: Mon, 8 Jul 2013 19:12:01 +0000 (+0000) Subject: [ADT/NullablePtr] Allow implicit conversion of NullablePtr -> NullablePtr... X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=7426a3b5880b68989e49f963229b7731cb36dba7;p=oota-llvm.git [ADT/NullablePtr] Allow implicit conversion of NullablePtr -> NullablePtr if OtherT is derived from T. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@185851 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/ADT/NullablePtr.h b/include/llvm/ADT/NullablePtr.h index 8ddfd5d20ab..e66c1d08cde 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 #include @@ -25,8 +26,17 @@ namespace llvm { template class NullablePtr { T *Ptr; + struct PlaceHolder {}; + public: NullablePtr(T *P = 0) : Ptr(P) {} + + template + NullablePtr(NullablePtr Other, + typename enable_if< + is_base_of, + PlaceHolder + >::type = PlaceHolder()) : Ptr(Other.getPtrOrNull()) {} bool isNull() const { return Ptr == 0; } bool isNonNull() const { return Ptr != 0; }