This is the mail archive of the libstdc++@sourceware.cygnus.com 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]

vector algorithms and __normal_iterator



Now that vector<> is using __normal_iterator<> iterators in place of
plain pointers some of the specialisations that were previously used
no longer apply.  For example

   vector<int> a(3);
   vector<int> b(a.begin(), a.end());

used to call memmove (via __copy_trivial() in stl_algobase.h) but now
executes a loop in __copy().

I am not sure where this is best fixed. One possibility is in the
vector class itself:

------------------------------------------------------------------------------
1999-05-25  Philip Martin  <pm@corris.dircon.co.uk>

	* stl/bits/stl_vector.h: add __normal_iterator version of
	_M_range_initialize.

$  diff -c libstdc++/stl/bits/stl_vector.h libstdc++-modified/stl/bits
*** libstdc++/stl/bits/stl_vector.h     Fri May  7 20:10:14 1999
--- libstdc++-modified/stl/bits/stl_vector.h    Sun May 23 21:59:54 1999
***************
*** 478,483 ****
--- 478,490 ----
      _M_finish = uninitialized_copy(__first, __last, _M_start);
    }
  
+   void _M_range_initialize(iterator __first, iterator __last,
+                            iterator::iterator_category)
+   {
+      _M_range_initialize(__first.base(), __last.base(),
+                          __ITERATOR_CATEGORY(__first));
+   }
+ 
    template <class _InputIterator>
    void _M_range_insert(iterator __pos,
                         _InputIterator __first, _InputIterator __last,

------------------------------------------------------------------------------


Another way to do this is within the algorithms themselves.

------------------------------------------------------------------------------
1999-05-25  Philip Martin  <pm@corris.dircon.co.uk>

	* stl/bits/stl_algobase.h: add __normal_iterator version of
	copy


$ diff -c libstdc++/stl/bits/stl_algobase.h libstdc++-modified/stl/bits
***************
*** 187,192 ****
--- 186,199 ----
  inline _OutputIter copy(_InputIter __first, _InputIter __last,
                          _OutputIter __result) {
    return __copy_aux(__first, __last, __result, __VALUE_TYPE(__first));
+ }
+ 
+ template <typename _Tp, typename _Container, class _OutputIter>
+ inline _OutputIter copy(__normal_iterator<_Tp, _Container> __first,
+                         __normal_iterator<_Tp, _Container> __last,
+                         _OutputIter __result) {
+   return __copy_aux(__first.base(), __last.base(), __result,
+                     __VALUE_TYPE(__first.base()));
  }
  
  // Hack for compilers that don't have partial ordering of function templates

------------------------------------------------------------------------------


I expect there are other places where pointer specialisations are no
longer used, so should the change be made high up in the call chain
(in vector above) or lower down (in algorithms)?


Philip


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