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

David Blaikie dblaikie at gmail.com
Mon Jul 8 16:05:53 PDT 2013


On Mon, Jul 8, 2013 at 2:51 PM, Argyrios Kyrtzidis <akyrtzi at gmail.com> wrote:
> On Jul 8, 2013, at 12:47 PM, David Blaikie <dblaikie at gmail.com> wrote:
>
> On Mon, Jul 8, 2013 at 12:12 PM, Argyrios Kyrtzidis <akyrtzi at gmail.com>
> wrote:
>
> 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.
>
>
> Might be nicer to do this for any case where SrcT* is implicitly
> convertible DestT* (such as adding cv qualifiers or converting to
> void*).
>
>
> cv qualifiers look like are working, void* is not.
> In general, we need to add the equivalent of C++11's is_convertible to
> "llvm/Support/type_traits.h" and use it here.

Shall we do that then?

(your current implementation also disables this ctor for NullablePtr's
of non-class type (NullablePtr<int> for example), I think... that
seems unreasonable)

>
>
>
> 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; }
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
>



More information about the llvm-commits mailing list