Skip to content

Commit

Permalink
[ADT/NullablePtr] Allow implicit conversion of NullablePtr<OtherT> ->…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
akyrtzi committed Jul 8, 2013
1 parent ca4ed88 commit 7426a3b
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions include/llvm/ADT/NullablePtr.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#ifndef LLVM_ADT_NULLABLEPTR_H
#define LLVM_ADT_NULLABLEPTR_H

#include "llvm/Support/type_traits.h"
#include <cassert>
#include <cstddef>

Expand All @@ -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; }
Expand Down

0 comments on commit 7426a3b

Please sign in to comment.