This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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]

[v3] Finish overhauling stl_algobase.h


Hi,

the below finishes the work on this file. I haven't tried for now to
also fix the "hack" that we have been using for _Is_normal_iterator
(i.e., forward declaration of __normal_iterator)

Took the occasion to remove a redundant #include.

Tested x86-linux (gnu/generic locale models).

Paolo.

/////////////
2004-07-02  Paolo Carlini  <pcarlini@suse.de>

	* include/bits/type_traits.h (_Is_normal_iterator): Move...
	* include/bits/cpp_type_traits.h: ... here, renamed to
	__is_normal_iterator and consistent with the other traits.
	* include/bits/stl_algobase.h (__copy_ni1, __copy_ni2): Convert
	to the struct __copy_normal and three specializations.
	(__copy_backward_output_normal_iterator,
	__copy_backward_input_normal_iterator): Likewise, convert to
	the struct __copy_backward_normal and three specializations.
	(copy, copy_backward): Use the latter.
	(__copy_aux, __copy_backward_aux): Very minor tweaks.
diff -prN libstdc++-v3-orig/include/bits/cpp_type_traits.h libstdc++-v3/include/bits/cpp_type_traits.h
*** libstdc++-v3-orig/include/bits/cpp_type_traits.h	Mon Jun 28 23:40:55 2004
--- libstdc++-v3/include/bits/cpp_type_traits.h	Fri Jul  2 12:27:24 2004
***************
*** 42,48 ****
  //
  // This file provides some compile-time information about various types.
  // These representations were designed, on purpose, to be constant-expressions
! // and not types as found in <stl/bits/type_traits.h>.  In particular, they
  // can be used in control structures and the optimizer hopefully will do
  // the obvious thing.
  //
--- 42,48 ----
  //
  // This file provides some compile-time information about various types.
  // These representations were designed, on purpose, to be constant-expressions
! // and not types as found in <bits/type_traits.h>.  In particular, they
  // can be used in control structures and the optimizer hopefully will do
  // the obvious thing.
  //
*************** namespace __gnu_internal
*** 77,82 ****
--- 77,89 ----
    __two& __test_type (...);
  } // namespace __gnu_internal
  
+ // Forward declaration hack, should really include this from somewhere.
+ namespace __gnu_cxx
+ {
+   template<typename _Iterator, typename _Container>
+     class __normal_iterator;
+ } // namespace __gnu_cxx
+ 
  namespace std
  {
    // Compare for equality of types.
*************** namespace std
*** 325,330 ****
--- 332,359 ----
      };
  
    //
+   // Normal iterator type
+   //
+   template<typename _Tp>
+     struct __is_normal_iterator
+     {
+       enum
+ 	{
+ 	  _M_type = 0
+ 	};
+     };
+ 
+   template<typename _Iterator, typename _Container>
+     struct __is_normal_iterator< __gnu_cxx::__normal_iterator<_Iterator,
+ 							      _Container> >
+     {
+       enum
+ 	{
+ 	  _M_type = 1
+ 	};
+     };
+ 
+   //
    // An arithmetic type is an integer type or a floating point type
    //
    template<typename _Tp>
diff -prN libstdc++-v3-orig/include/bits/stl_algobase.h libstdc++-v3/include/bits/stl_algobase.h
*** libstdc++-v3-orig/include/bits/stl_algobase.h	Thu Jul  1 15:23:13 2004
--- libstdc++-v3/include/bits/stl_algobase.h	Fri Jul  2 15:44:56 2004
***************
*** 66,75 ****
  #include <climits>
  #include <cstdlib>
  #include <cstddef>
- #include <new>
  #include <iosfwd>
  #include <bits/stl_pair.h>
- #include <bits/type_traits.h>
  #include <bits/cpp_type_traits.h>
  #include <bits/stl_iterator_base_types.h>
  #include <bits/stl_iterator_base_funcs.h>
--- 66,73 ----
*************** namespace std
*** 220,226 ****
        return __a;
      }
  
!   // All of these auxiliary functions serve two purposes.  (1) Replace
    // calls to copy with memmove whenever possible.  (Memmove, not memcpy,
    // because the input and output ranges are permitted to overlap.)
    // (2) If we're using random access iterators, then write the loop as
--- 218,224 ----
        return __a;
      }
  
!   // All of these auxiliary structs serve two purposes.  (1) Replace
    // calls to copy with memmove whenever possible.  (Memmove, not memcpy,
    // because the input and output ranges are permitted to overlap.)
    // (2) If we're using random access iterators, then write the loop as
*************** namespace std
*** 276,282 ****
        typedef typename iterator_traits<_II>::value_type _ValueTypeI;
        typedef typename iterator_traits<_OI>::value_type _ValueTypeO;
        typedef typename iterator_traits<_II>::iterator_category _Category;
!       const bool __simple = (__is_trivially_copyable<_ValueTypeO>::_M_type
  	                     && __is_pointer<_II>::_M_type
  	                     && __is_pointer<_OI>::_M_type
  			     && __are_same<_ValueTypeI, _ValueTypeO>::_M_type);
--- 274,280 ----
        typedef typename iterator_traits<_II>::value_type _ValueTypeI;
        typedef typename iterator_traits<_OI>::value_type _ValueTypeO;
        typedef typename iterator_traits<_II>::iterator_category _Category;
!       const bool __simple = (__is_trivially_copyable<_ValueTypeI>::_M_type
  	                     && __is_pointer<_II>::_M_type
  	                     && __is_pointer<_OI>::_M_type
  			     && __are_same<_ValueTypeI, _ValueTypeO>::_M_type);
*************** namespace std
*** 284,320 ****
        return std::__copy<__simple, _Category>::copy(__first, __last, __result);
      }
  
!   template<typename _InputIterator, typename _OutputIterator>
!     inline _OutputIterator
!     __copy_ni2(_InputIterator __first, _InputIterator __last,
! 	       _OutputIterator __result, __true_type)
!     { return _OutputIterator(std::__copy_aux(__first, __last,
! 					     __result.base())); }
  
!   template<typename _InputIterator, typename _OutputIterator>
!     inline _OutputIterator
!     __copy_ni2(_InputIterator __first, _InputIterator __last,
! 	       _OutputIterator __result, __false_type)
!     { return std::__copy_aux(__first, __last, __result); }
  
!   template<typename _InputIterator, typename _OutputIterator>
!     inline _OutputIterator
!     __copy_ni1(_InputIterator __first, _InputIterator __last,
! 	       _OutputIterator __result, __true_type)
      {
!       typedef typename _Is_normal_iterator<_OutputIterator>::_Normal __Normal;
!       return std::__copy_ni2(__first.base(), __last.base(),
! 			     __result, __Normal());
!     }
  
!   template<typename _InputIterator, typename _OutputIterator>
!     inline _OutputIterator
!     __copy_ni1(_InputIterator __first, _InputIterator __last,
! 	       _OutputIterator __result, __false_type)
      {
!       typedef typename _Is_normal_iterator<_OutputIterator>::_Normal __Normal;
!       return std::__copy_ni2(__first, __last, __result, __Normal());
!     }
  
    /**
     *  @brief Copies the range [first,last) into result.
--- 282,323 ----
        return std::__copy<__simple, _Category>::copy(__first, __last, __result);
      }
  
!   template<bool, bool>
!     struct __copy_normal
!     {
!       template<typename _II, typename _OI>
!         static _OI
!         copy_n(_II __first, _II __last, _OI __result)
!         { return std::__copy_aux(__first, __last, __result); }
!     };
  
!   template<>
!     struct __copy_normal<true, false>
!     {
!       template<typename _II, typename _OI>
!         static _OI
!         copy_n(_II __first, _II __last, _OI __result)
!         { return std::__copy_aux(__first.base(), __last.base(), __result); }
!     };
  
!   template<>
!     struct __copy_normal<false, true>
      {
!       template<typename _II, typename _OI>
!         static _OI
!         copy_n(_II __first, _II __last, _OI __result)
!         { return _OI(std::__copy_aux(__first, __last, __result.base())); }
!     };
  
!   template<>
!     struct __copy_normal<true, true>
      {
!       template<typename _II, typename _OI>
!         static _OI
!         copy_n(_II __first, _II __last, _OI __result)
!         { return _OI(std::__copy_aux(__first.base(), __last.base(),
! 				     __result.base())); }
!     };
  
    /**
     *  @brief Copies the range [first,last) into result.
*************** namespace std
*** 343,350 ****
  	    typename iterator_traits<_InputIterator>::value_type>)
        __glibcxx_requires_valid_range(__first, __last);
  
!        typedef typename _Is_normal_iterator<_InputIterator>::_Normal __Normal;
!        return std::__copy_ni1(__first, __last, __result, __Normal());
      }
    
    template<bool, typename>
--- 346,355 ----
  	    typename iterator_traits<_InputIterator>::value_type>)
        __glibcxx_requires_valid_range(__first, __last);
  
!        const bool __in = __is_normal_iterator<_InputIterator>::_M_type;
!        const bool __out = __is_normal_iterator<_OutputIterator>::_M_type;
!        return std::__copy_normal<__in, __out>::copy_n(__first, __last,
! 						      __result);
      }
    
    template<bool, typename>
*************** namespace std
*** 394,400 ****
        typedef typename iterator_traits<_BI1>::value_type _ValueType1;
        typedef typename iterator_traits<_BI2>::value_type _ValueType2;
        typedef typename iterator_traits<_BI1>::iterator_category _Category;
!       const bool __simple = (__is_trivially_copyable<_ValueType2>::_M_type
  	                     && __is_pointer<_BI1>::_M_type
  	                     && __is_pointer<_BI2>::_M_type
  			     && __are_same<_ValueType1, _ValueType2>::_M_type);
--- 399,405 ----
        typedef typename iterator_traits<_BI1>::value_type _ValueType1;
        typedef typename iterator_traits<_BI2>::value_type _ValueType2;
        typedef typename iterator_traits<_BI1>::iterator_category _Category;
!       const bool __simple = (__is_trivially_copyable<_ValueType1>::_M_type
  	                     && __is_pointer<_BI1>::_M_type
  	                     && __is_pointer<_BI2>::_M_type
  			     && __are_same<_ValueType1, _ValueType2>::_M_type);
*************** namespace std
*** 403,440 ****
  							       __result);
      }
  
!   template <typename _BI1, typename _BI2>
!     inline _BI2
!     __copy_backward_output_normal_iterator(_BI1 __first, _BI1 __last,
! 					   _BI2 __result, __true_type)
!     { return _BI2(std::__copy_backward_aux(__first, __last, __result.base())); }
  
!   template <typename _BI1, typename _BI2>
!     inline _BI2
!     __copy_backward_output_normal_iterator(_BI1 __first, _BI1 __last,
! 					   _BI2 __result, __false_type)
!     { return std::__copy_backward_aux(__first, __last, __result); }
  
!   template <typename _BI1, typename _BI2>
!     inline _BI2
!     __copy_backward_input_normal_iterator(_BI1 __first, _BI1 __last,
! 					  _BI2 __result, __true_type)
      {
!       typedef typename _Is_normal_iterator<_BI2>::_Normal __Normal;
!       return std::__copy_backward_output_normal_iterator(__first.base(),
! 							 __last.base(),
! 							 __result, __Normal());
!     }
  
!   template <typename _BI1, typename _BI2>
!     inline _BI2
!     __copy_backward_input_normal_iterator(_BI1 __first, _BI1 __last,
! 					  _BI2 __result, __false_type)
      {
!       typedef typename _Is_normal_iterator<_BI2>::_Normal __Normal;
!       return std::__copy_backward_output_normal_iterator(__first, __last,
! 							 __result, __Normal());
!     }
  
    /**
     *  @brief Copies the range [first,last) into result.
--- 408,451 ----
  							       __result);
      }
  
!   template<bool, bool>
!     struct __copy_backward_normal
!     {
!       template<typename _BI1, typename _BI2>
!         static _BI2
!         copy_b_n(_BI1 __first, _BI1 __last, _BI2 __result)
!         { return std::__copy_backward_aux(__first, __last, __result); }
!     };
  
!   template<>
!     struct __copy_backward_normal<true, false>
!     {
!       template<typename _BI1, typename _BI2>
!         static _BI2
!         copy_b_n(_BI1 __first, _BI1 __last, _BI2 __result)
!         { return std::__copy_backward_aux(__first.base(), __last.base(),
! 					  __result); }
!     };
  
!   template<>
!     struct __copy_backward_normal<false, true>
      {
!       template<typename _BI1, typename _BI2>
!         static _BI2
!         copy_b_n(_BI1 __first, _BI1 __last, _BI2 __result)
!         { return _BI2(std::__copy_backward_aux(__first, __last,
! 					       __result.base())); }
!     };
  
!   template<>
!     struct __copy_backward_normal<true, true>
      {
!       template<typename _BI1, typename _BI2>
!         static _BI2
!         copy_b_n(_BI1 __first, _BI1 __last, _BI2 __result)
!         { return _BI2(std::__copy_backward_aux(__first.base(), __last.base(),
! 					       __result.base())); }
!     };
  
    /**
     *  @brief Copies the range [first,last) into result.
*************** namespace std
*** 465,473 ****
  	    typename iterator_traits<_BI2>::value_type>)
        __glibcxx_requires_valid_range(__first, __last);
  
!       typedef typename _Is_normal_iterator<_BI1>::_Normal __Normal;
!       return std::__copy_backward_input_normal_iterator(__first, __last,
! 							__result, __Normal());
      }
  
    template<bool>
--- 476,485 ----
  	    typename iterator_traits<_BI2>::value_type>)
        __glibcxx_requires_valid_range(__first, __last);
  
!       const bool __bi1 = __is_normal_iterator<_BI1>::_M_type;
!       const bool __bi2 = __is_normal_iterator<_BI2>::_M_type;
!       return std::__copy_backward_normal<__bi1, __bi2>::copy_b_n(__first, __last,
! 								 __result);
      }
  
    template<bool>
diff -prN libstdc++-v3-orig/include/bits/type_traits.h libstdc++-v3/include/bits/type_traits.h
*** libstdc++-v3-orig/include/bits/type_traits.h	Sun Feb  8 05:46:42 2004
--- libstdc++-v3/include/bits/type_traits.h	Fri Jul  2 11:04:32 2004
*************** template<>
*** 378,403 ****
      typedef __true_type _Integral;
    };
  
- template<typename _Tp>
-   struct _Is_normal_iterator
-   {
-     typedef __false_type _Normal;
-   };
- 
- // Forward declaration hack, should really include this from somewhere.
- namespace __gnu_cxx
- {
-   template<typename _Iterator, typename _Container>
-     class __normal_iterator;
- }
- 
- template<typename _Iterator, typename _Container>
-   struct _Is_normal_iterator< __gnu_cxx::__normal_iterator<_Iterator,
- 							   _Container> >
-   {
-     typedef __true_type _Normal;
-   };
- 
  #endif /* _TYPE_TRAITS_H */
  
  // Local Variables:
--- 378,383 ----

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