This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

make unique_ptr<T,D> use D::pointer if it exists


We don't conform to [unique.ptr.single] paragraph 3, i.e. we don't use
the deleter's pointer type.

I won't be able to add new tests and commit it for a couple of days
but I believe the patch below is sufficient, does anyone see a problem
with it?


Index: include/bits/unique_ptr.h
===================================================================
--- include/bits/unique_ptr.h   (revision 158623)
+++ include/bits/unique_ptr.h   (working copy)
@@ -76,6 +76,22 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
       }
     };

+  // use SFINAE to determine whether _Del::pointer exists
+  template<typename _Tp, typename _Del>
+    class _UP_pointer_type
+    {
+      template<typename _Up>
+        static typename _Up::pointer __test(typename _Up::pointer*);
+
+      template<typename _Up>
+        static _Tp* __test(...);
+
+      typedef typename remove_reference<_Del>::type _Del2;
+
+    public:
+      typedef decltype( __test<_Del2>(0) ) type;
+    };
+
   /// 20.7.12.2 unique_ptr for single objects.
   template <typename _Tp, typename _Tp_Deleter = default_delete<_Tp> >
     class unique_ptr
@@ -84,9 +100,9 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
       typedef _Tp* unique_ptr::*             __unspecified_pointer_type;

     public:
-      typedef _Tp*               pointer;
-      typedef _Tp                element_type;
-      typedef _Tp_Deleter        deleter_type;
+      typedef typename _UP_pointer_type<_Tp, _Tp_Deleter>::type pointer;
+      typedef _Tp                                               element_type;
+      typedef _Tp_Deleter                                       deleter_type;

       // Constructors.
       unique_ptr()


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]