From 8070c78887949b019683b0df268d0e4bbc98169e Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Sat, 18 Oct 1997 02:09:13 +0000 Subject: * tree.h, vector.h: Fix accidental divergence from SGI release. From-SVN: r15989 --- libstdc++/stl/ChangeLog | 4 ++++ libstdc++/stl/tree.h | 4 ++-- libstdc++/stl/vector.h | 58 +++++++++++++++++++++++++++++-------------------- 3 files changed, 40 insertions(+), 26 deletions(-) (limited to 'libstdc++') diff --git a/libstdc++/stl/ChangeLog b/libstdc++/stl/ChangeLog index 2e12e0c8dab..ca1c01a626f 100644 --- a/libstdc++/stl/ChangeLog +++ b/libstdc++/stl/ChangeLog @@ -1,3 +1,7 @@ +Fri Oct 17 19:07:42 1997 Jason Merrill + + * tree.h, vector.h: Fix accidental divergence from SGI release. + Tue Sep 9 19:47:28 1997 Jason Merrill * algo.h, algobase.h, alloc.h, bvector.h, deque.h, hashtable.h, diff --git a/libstdc++/stl/tree.h b/libstdc++/stl/tree.h index b55f0c51f0f..80e0cafa352 100644 --- a/libstdc++/stl/tree.h +++ b/libstdc++/stl/tree.h @@ -523,10 +523,10 @@ private: public: // allocation/deallocation rb_tree(const Compare& comp = Compare()) - : key_compare(comp), node_count(0) { init(); } + : node_count(0), key_compare(comp) { init(); } rb_tree(const rb_tree& x) - : key_compare(x.key_compare), node_count(0) { + : node_count(0), key_compare(x.key_compare) { header = get_node(); color(header) = __rb_tree_red; if (x.root() == 0) { diff --git a/libstdc++/stl/vector.h b/libstdc++/stl/vector.h index e0b88a1cd49..1c7867e8b03 100644 --- a/libstdc++/stl/vector.h +++ b/libstdc++/stl/vector.h @@ -61,6 +61,12 @@ protected: void deallocate() { if (start) data_allocator::deallocate(start, end_of_storage - start); } + + void fill_initialize(size_type n, const T& value) { + start = allocate_and_fill(n, value); + finish = start + n; + end_of_storage = finish; + } public: iterator begin() { return start; } const_iterator begin() const { return start; } @@ -75,22 +81,18 @@ public: return const_reverse_iterator(begin()); } size_type size() const { return size_type(end() - begin()); } - size_type max_size() const { return size_type(-1); } + size_type max_size() const { return size_type(-1) / sizeof(T); } size_type capacity() const { return size_type(end_of_storage - begin()); } bool empty() const { return begin() == end(); } reference operator[](size_type n) { return *(begin() + n); } const_reference operator[](size_type n) const { return *(begin() + n); } + vector() : start(0), finish(0), end_of_storage(0) {} - vector(size_type n, const T& value) { - start = allocate_and_fill(n, value); - finish = start + n; - end_of_storage = finish; - } - explicit vector(size_type n) { - start = allocate_and_fill(n, T()); - finish = start + n; - end_of_storage = finish; - } + vector(size_type n, const T& value) { fill_initialize(n, value); } + vector(int n, const T& value) { fill_initialize(n, value); } + vector(long n, const T& value) { fill_initialize(n, value); } + explicit vector(size_type n) { fill_initialize(n, T()); } + vector(const vector& x) { start = allocate_and_copy(x.end() - x.begin(), x.begin(), x.end()); finish = start + (x.end() - x.begin()); @@ -119,7 +121,7 @@ public: void reserve(size_type n) { if (capacity() < n) { const size_type old_size = size(); - const iterator tmp = allocate_and_copy(n, start, finish); + iterator tmp = allocate_and_copy(n, start, finish); destroy(start, finish); deallocate(); start = tmp; @@ -162,7 +164,15 @@ public: void insert(iterator position, const_iterator first, const_iterator last); #endif /* __STL_MEMBER_TEMPLATES */ - void insert (iterator position, size_type n, const T& x); + + void insert (iterator pos, size_type n, const T& x); + void insert (iterator pos, int n, const T& x) { + insert(pos, (size_type) n, x); + } + void insert (iterator pos, long n, const T& x) { + insert(pos, (size_type) n, x); + } + void pop_back() { --finish; destroy(finish); @@ -291,7 +301,7 @@ template vector& vector::operator=(const vector& x) { if (&x != this) { if (x.size() > capacity()) { - const iterator tmp = allocate_and_copy(x.end() - x.begin(), + iterator tmp = allocate_and_copy(x.end() - x.begin(), x.begin(), x.end()); destroy(start, finish); deallocate(); @@ -323,7 +333,7 @@ void vector::insert_aux(iterator position, const T& x) { else { const size_type old_size = size(); const size_type len = old_size != 0 ? 2 * old_size : 1; - const iterator new_start = data_allocator::allocate(len); + iterator new_start = data_allocator::allocate(len); iterator new_finish = new_start; # ifdef __STL_USE_EXCEPTIONS try { @@ -351,10 +361,10 @@ void vector::insert_aux(iterator position, const T& x) { template void vector::insert(iterator position, size_type n, const T& x) { if (n != 0) { - if (size_type (end_of_storage - finish) >= n) { + if (size_type(end_of_storage - finish) >= n) { T x_copy = x; const size_type elems_after = finish - position; - const iterator old_finish = finish; + iterator old_finish = finish; if (elems_after > n) { uninitialized_copy(finish - n, finish, finish); finish += n; @@ -372,7 +382,7 @@ void vector::insert(iterator position, size_type n, const T& x) { else { const size_type old_size = size(); const size_type len = old_size + max(old_size, n); - const iterator new_start = data_allocator::allocate(len); + iterator new_start = data_allocator::allocate(len); iterator new_finish = new_start; # ifdef __STL_USE_EXCEPTIONS try { @@ -417,9 +427,9 @@ void vector::range_insert(iterator position, if (first != last) { size_type n = 0; distance(first, last, n); - if (size_type (end_of_storage - finish) >= n) { + if (size_type(end_of_storage - finish) >= n) { const size_type elems_after = finish - position; - const iterator old_finish = finish; + iterator old_finish = finish; if (elems_after > n) { uninitialized_copy(finish - n, finish, finish); finish += n; @@ -439,7 +449,7 @@ void vector::range_insert(iterator position, else { const size_type old_size = size(); const size_type len = old_size + max(old_size, n); - const iterator new_start = data_allocator::allocate(len); + iterator new_start = data_allocator::allocate(len); iterator new_finish = new_start; # ifdef __STL_USE_EXCEPTIONS try { @@ -473,9 +483,9 @@ void vector::insert(iterator position, if (first != last) { size_type n = 0; distance(first, last, n); - if (end_of_storage - finish >= n) { + if (size_type(end_of_storage - finish) >= n) { const size_type elems_after = finish - position; - const iterator old_finish = finish; + iterator old_finish = finish; if (elems_after > n) { uninitialized_copy(finish - n, finish, finish); finish += n; @@ -493,7 +503,7 @@ void vector::insert(iterator position, else { const size_type old_size = size(); const size_type len = old_size + max(old_size, n); - const iterator new_start = data_allocator::allocate(len); + iterator new_start = data_allocator::allocate(len); iterator new_finish = new_start; # ifdef __STL_USE_EXCEPTIONS try { -- cgit v1.2.1