diff mbox

[v3] libstdc++/45549

Message ID 4C86BD5E.4020508@oracle.com
State New
Headers show

Commit Message

Paolo Carlini Sept. 7, 2010, 10:31 p.m. UTC
Hi,

I have applied to mainline the change suggested by Marc, let's see how
it goes. Tested x86_64-linux.

Paolo.

////////////////////
2010-09-07  Paolo Carlini  <paolo.carlini@oracle.com>
	    Marc Glisse  <marc.glisse@normalesup.org>

	PR libstdc++/45549
	* include/bits/cpp_type_traits.h (__is_iterator_helper): Rename to
	__has_iterator_category.
	(__is_iterator): Adjust.
	* include/bits/stl_iterator_base_types.h (__iterator_traits): Add
	in C++0x mode, use the latter.
	(iterator_traits): In C++0x mode, derive from the latter.
	* include/bits/stl_iterator_base_funcs.h (next, prev): Remove
	enable_if on the return type.
diff mbox

Patch

Index: include/bits/stl_iterator_base_types.h
===================================================================
--- include/bits/stl_iterator_base_types.h	(revision 163925)
+++ include/bits/stl_iterator_base_types.h	(working copy)
@@ -64,6 +64,10 @@ 
 
 #include <bits/c++config.h>
 
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+# include <bits/cpp_type_traits.h> // For __has_iterator_category
+#endif
+
 _GLIBCXX_BEGIN_NAMESPACE(std)
 
   /**
@@ -132,8 +136,27 @@ 
    *  argument.  Specialized versions for pointers and pointers-to-const
    *  provide tighter, more correct semantics.
   */
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+  template<typename _Iterator,
+	   bool = __has_iterator_category<_Iterator>::__value>
+    struct __iterator_traits { };
+
   template<typename _Iterator>
+    struct __iterator_traits<_Iterator, true>
+    {
+      typedef typename _Iterator::iterator_category iterator_category;
+      typedef typename _Iterator::value_type        value_type;
+      typedef typename _Iterator::difference_type   difference_type;
+      typedef typename _Iterator::pointer           pointer;
+      typedef typename _Iterator::reference         reference;
+    };
+
+  template<typename _Iterator>
     struct iterator_traits
+    : public __iterator_traits<_Iterator> { };
+#else
+  template<typename _Iterator>
+    struct iterator_traits
     {
       typedef typename _Iterator::iterator_category iterator_category;
       typedef typename _Iterator::value_type        value_type;
@@ -141,6 +164,7 @@ 
       typedef typename _Iterator::pointer           pointer;
       typedef typename _Iterator::reference         reference;
     };
+#endif
 
   /// Partial specialization for pointer types.
   template<typename _Tp>
Index: include/bits/stl_iterator_base_funcs.h
===================================================================
--- include/bits/stl_iterator_base_funcs.h	(revision 163925)
+++ include/bits/stl_iterator_base_funcs.h	(working copy)
@@ -173,18 +173,10 @@ 
       std::__advance(__i, __d, std::__iterator_category(__i));
     }
 
-_GLIBCXX_END_NAMESPACE
-
 #ifdef __GXX_EXPERIMENTAL_CXX0X__
 
-#include <ext/type_traits.h> // For __enable_if and __is_iterator
-
-_GLIBCXX_BEGIN_NAMESPACE(std)
-
   template<typename _ForwardIterator>
-    inline typename
-    __gnu_cxx::__enable_if<__is_iterator<_ForwardIterator>::__value,
-			   _ForwardIterator>::__type
+    inline _ForwardIterator
     next(_ForwardIterator __x, typename
 	 iterator_traits<_ForwardIterator>::difference_type __n = 1)
     {
@@ -193,9 +185,7 @@ 
     }
 
   template<typename _BidirectionalIterator>
-    inline typename
-    __gnu_cxx::__enable_if<__is_iterator<_BidirectionalIterator>::__value,
-			   _BidirectionalIterator>::__type
+    inline _BidirectionalIterator
     prev(_BidirectionalIterator __x, typename
 	 iterator_traits<_BidirectionalIterator>::difference_type __n = 1) 
     {
@@ -203,8 +193,8 @@ 
       return __x;
     }
 
-_GLIBCXX_END_NAMESPACE
-
 #endif // __GXX_EXPERIMENTAL_CXX0X__
 
+_GLIBCXX_END_NAMESPACE
+
 #endif /* _STL_ITERATOR_BASE_FUNCS_H */
Index: include/bits/cpp_type_traits.h
===================================================================
--- include/bits/cpp_type_traits.h	(revision 163925)
+++ include/bits/cpp_type_traits.h	(working copy)
@@ -415,7 +415,7 @@ 
 #endif
 
   template<typename _Tp>
-    class __is_iterator_helper
+    class __has_iterator_category
     {
       typedef char __one;
       typedef struct { char __arr[2]; } __two;
@@ -431,14 +431,14 @@ 
         static __two __test(...);
 
     public:
-      static const bool __value = (sizeof(__test<_Tp>(0)) == 1
-				   || __is_pointer<_Tp>::__value);
+      static const bool __value = sizeof(__test<_Tp>(0)) == 1;
     };
 
   template<typename _Tp>
     struct __is_iterator
     {
-      enum { __value = __is_iterator_helper<_Tp>::__value };
+      enum { __value = (__has_iterator_category<_Tp>::__value
+			|| __is_pointer<_Tp>::__value) };
       typedef typename __truth_type<__value>::__type __type;
     };