1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 03:33:20 +01:00

[ADT/NullablePtr] Allow implicit conversion of NullablePtr<OtherT> -> NullablePtr<T> if OtherT is derived from T.

llvm-svn: 185851
This commit is contained in:
Argyrios Kyrtzidis 2013-07-08 19:12:01 +00:00
parent 3e59a5ddfa
commit 993565f337

View File

@ -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; }