[llvm] r185851 - [ADT/NullablePtr] Allow implicit conversion of NullablePtr<OtherT> -> NullablePtr<T> if OtherT is derived from T.
Argyrios Kyrtzidis
akyrtzi at gmail.com
Mon Jul 8 12:12:02 PDT 2013
Author: akirtzidis
Date: Mon Jul 8 14:12:01 2013
New Revision: 185851
URL: http://llvm.org/viewvc/llvm-project?rev=185851&view=rev
Log:
[ADT/NullablePtr] Allow implicit conversion of NullablePtr<OtherT> -> NullablePtr<T> if OtherT is derived from T.
Modified:
llvm/trunk/include/llvm/ADT/NullablePtr.h
Modified: llvm/trunk/include/llvm/ADT/NullablePtr.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/NullablePtr.h?rev=185851&r1=185850&r2=185851&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/NullablePtr.h (original)
+++ llvm/trunk/include/llvm/ADT/NullablePtr.h Mon Jul 8 14:12:01 2013
@@ -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; }
More information about the llvm-commits
mailing list