Commit b49df333 by Benjamin Kosnik Committed by Martin v. Löwis

stl_rope.h: Fix initialization order.

        * stl_rope.h: Fix initialization order.
        * stl_deque.h: Use static_casts<size_type>(signed_type).

Co-Authored-By: Matthias Klose <doko@cs.tu-berlin.de>

From-SVN: r30622
parent a8196924
1999-11-10 Benjamin Kosnik <bkoz@haight.constant.com>
Matthias Klose <doko@cs.tu-berlin.de>
* stl_rope.h: Fix initialization order.
* stl_deque.h: Use static_casts<size_type>(signed_type).
1999-11-06 Martin v. Lwis <loewis@informatik.hu-berlin.de> 1999-11-06 Martin v. Lwis <loewis@informatik.hu-berlin.de>
* bitset (class bitset): Declare reference as our friend. * bitset (class bitset): Declare reference as our friend.
......
...@@ -815,7 +815,7 @@ public: // Erase ...@@ -815,7 +815,7 @@ public: // Erase
iterator __next = __pos; iterator __next = __pos;
++__next; ++__next;
difference_type __index = __pos - _M_start; difference_type __index = __pos - _M_start;
if (__index < (size() >> 1)) { if (static_cast<size_type>(__index) < (size() >> 1)) {
copy_backward(_M_start, __pos, __next); copy_backward(_M_start, __pos, __next);
pop_front(); pop_front();
} }
...@@ -1048,7 +1048,7 @@ deque<_Tp,_Alloc,__bufsize>::erase(iterator __first, iterator __last) ...@@ -1048,7 +1048,7 @@ deque<_Tp,_Alloc,__bufsize>::erase(iterator __first, iterator __last)
else { else {
difference_type __n = __last - __first; difference_type __n = __last - __first;
difference_type __elems_before = __first - _M_start; difference_type __elems_before = __first - _M_start;
if (__elems_before < (size() - __n) / 2) { if (static_cast<size_type>(__elems_before) < (size() - __n) / 2) {
copy_backward(_M_start, __first, __last); copy_backward(_M_start, __first, __last);
iterator __new_start = _M_start + __n; iterator __new_start = _M_start + __n;
destroy(_M_start, __new_start); destroy(_M_start, __new_start);
...@@ -1282,7 +1282,7 @@ deque<_Tp,_Alloc,__bufsize>::_M_insert_aux(iterator __pos, ...@@ -1282,7 +1282,7 @@ deque<_Tp,_Alloc,__bufsize>::_M_insert_aux(iterator __pos,
{ {
difference_type __index = __pos - _M_start; difference_type __index = __pos - _M_start;
value_type __x_copy = __x; value_type __x_copy = __x;
if (__index < size() / 2) { if (static_cast<size_type>(__index) < size() / 2) {
push_front(front()); push_front(front());
iterator __front1 = _M_start; iterator __front1 = _M_start;
++__front1; ++__front1;
...@@ -1311,7 +1311,7 @@ typename deque<_Tp,_Alloc,__bufsize>::iterator ...@@ -1311,7 +1311,7 @@ typename deque<_Tp,_Alloc,__bufsize>::iterator
deque<_Tp,_Alloc,__bufsize>::_M_insert_aux(iterator __pos) deque<_Tp,_Alloc,__bufsize>::_M_insert_aux(iterator __pos)
{ {
difference_type __index = __pos - _M_start; difference_type __index = __pos - _M_start;
if (__index < size() / 2) { if (static_cast<size_type>(__index) < size() / 2) {
push_front(front()); push_front(front());
iterator __front1 = _M_start; iterator __front1 = _M_start;
++__front1; ++__front1;
...@@ -1344,7 +1344,7 @@ deque<_Tp,_Alloc,__bufsize>::_M_insert_aux(iterator __pos, ...@@ -1344,7 +1344,7 @@ deque<_Tp,_Alloc,__bufsize>::_M_insert_aux(iterator __pos,
const difference_type __elems_before = __pos - _M_start; const difference_type __elems_before = __pos - _M_start;
size_type __length = size(); size_type __length = size();
value_type __x_copy = __x; value_type __x_copy = __x;
if (__elems_before < __length / 2) { if (static_cast<size_type>(__elems_before) < __length / 2) {
iterator __new_start = _M_reserve_elements_at_front(__n); iterator __new_start = _M_reserve_elements_at_front(__n);
iterator __old_start = _M_start; iterator __old_start = _M_start;
__pos = _M_start + __elems_before; __pos = _M_start + __elems_before;
...@@ -1403,7 +1403,7 @@ deque<_Tp,_Alloc,__bufsize>::_M_insert_aux(iterator __pos, ...@@ -1403,7 +1403,7 @@ deque<_Tp,_Alloc,__bufsize>::_M_insert_aux(iterator __pos,
{ {
const difference_type __elemsbefore = __pos - _M_start; const difference_type __elemsbefore = __pos - _M_start;
size_type __length = size(); size_type __length = size();
if (__elemsbefore < __length / 2) { if (static_cast<size_type>(__elemsbefore) < __length / 2) {
iterator __new_start = _M_reserve_elements_at_front(__n); iterator __new_start = _M_reserve_elements_at_front(__n);
iterator __old_start = _M_start; iterator __old_start = _M_start;
__pos = _M_start + __elemsbefore; __pos = _M_start + __elemsbefore;
......
...@@ -386,8 +386,8 @@ struct _Rope_RopeRep : public _Rope_rep_base<_CharT,_Alloc> { ...@@ -386,8 +386,8 @@ struct _Rope_RopeRep : public _Rope_rep_base<_CharT,_Alloc> {
typedef _Rope_rep_base<_CharT,_Alloc>::allocator_type allocator_type; typedef _Rope_rep_base<_CharT,_Alloc>::allocator_type allocator_type;
_Rope_RopeRep(_Tag __t, int __d, bool __b, size_t __size, _Rope_RopeRep(_Tag __t, int __d, bool __b, size_t __size,
allocator_type __a) allocator_type __a)
: _M_tag(__t), _M_depth(__d), _M_is_balanced(__b), _M_c_string(0), : _Rope_rep_base<_CharT,_Alloc>(__size, __a),
_Rope_rep_base<_CharT,_Alloc>(__size, __a) _M_tag(__t), _M_depth(__d), _M_is_balanced(__b), _M_c_string(0)
{ {
# ifndef __GC # ifndef __GC
_M_refcount = 1; _M_refcount = 1;
...@@ -562,8 +562,8 @@ struct _Rope_RopeLeaf : public _Rope_RopeRep<_CharT,_Alloc> { ...@@ -562,8 +562,8 @@ struct _Rope_RopeLeaf : public _Rope_RopeRep<_CharT,_Alloc> {
/* doesn't matter. */ /* doesn't matter. */
typedef _Rope_rep_base<_CharT,_Alloc>::allocator_type allocator_type; typedef _Rope_rep_base<_CharT,_Alloc>::allocator_type allocator_type;
_Rope_RopeLeaf(__GC_CONST _CharT* __d, size_t __size, allocator_type __a) _Rope_RopeLeaf(__GC_CONST _CharT* __d, size_t __size, allocator_type __a)
: _M_data(__d) : _Rope_RopeRep<_CharT,_Alloc>(_S_leaf, 0, true, __size, __a),
, _Rope_RopeRep<_CharT,_Alloc>(_S_leaf, 0, true, __size, __a) _M_data(__d)
{ {
__stl_assert(__size > 0); __stl_assert(__size > 0);
if (_S_is_basic_char_type((_CharT *)0)) { if (_S_is_basic_char_type((_CharT *)0)) {
...@@ -593,10 +593,10 @@ struct _Rope_RopeConcatenation : public _Rope_RopeRep<_CharT,_Alloc> { ...@@ -593,10 +593,10 @@ struct _Rope_RopeConcatenation : public _Rope_RopeRep<_CharT,_Alloc> {
_Rope_RopeConcatenation(_Rope_RopeRep<_CharT,_Alloc>* __l, _Rope_RopeConcatenation(_Rope_RopeRep<_CharT,_Alloc>* __l,
_Rope_RopeRep<_CharT,_Alloc>* __r, _Rope_RopeRep<_CharT,_Alloc>* __r,
allocator_type __a) allocator_type __a)
: _M_left(__l), _M_right(__r) : _Rope_RopeRep<_CharT,_Alloc>(
, _Rope_RopeRep<_CharT,_Alloc>(
_S_concat, max(__l->_M_depth, __r->_M_depth) + 1, false, _S_concat, max(__l->_M_depth, __r->_M_depth) + 1, false,
__l->_M_size + __r->_M_size, __a) __l->_M_size + __r->_M_size, __a),
_M_left(__l), _M_right(__r)
{} {}
# ifndef __GC # ifndef __GC
~_Rope_RopeConcatenation() { ~_Rope_RopeConcatenation() {
...@@ -629,11 +629,12 @@ struct _Rope_RopeFunction : public _Rope_RopeRep<_CharT,_Alloc> { ...@@ -629,11 +629,12 @@ struct _Rope_RopeFunction : public _Rope_RopeRep<_CharT,_Alloc> {
typedef _Rope_rep_base<_CharT,_Alloc>::allocator_type allocator_type; typedef _Rope_rep_base<_CharT,_Alloc>::allocator_type allocator_type;
_Rope_RopeFunction(char_producer<_CharT>* __f, size_t __size, _Rope_RopeFunction(char_producer<_CharT>* __f, size_t __size,
bool __d, allocator_type __a) bool __d, allocator_type __a)
: _M_fn(__f) :_Rope_RopeRep<_CharT,_Alloc>(_S_function, 0, true, __size, __a),
_M_fn(__f)
# ifndef __GC # ifndef __GC
, _M_delete_when_done(__d) , _M_delete_when_done(__d)
# endif # endif
, _Rope_RopeRep<_CharT,_Alloc>(_S_function, 0, true, __size, __a) { {
__stl_assert(__size > 0); __stl_assert(__size > 0);
# ifdef __GC # ifdef __GC
if (__d) { if (__d) {
...@@ -693,9 +694,7 @@ struct _Rope_RopeSubstring : public _Rope_RopeFunction<_CharT,_Alloc>, ...@@ -693,9 +694,7 @@ struct _Rope_RopeSubstring : public _Rope_RopeFunction<_CharT,_Alloc>,
typedef _Rope_rep_base<_CharT,_Alloc>::allocator_type allocator_type; typedef _Rope_rep_base<_CharT,_Alloc>::allocator_type allocator_type;
_Rope_RopeSubstring(_Rope_RopeRep<_CharT,_Alloc>* __b, size_t __s, _Rope_RopeSubstring(_Rope_RopeRep<_CharT,_Alloc>* __b, size_t __s,
size_t __l, allocator_type __a) size_t __l, allocator_type __a)
: _M_base(__b) : _Rope_RopeFunction<_CharT,_Alloc>(this, __l, false, __a), _M_base(__b), _M_start(__s)
, _M_start(__s)
, _Rope_RopeFunction<_CharT,_Alloc>(this, __l, false, __a)
{ {
__stl_assert(__l > 0); __stl_assert(__l > 0);
__stl_assert(__s + __l <= __b->_M_size); __stl_assert(__s + __l <= __b->_M_size);
...@@ -766,16 +765,16 @@ class _Rope_char_ref_proxy { ...@@ -766,16 +765,16 @@ class _Rope_char_ref_proxy {
_My_rope* _M_root; // The whole rope. _My_rope* _M_root; // The whole rope.
public: public:
_Rope_char_ref_proxy(_My_rope* __r, size_t __p) : _Rope_char_ref_proxy(_My_rope* __r, size_t __p) :
_M_pos(__p), _M_root(__r), _M_current_valid(false) {} _M_pos(__p), _M_current_valid(false), _M_root(__r) {}
_Rope_char_ref_proxy(const _Rope_char_ref_proxy& __x) : _Rope_char_ref_proxy(const _Rope_char_ref_proxy& __x) :
_M_pos(__x._M_pos), _M_root(__x._M_root), _M_current_valid(false) {} _M_pos(__x._M_pos), _M_current_valid(false), _M_root(__x._M_root) {}
// Don't preserve cache if the reference can outlive the // Don't preserve cache if the reference can outlive the
// expression. We claim that's not possible without calling // expression. We claim that's not possible without calling
// a copy constructor or generating reference to a proxy // a copy constructor or generating reference to a proxy
// reference. We declare the latter to have undefined semantics. // reference. We declare the latter to have undefined semantics.
_Rope_char_ref_proxy(_My_rope* __r, size_t __p, _Rope_char_ref_proxy(_My_rope* __r, size_t __p,
_CharT __c) : _CharT __c) :
_M_pos(__p), _M_root(__r), _M_current(__c), _M_current_valid(true) {} _M_pos(__p), _M_current(__c), _M_current_valid(true), _M_root(__r) {}
inline operator _CharT () const; inline operator _CharT () const;
_Rope_char_ref_proxy& operator= (_CharT __c); _Rope_char_ref_proxy& operator= (_CharT __c);
_Rope_char_ptr_proxy<_CharT,_Alloc> operator& () const; _Rope_char_ptr_proxy<_CharT,_Alloc> operator& () const;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment