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]

[Patch] Remove workaround for copy_backward


Hi all, hi Gaby,

in the current code there is this disclaimer:

// This dispatch class is a workaround for compilers that do not
// have partial ordering of function templates.  All we're doing is
// creating a specialization so that we can turn a call to copy_backward
// into a memmove whenever possible.
template<typename _BidirectionalIterator1, typename _BidirectionalIterator2,
        typename _BoolType>
 struct __copy_backward_dispatch(...

However, interestingly, before it, in the implementation of copy, partial
ordering of function templates *is used*, and this is safe since current
g++ is actually ok (the disclaimer dates back to SGI/HP, I think!).

Therefore, I simply removed the workaround and used for copy_backward the
very same dispatching strategy already present for copy.

Regtested x86-linux, of course, but I don't consider myself a templates
wizard ;), therefore I'm asking humbly for a review, Gaby and
everyone!

Paolo.

///////////
2003-09-27  Paolo Carlini  <pcarlini@unitus.it>

	* include/bits/stl_algobase.h (struct __copy_backward_dispatch):
	Remove, thus avoiding the workaround. Use instead...
	(__copy_backward_dispatch(_BidirectionalIterator1,
	_BidirectionalIterator1, _BidirectionalIterator2, __false_type),
	__copy_backward_dispatch(_BidirectionalIterator1,
	_BidirectionalIterator1, _BidirectionalIterator2, __true_type),
	__copy_backward_dispatch(_Tp*, _Tp*, _Tp*, __true_type),
	__copy_backward_dispatch(const _Tp*, const _Tp*, _Tp*,
	__true_type)): ... this set of function templates, similarly
	to what happens in the implementation of copy(). The latter two
	call __copy_backward_trivial.
	(__copy_backward_trivial): New, similar to __copy_trivial.
	(__copy_backward_aux): Tweak.
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	Tue Jul 15 09:30:19 2003
--- libstdc++-v3/include/bits/stl_algobase.h	Sat Sep 27 17:42:58 2003
*************** namespace std
*** 359,404 ****
        return __result;
      }
  
- 
-   // This dispatch class is a workaround for compilers that do not 
-   // have partial ordering of function templates.  All we're doing is
-   // creating a specialization so that we can turn a call to copy_backward
-   // into a memmove whenever possible.
-   template<typename _BidirectionalIterator1, typename _BidirectionalIterator2,
-            typename _BoolType>
-     struct __copy_backward_dispatch
-     {
-       static _BidirectionalIterator2
-       copy(_BidirectionalIterator1 __first, _BidirectionalIterator1 __last, 
- 	   _BidirectionalIterator2 __result)
-       {
-         return std::__copy_backward(__first, __last, __result, 
- 				    std::__iterator_category(__first));
-       }
-     };
- 
    template<typename _Tp>
!     struct __copy_backward_dispatch<_Tp*, _Tp*, __true_type>
      {
!       static _Tp*
!       copy(const _Tp* __first, const _Tp* __last, _Tp* __result)
!       {
! 	const ptrdiff_t _Num = __last - __first;
! 	std::memmove(__result - _Num, __first, sizeof(_Tp) * _Num);
! 	return __result - _Num;
!       }
!     };
  
    template<typename _Tp>
!     struct __copy_backward_dispatch<const _Tp*, _Tp*, __true_type>
!     {
!       static _Tp*
!       copy(const _Tp* __first, const _Tp* __last, _Tp* __result)
!       {
! 	return  std::__copy_backward_dispatch<_Tp*, _Tp*, __true_type>
! 	  ::copy(__first, __last, __result);
!       }
!     };
  
    template<typename _BI1, typename _BI2>
      inline _BI2
--- 359,405 ----
        return __result;
      }
  
    template<typename _Tp>
!     inline _Tp*
!     __copy_backward_trivial(const _Tp* __first, const _Tp* __last, _Tp* __result)
      {
!       const ptrdiff_t _Num = __last - __first;
!       std::memmove(__result - _Num, __first, sizeof(_Tp) * _Num);
!       return __result - _Num;
!     }
! 
!   template<typename _BidirectionalIterator1, typename _BidirectionalIterator2>
!     inline _BidirectionalIterator2
!     __copy_backward_dispatch(_BidirectionalIterator1 __first,
! 			     _BidirectionalIterator1 __last,
! 			     _BidirectionalIterator2 __result,
! 			     __false_type)
!     {
!       return std::__copy_backward(__first, __last, __result, 
! 				  std::__iterator_category(__first));
!     }
! 
!   template<typename _BidirectionalIterator1, typename _BidirectionalIterator2>
!     inline _BidirectionalIterator2
!     __copy_backward_dispatch(_BidirectionalIterator1 __first,
! 			     _BidirectionalIterator1 __last,
! 			     _BidirectionalIterator2 __result,
! 			     __true_type)
!     {
!       return std::__copy_backward(__first, __last, __result, 
! 				  std::__iterator_category(__first));
!     }
  
    template<typename _Tp>
!     inline _Tp*
!     __copy_backward_dispatch(_Tp* __first, _Tp* __last, _Tp* __result, __true_type)
!     { return std::__copy_backward_trivial(__first, __last, __result); }
! 
!   template<typename _Tp>
!     inline _Tp*
!     __copy_backward_dispatch(const _Tp* __first, const _Tp* __last, _Tp* __result,
! 			     __true_type)
!     { return std::__copy_backward_trivial(__first, __last, __result); }
  
    template<typename _BI1, typename _BI2>
      inline _BI2
*************** namespace std
*** 406,414 ****
      {
        typedef typename __type_traits<typename iterator_traits<_BI2>::value_type>
  			    ::has_trivial_assignment_operator _Trivial;
!       return std::__copy_backward_dispatch<_BI1, _BI2, _Trivial>::copy(__first, 
! 								       __last, 
! 								       __result);
      }
  
    template <typename _BI1, typename _BI2>
--- 407,413 ----
      {
        typedef typename __type_traits<typename iterator_traits<_BI2>::value_type>
  			    ::has_trivial_assignment_operator _Trivial;
!       return std::__copy_backward_dispatch(__first, __last, __result, _Trivial());
      }
  
    template <typename _BI1, typename _BI2>

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