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]

Re: stl_vector.h problem - patch


After the switch in vector<>::iterator from a pointer
to the __normal_iterator<> class some changes are necessary.
I used the operator-> member function to fix it.


1999-05-03  Ryszard Kabatek <kabatek@chemie.uni-halle.de>

	* stl/bits/stl_vector.h:
	  Fix the code of vector<> for usage with an iterator class
	  (using iterator::operator->()).


Ryszard Kabatek
Martin-Luther University Halle-Wittenberg, Department of Physical Chemistry
Geusaer Str. 88, 06217 Merseburg, Germany
Tel. +49 3461 46 2487 Fax. +49 3461 46 2129
Index: stl/bits/stl_vector.h
===================================================================
RCS file: /cvs/libstdc++/libstdc++/stl/bits/stl_vector.h,v
retrieving revision 1.10
diff -c -2 -p -r1.10 stl_vector.h
*** stl_vector.h	1999/04/06 17:44:17	1.10
--- stl_vector.h	1999/05/03 16:31:23
*************** public:
*** 214,218 ****
      { return size_type(-1) / sizeof(_Tp); }
    size_type capacity() const
!     { return size_type(_M_end_of_storage - begin()); }
    bool empty() const
      { return begin() == end(); }
--- 214,218 ----
      { return size_type(-1) / sizeof(_Tp); }
    size_type capacity() const
!     { return size_type(const_iterator(_M_end_of_storage) - begin()); }
    bool empty() const
      { return begin() == end(); }
*************** public:
*** 287,292 ****
        destroy(_M_start, _M_finish);
        _M_deallocate(_M_start, _M_end_of_storage - _M_start);
!       _M_start = __tmp;
!       _M_finish = __tmp + __old_size;
        _M_end_of_storage = _M_start + __n;
      }
--- 287,292 ----
        destroy(_M_start, _M_finish);
        _M_deallocate(_M_start, _M_end_of_storage - _M_start);
!       _M_start = __tmp.operator->();
!       _M_finish = __tmp.operator->() + __old_size;
        _M_end_of_storage = _M_start + __n;
      }
*************** protected:
*** 442,446 ****
        return __result;
      }
!     __STL_UNWIND(_M_deallocate(__result, __n));
    }
  #else /* __STL_MEMBER_TEMPLATES */
--- 442,446 ----
        return __result;
      }
!     __STL_UNWIND(_M_deallocate(__result.operator->(), __n));
    }
  #else /* __STL_MEMBER_TEMPLATES */
*************** vector<_Tp,_Alloc>::operator=(const vect
*** 552,561 ****
        destroy(_M_start, _M_finish);
        _M_deallocate(_M_start, _M_end_of_storage - _M_start);
!       _M_start = __tmp;
        _M_end_of_storage = _M_start + __xlen;
      }
      else if (size() >= __xlen) {
        iterator __i(copy(__x.begin(), __x.end(), begin()));
!       destroy(__i, _M_finish);
      }
      else {
--- 552,561 ----
        destroy(_M_start, _M_finish);
        _M_deallocate(_M_start, _M_end_of_storage - _M_start);
!       _M_start = __tmp.operator->();
        _M_end_of_storage = _M_start + __xlen;
      }
      else if (size() >= __xlen) {
        iterator __i(copy(__x.begin(), __x.end(), begin()));
!       destroy(__i.operator->(), _M_finish);
      }
      else {
*************** vector<_Tp, _Alloc>::_M_insert_aux(itera
*** 667,671 ****
      construct(_M_finish, *(_M_finish - 1));
      ++_M_finish;
!     copy_backward(__position, _M_finish - 2, _M_finish - 1);
      *__position = _Tp();
    }
--- 667,671 ----
      construct(_M_finish, *(_M_finish - 1));
      ++_M_finish;
!     copy_backward(__position.operator->(), _M_finish - 2, _M_finish - 1);
      *__position = _Tp();
    }
*************** vector<_Tp, _Alloc>::_M_insert_aux(itera
*** 676,691 ****
      iterator __new_finish(__new_start);
      __STL_TRY {
!       __new_finish = uninitialized_copy(_M_start, __position, __new_start);
!       construct(__new_finish);
        ++__new_finish;
!       __new_finish = uninitialized_copy(__position, _M_finish, __new_finish);
      }
      __STL_UNWIND((destroy(__new_start,__new_finish), 
!                   _M_deallocate(__new_start,__len)));
      destroy(begin(), end());
      _M_deallocate(_M_start, _M_end_of_storage - _M_start);
!     _M_start = __new_start;
!     _M_finish = __new_finish;
!     _M_end_of_storage = __new_start + __len;
    }
  }
--- 676,693 ----
      iterator __new_finish(__new_start);
      __STL_TRY {
!       __new_finish = uninitialized_copy(_M_start, __position.operator->(),
!                                         __new_start);
!       construct(__new_finish.operator->());
        ++__new_finish;
!       __new_finish = uninitialized_copy(__position, iterator(_M_finish), 
!                                         __new_finish);
      }
      __STL_UNWIND((destroy(__new_start,__new_finish), 
!                   _M_deallocate(__new_start.operator->(),__len)));
      destroy(begin(), end());
      _M_deallocate(_M_start, _M_end_of_storage - _M_start);
!     _M_start = __new_start.operator->();
!     _M_finish = __new_finish.operator->();
!     _M_end_of_storage = __new_start.operator->() + __len;
    }
  }

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