From 874e7baa4ce28aedab159353f0c40846a7b771e5 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Mon, 26 Apr 2004 09:02:43 +0000 Subject: [PATCH] stl_vector.h: Trivial formatting fixes. 2004-04-26 Paolo Carlini * include/bits/stl_vector.h: Trivial formatting fixes. * include/bits/vector.tcc: Likewise. From-SVN: r81178 --- libstdc++-v3/ChangeLog | 5 + libstdc++-v3/include/bits/stl_vector.h | 160 +++++--- libstdc++-v3/include/bits/vector.tcc | 541 +++++++++++++------------ 3 files changed, 394 insertions(+), 312 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index df302fa9524..22f39492425 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,8 @@ +2004-04-26 Paolo Carlini + + * include/bits/stl_vector.h: Trivial formatting fixes. + * include/bits/vector.tcc: Likewise. + 2004-04-25 Paolo Carlini PR libstdc++/15002 (continued again) diff --git a/libstdc++-v3/include/bits/stl_vector.h b/libstdc++-v3/include/bits/stl_vector.h index b025393a741..8a741b4d9dc 100644 --- a/libstdc++-v3/include/bits/stl_vector.h +++ b/libstdc++-v3/include/bits/stl_vector.h @@ -1,6 +1,6 @@ // Vector implementation -*- C++ -*- -// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. +// Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -76,12 +76,13 @@ namespace _GLIBCXX_STD struct _Vector_base { struct _Vector_impl - : public _Alloc { + : public _Alloc + { _Tp* _M_start; _Tp* _M_finish; _Tp* _M_end_of_storage; _Vector_impl (_Alloc const& __a) - : _Alloc(__a), _M_start(0), _M_finish(0), _M_end_of_storage(0) + : _Alloc(__a), _M_start(0), _M_finish(0), _M_end_of_storage(0) { } }; @@ -89,13 +90,15 @@ namespace _GLIBCXX_STD typedef _Alloc allocator_type; allocator_type - get_allocator() const { return *static_cast(&this->_M_impl); } + get_allocator() const + { return *static_cast(&this->_M_impl); } - _Vector_base(const allocator_type& __a) : _M_impl(__a) + _Vector_base(const allocator_type& __a) + : _M_impl(__a) { } _Vector_base(size_t __n, const allocator_type& __a) - : _M_impl(__a) + : _M_impl(__a) { this->_M_impl._M_start = this->_M_allocate(__n); this->_M_impl._M_finish = this->_M_impl._M_start; @@ -103,18 +106,21 @@ namespace _GLIBCXX_STD } ~_Vector_base() - { _M_deallocate(this->_M_impl._M_start, - this->_M_impl._M_end_of_storage - this->_M_impl._M_start); } + { _M_deallocate(this->_M_impl._M_start, this->_M_impl._M_end_of_storage + - this->_M_impl._M_start); } public: _Vector_impl _M_impl; _Tp* - _M_allocate(size_t __n) { return _M_impl.allocate(__n); } + _M_allocate(size_t __n) + { return _M_impl.allocate(__n); } void _M_deallocate(_Tp* __p, size_t __n) - { if (__p) _M_impl.deallocate(__p, __n); } + { if (__p) + _M_impl.deallocate(__p, __n); + } }; @@ -179,7 +185,8 @@ namespace _GLIBCXX_STD */ explicit vector(const allocator_type& __a = allocator_type()) - : _Base(__a) { } + : _Base(__a) + { } /** * @brief Create a %vector with copies of an exemplar element. @@ -191,8 +198,9 @@ namespace _GLIBCXX_STD vector(size_type __n, const value_type& __value, const allocator_type& __a = allocator_type()) : _Base(__n, __a) - { this->_M_impl._M_finish = std::uninitialized_fill_n(this->_M_impl._M_start, - __n, __value); } + { this->_M_impl._M_finish = std::uninitialized_fill_n(this-> + _M_impl._M_start, + __n, __value); } /** * @brief Create a %vector with default elements. @@ -204,8 +212,10 @@ namespace _GLIBCXX_STD explicit vector(size_type __n) : _Base(__n, allocator_type()) - { this->_M_impl._M_finish = std::uninitialized_fill_n(this->_M_impl._M_start, - __n, value_type()); } + { this->_M_impl._M_finish = std::uninitialized_fill_n(this-> + _M_impl._M_start, + __n, + value_type()); } /** * @brief %Vector copy constructor. @@ -218,8 +228,10 @@ namespace _GLIBCXX_STD */ vector(const vector& __x) : _Base(__x.size(), __x.get_allocator()) - { this->_M_impl._M_finish = std::uninitialized_copy(__x.begin(), __x.end(), - this->_M_impl._M_start); + { this->_M_impl._M_finish = std::uninitialized_copy(__x.begin(), + __x.end(), + this-> + _M_impl._M_start); } /** @@ -253,7 +265,8 @@ namespace _GLIBCXX_STD * not touched in any way. Managing the pointer is the user's * responsibilty. */ - ~vector() { std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish); } + ~vector() + { std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish); } /** * @brief %Vector assignment operator. @@ -311,7 +324,8 @@ namespace _GLIBCXX_STD * element order. */ iterator - begin() { return iterator (this->_M_impl._M_start); } + begin() + { return iterator (this->_M_impl._M_start); } /** * Returns a read-only (constant) iterator that points to the @@ -319,7 +333,8 @@ namespace _GLIBCXX_STD * element order. */ const_iterator - begin() const { return const_iterator (this->_M_impl._M_start); } + begin() const + { return const_iterator (this->_M_impl._M_start); } /** * Returns a read/write iterator that points one past the last @@ -327,7 +342,8 @@ namespace _GLIBCXX_STD * element order. */ iterator - end() { return iterator (this->_M_impl._M_finish); } + end() + { return iterator (this->_M_impl._M_finish); } /** * Returns a read-only (constant) iterator that points one past @@ -335,7 +351,8 @@ namespace _GLIBCXX_STD * ordinary element order. */ const_iterator - end() const { return const_iterator (this->_M_impl._M_finish); } + end() const + { return const_iterator (this->_M_impl._M_finish); } /** * Returns a read/write reverse iterator that points to the @@ -343,7 +360,8 @@ namespace _GLIBCXX_STD * element order. */ reverse_iterator - rbegin() { return reverse_iterator(end()); } + rbegin() + { return reverse_iterator(end()); } /** * Returns a read-only (constant) reverse iterator that points @@ -351,7 +369,8 @@ namespace _GLIBCXX_STD * reverse element order. */ const_reverse_iterator - rbegin() const { return const_reverse_iterator(end()); } + rbegin() const + { return const_reverse_iterator(end()); } /** * Returns a read/write reverse iterator that points to one @@ -359,7 +378,8 @@ namespace _GLIBCXX_STD * in reverse element order. */ reverse_iterator - rend() { return reverse_iterator(begin()); } + rend() + { return reverse_iterator(begin()); } /** * Returns a read-only (constant) reverse iterator that points @@ -367,16 +387,19 @@ namespace _GLIBCXX_STD * is done in reverse element order. */ const_reverse_iterator - rend() const { return const_reverse_iterator(begin()); } + rend() const + { return const_reverse_iterator(begin()); } // [23.2.4.2] capacity /** Returns the number of elements in the %vector. */ size_type - size() const { return size_type(end() - begin()); } + size() const + { return size_type(end() - begin()); } /** Returns the size() of the largest possible %vector. */ size_type - max_size() const { return size_type(-1) / sizeof(value_type); } + max_size() const + { return size_type(-1) / sizeof(value_type); } /** * @brief Resizes the %vector to the specified number of elements. @@ -409,7 +432,8 @@ namespace _GLIBCXX_STD * default-constructed. */ void - resize(size_type __new_size) { resize(__new_size, value_type()); } + resize(size_type __new_size) + { resize(__new_size, value_type()); } /** * Returns the total number of elements that the %vector can @@ -417,14 +441,16 @@ namespace _GLIBCXX_STD */ size_type capacity() const - { return size_type(const_iterator(this->_M_impl._M_end_of_storage) - begin()); } + { return size_type(const_iterator(this->_M_impl._M_end_of_storage) + - begin()); } /** * Returns true if the %vector is empty. (Thus begin() would * equal end().) */ bool - empty() const { return begin() == end(); } + empty() const + { return begin() == end(); } /** * @brief Attempt to preallocate enough memory for specified number of @@ -459,7 +485,8 @@ namespace _GLIBCXX_STD * see at().) */ reference - operator[](size_type __n) { return *(begin() + __n); } + operator[](size_type __n) + { return *(begin() + __n); } /** * @brief Subscript access to the data contained in the %vector. @@ -473,7 +500,8 @@ namespace _GLIBCXX_STD * see at().) */ const_reference - operator[](size_type __n) const { return *(begin() + __n); } + operator[](size_type __n) const + { return *(begin() + __n); } protected: /// @if maint Safety check used only from at(). @endif @@ -497,7 +525,11 @@ namespace _GLIBCXX_STD * function throws out_of_range if the check fails. */ reference - at(size_type __n) { _M_range_check(__n); return (*this)[__n]; } + at(size_type __n) + { + _M_range_check(__n); + return (*this)[__n]; + } /** * @brief Provides access to the data contained in the %vector. @@ -511,35 +543,43 @@ namespace _GLIBCXX_STD * function throws out_of_range if the check fails. */ const_reference - at(size_type __n) const { _M_range_check(__n); return (*this)[__n]; } + at(size_type __n) const + { + _M_range_check(__n); + return (*this)[__n]; + } /** * Returns a read/write reference to the data at the first * element of the %vector. */ reference - front() { return *begin(); } + front() + { return *begin(); } /** * Returns a read-only (constant) reference to the data at the first * element of the %vector. */ const_reference - front() const { return *begin(); } + front() const + { return *begin(); } /** * Returns a read/write reference to the data at the last * element of the %vector. */ reference - back() { return *(end() - 1); } - + back() + { return *(end() - 1); } + /** * Returns a read-only (constant) reference to the data at the * last element of the %vector. */ const_reference - back() const { return *(end() - 1); } + back() const + { return *(end() - 1); } // [23.2.4.3] modifiers /** @@ -688,7 +728,8 @@ namespace _GLIBCXX_STD { std::swap(this->_M_impl._M_start, __x._M_impl._M_start); std::swap(this->_M_impl._M_finish, __x._M_impl._M_finish); - std::swap(this->_M_impl._M_end_of_storage, __x._M_impl._M_end_of_storage); + std::swap(this->_M_impl._M_end_of_storage, + __x._M_impl._M_end_of_storage); } /** @@ -698,7 +739,8 @@ namespace _GLIBCXX_STD * the user's responsibilty. */ void - clear() { erase(begin(), end()); } + clear() + { erase(begin(), end()); } protected: /** @@ -735,8 +777,9 @@ namespace _GLIBCXX_STD { this->_M_impl._M_start = _M_allocate(__n); this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __n; - this->_M_impl._M_finish = std::uninitialized_fill_n(this->_M_impl._M_start, - __n, __value); + this->_M_impl._M_finish = std::uninitialized_fill_n(this-> + _M_impl._M_start, + __n, __value); } // Called by the range constructor to implement [23.1.1]/9 @@ -770,7 +813,8 @@ namespace _GLIBCXX_STD this->_M_impl._M_start = this->_M_allocate(__n); this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __n; this->_M_impl._M_finish = std::uninitialized_copy(__first, __last, - this->_M_impl._M_start); + this-> + _M_impl._M_start); } @@ -873,11 +917,9 @@ namespace _GLIBCXX_STD */ template inline bool - operator==(const vector<_Tp,_Alloc>& __x, const vector<_Tp,_Alloc>& __y) - { - return __x.size() == __y.size() && - std::equal(__x.begin(), __x.end(), __y.begin()); - } + operator==(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y) + { return (__x.size() == __y.size() + && std::equal(__x.begin(), __x.end(), __y.begin())); } /** * @brief Vector ordering relation. @@ -892,40 +934,38 @@ namespace _GLIBCXX_STD */ template inline bool - operator<(const vector<_Tp,_Alloc>& __x, const vector<_Tp,_Alloc>& __y) - { - return std::lexicographical_compare(__x.begin(), __x.end(), - __y.begin(), __y.end()); - } + operator<(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y) + { return std::lexicographical_compare(__x.begin(), __x.end(), + __y.begin(), __y.end()); } /// Based on operator== template inline bool - operator!=(const vector<_Tp,_Alloc>& __x, const vector<_Tp,_Alloc>& __y) + operator!=(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y) { return !(__x == __y); } /// Based on operator< template inline bool - operator>(const vector<_Tp,_Alloc>& __x, const vector<_Tp,_Alloc>& __y) + operator>(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y) { return __y < __x; } /// Based on operator< template inline bool - operator<=(const vector<_Tp,_Alloc>& __x, const vector<_Tp,_Alloc>& __y) + operator<=(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y) { return !(__y < __x); } /// Based on operator< template inline bool - operator>=(const vector<_Tp,_Alloc>& __x, const vector<_Tp,_Alloc>& __y) + operator>=(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y) { return !(__x < __y); } /// See std::vector::swap(). template inline void - swap(vector<_Tp,_Alloc>& __x, vector<_Tp,_Alloc>& __y) + swap(vector<_Tp, _Alloc>& __x, vector<_Tp, _Alloc>& __y) { __x.swap(__y); } } // namespace std diff --git a/libstdc++-v3/include/bits/vector.tcc b/libstdc++-v3/include/bits/vector.tcc index abd1ba76250..5e8b9a7108d 100644 --- a/libstdc++-v3/include/bits/vector.tcc +++ b/libstdc++-v3/include/bits/vector.tcc @@ -1,6 +1,6 @@ // Vector implementation (out of line) -*- C++ -*- -// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. +// Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -65,7 +65,7 @@ namespace _GLIBCXX_STD { template void - vector<_Tp,_Alloc>:: + vector<_Tp, _Alloc>:: reserve(size_type __n) { if (__n > this->max_size()) @@ -78,7 +78,8 @@ namespace _GLIBCXX_STD this->_M_impl._M_finish); std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish); _M_deallocate(this->_M_impl._M_start, - this->_M_impl._M_end_of_storage - this->_M_impl._M_start); + this->_M_impl._M_end_of_storage + - this->_M_impl._M_start); this->_M_impl._M_start = __tmp; this->_M_impl._M_finish = __tmp + __old_size; this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __n; @@ -86,24 +87,25 @@ namespace _GLIBCXX_STD } template - typename vector<_Tp,_Alloc>::iterator - vector<_Tp,_Alloc>:: + typename vector<_Tp, _Alloc>::iterator + vector<_Tp, _Alloc>:: insert(iterator __position, const value_type& __x) { size_type __n = __position - begin(); - if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage && __position == end()) - { - std::_Construct(this->_M_impl._M_finish, __x); - ++this->_M_impl._M_finish; - } + if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage + && __position == end()) + { + std::_Construct(this->_M_impl._M_finish, __x); + ++this->_M_impl._M_finish; + } else _M_insert_aux(__position, __x); return begin() + __n; } template - typename vector<_Tp,_Alloc>::iterator - vector<_Tp,_Alloc>:: + typename vector<_Tp, _Alloc>::iterator + vector<_Tp, _Alloc>:: erase(iterator __position) { if (__position + 1 != end()) @@ -114,8 +116,8 @@ namespace _GLIBCXX_STD } template - typename vector<_Tp,_Alloc>::iterator - vector<_Tp,_Alloc>:: + typename vector<_Tp, _Alloc>::iterator + vector<_Tp, _Alloc>:: erase(iterator __first, iterator __last) { iterator __i(copy(__last, end(), __first)); @@ -125,102 +127,118 @@ namespace _GLIBCXX_STD } template - vector<_Tp,_Alloc>& - vector<_Tp,_Alloc>:: - operator=(const vector<_Tp,_Alloc>& __x) + vector<_Tp, _Alloc>& + vector<_Tp, _Alloc>:: + operator=(const vector<_Tp, _Alloc>& __x) { if (&__x != this) - { - const size_type __xlen = __x.size(); - if (__xlen > capacity()) - { - pointer __tmp = _M_allocate_and_copy(__xlen, __x.begin(), __x.end()); - std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish); - _M_deallocate(this->_M_impl._M_start, - this->_M_impl._M_end_of_storage - this->_M_impl._M_start); - this->_M_impl._M_start = __tmp; - this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __xlen; - } - else if (size() >= __xlen) - { - iterator __i(copy(__x.begin(), __x.end(), begin())); - std::_Destroy(__i, end()); - } - else - { - std::copy(__x.begin(), __x.begin() + size(), this->_M_impl._M_start); - std::uninitialized_copy(__x.begin() + size(), __x.end(), this->_M_impl._M_finish); - } - this->_M_impl._M_finish = this->_M_impl._M_start + __xlen; - } + { + const size_type __xlen = __x.size(); + if (__xlen > capacity()) + { + pointer __tmp = _M_allocate_and_copy(__xlen, __x.begin(), + __x.end()); + std::_Destroy(this->_M_impl._M_start, + this->_M_impl._M_finish); + _M_deallocate(this->_M_impl._M_start, + this->_M_impl._M_end_of_storage + - this->_M_impl._M_start); + this->_M_impl._M_start = __tmp; + this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __xlen; + } + else if (size() >= __xlen) + { + iterator __i(copy(__x.begin(), __x.end(), begin())); + std::_Destroy(__i, end()); + } + else + { + std::copy(__x.begin(), __x.begin() + size(), + this->_M_impl._M_start); + std::uninitialized_copy(__x.begin() + size(), + __x.end(), this->_M_impl._M_finish); + } + this->_M_impl._M_finish = this->_M_impl._M_start + __xlen; + } return *this; } template void - vector<_Tp,_Alloc>:: + vector<_Tp, _Alloc>:: _M_fill_assign(size_t __n, const value_type& __val) { if (__n > capacity()) - { - vector __tmp(__n, __val, get_allocator()); - __tmp.swap(*this); - } + { + vector __tmp(__n, __val, get_allocator()); + __tmp.swap(*this); + } else if (__n > size()) - { - std::fill(begin(), end(), __val); - this->_M_impl._M_finish - = std::uninitialized_fill_n(this->_M_impl._M_finish, __n - size(), __val); - } + { + std::fill(begin(), end(), __val); + this->_M_impl._M_finish = std::uninitialized_fill_n(this-> + _M_impl._M_finish, + __n - size(), + __val); + } else erase(fill_n(begin(), __n, __val), end()); } - template template - void - vector<_Tp,_Alloc>:: - _M_assign_aux(_InputIterator __first, _InputIterator __last, input_iterator_tag) - { - iterator __cur(begin()); - for ( ; __first != __last && __cur != end(); ++__cur, ++__first) - *__cur = *__first; - if (__first == __last) - erase(__cur, end()); - else - insert(end(), __first, __last); - } + template + template + void + vector<_Tp, _Alloc>:: + _M_assign_aux(_InputIterator __first, _InputIterator __last, + input_iterator_tag) + { + iterator __cur(begin()); + for ( ; __first != __last && __cur != end(); ++__cur, ++__first) + *__cur = *__first; + if (__first == __last) + erase(__cur, end()); + else + insert(end(), __first, __last); + } - template template - void - vector<_Tp,_Alloc>:: - _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last, - forward_iterator_tag) - { - size_type __len = std::distance(__first, __last); + template + template + void + vector<_Tp,_Alloc>:: + _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last, + forward_iterator_tag) + { + size_type __len = std::distance(__first, __last); - if (__len > capacity()) - { - pointer __tmp(_M_allocate_and_copy(__len, __first, __last)); - std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish); - _M_deallocate(this->_M_impl._M_start, - this->_M_impl._M_end_of_storage - this->_M_impl._M_start); - this->_M_impl._M_start = __tmp; - this->_M_impl._M_end_of_storage = this->_M_impl._M_finish = this->_M_impl._M_start + __len; + if (__len > capacity()) + { + pointer __tmp(_M_allocate_and_copy(__len, __first, __last)); + std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish); + _M_deallocate(this->_M_impl._M_start, + this->_M_impl._M_end_of_storage + - this->_M_impl._M_start); + this->_M_impl._M_start = __tmp; + this->_M_impl._M_finish = this->_M_impl._M_start + __len; + this->_M_impl._M_end_of_storage = this->_M_impl._M_finish; + } + else if (size() >= __len) + { + iterator __new_finish(copy(__first, __last, + this->_M_impl._M_start)); + std::_Destroy(__new_finish, end()); + this->_M_impl._M_finish = __new_finish.base(); + } + else + { + _ForwardIterator __mid = __first; + std::advance(__mid, size()); + std::copy(__first, __mid, this->_M_impl._M_start); + this->_M_impl._M_finish = std::uninitialized_copy(__mid, + __last, + this->_M_impl. + _M_finish); + } } - else if (size() >= __len) - { - iterator __new_finish(copy(__first, __last, this->_M_impl._M_start)); - std::_Destroy(__new_finish, end()); - this->_M_impl._M_finish = __new_finish.base(); - } - else - { - _ForwardIterator __mid = __first; - std::advance(__mid, size()); - std::copy(__first, __mid, this->_M_impl._M_start); - this->_M_impl._M_finish = std::uninitialized_copy(__mid, __last, this->_M_impl._M_finish); - } - } template void @@ -228,45 +246,49 @@ namespace _GLIBCXX_STD _M_insert_aux(iterator __position, const _Tp& __x) { if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage) - { - std::_Construct(this->_M_impl._M_finish, *(this->_M_impl._M_finish - 1)); - ++this->_M_impl._M_finish; - _Tp __x_copy = __x; - std::copy_backward(__position, - iterator(this->_M_impl._M_finish-2), - iterator(this->_M_impl._M_finish-1)); - *__position = __x_copy; - } + { + std::_Construct(this->_M_impl._M_finish, + *(this->_M_impl._M_finish - 1)); + ++this->_M_impl._M_finish; + _Tp __x_copy = __x; + std::copy_backward(__position, + iterator(this->_M_impl._M_finish-2), + iterator(this->_M_impl._M_finish-1)); + *__position = __x_copy; + } else - { - const size_type __old_size = size(); - const size_type __len = __old_size != 0 ? 2 * __old_size : 1; - iterator __new_start(this->_M_allocate(__len)); - iterator __new_finish(__new_start); - try - { - __new_finish = std::uninitialized_copy(iterator(this->_M_impl._M_start), - __position, - __new_start); - std::_Construct(__new_finish.base(), __x); - ++__new_finish; - __new_finish = std::uninitialized_copy(__position, - iterator(this->_M_impl._M_finish), - __new_finish); + { + const size_type __old_size = size(); + const size_type __len = __old_size != 0 ? 2 * __old_size : 1; + iterator __new_start(this->_M_allocate(__len)); + iterator __new_finish(__new_start); + try + { + __new_finish = std::uninitialized_copy(iterator(this-> + _M_impl._M_start), + __position, + __new_start); + std::_Construct(__new_finish.base(), __x); + ++__new_finish; + __new_finish = std::uninitialized_copy(__position, + iterator(this->_M_impl. + _M_finish), + __new_finish); } - catch(...) - { - std::_Destroy(__new_start,__new_finish); - _M_deallocate(__new_start.base(),__len); - __throw_exception_again; - } - std::_Destroy(begin(), end()); - _M_deallocate(this->_M_impl._M_start, - this->_M_impl._M_end_of_storage - this->_M_impl._M_start); - this->_M_impl._M_start = __new_start.base(); - this->_M_impl._M_finish = __new_finish.base(); - this->_M_impl._M_end_of_storage = __new_start.base() + __len; - } + catch(...) + { + std::_Destroy(__new_start,__new_finish); + _M_deallocate(__new_start.base(),__len); + __throw_exception_again; + } + std::_Destroy(begin(), end()); + _M_deallocate(this->_M_impl._M_start, + this->_M_impl._M_end_of_storage + - this->_M_impl._M_start); + this->_M_impl._M_start = __new_start.base(); + this->_M_impl._M_finish = __new_finish.base(); + this->_M_impl._M_end_of_storage = __new_start.base() + __len; + } } template @@ -275,140 +297,155 @@ namespace _GLIBCXX_STD _M_fill_insert(iterator __position, size_type __n, const value_type& __x) { if (__n != 0) - { - if (size_type(this->_M_impl._M_end_of_storage - this->_M_impl._M_finish) >= __n) - { - value_type __x_copy = __x; - const size_type __elems_after = end() - __position; - iterator __old_finish(this->_M_impl._M_finish); - if (__elems_after > __n) - { - std::uninitialized_copy(this->_M_impl._M_finish - __n, - this->_M_impl._M_finish, - this->_M_impl._M_finish); - this->_M_impl._M_finish += __n; - std::copy_backward(__position, __old_finish - __n, __old_finish); - std::fill(__position, __position + __n, __x_copy); - } - else - { - std::uninitialized_fill_n(this->_M_impl._M_finish, - __n - __elems_after, - __x_copy); - this->_M_impl._M_finish += __n - __elems_after; - std::uninitialized_copy(__position, __old_finish, this->_M_impl._M_finish); - this->_M_impl._M_finish += __elems_after; - std::fill(__position, __old_finish, __x_copy); - } - } - else - { - const size_type __old_size = size(); - const size_type __len = __old_size + std::max(__old_size, __n); - iterator __new_start(this->_M_allocate(__len)); - iterator __new_finish(__new_start); - try - { - __new_finish = std::uninitialized_copy(begin(), __position, - __new_start); - __new_finish = std::uninitialized_fill_n(__new_finish, __n, __x); - __new_finish = std::uninitialized_copy(__position, end(), - __new_finish); - } - catch(...) - { - std::_Destroy(__new_start,__new_finish); - _M_deallocate(__new_start.base(),__len); - __throw_exception_again; - } - std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish); - _M_deallocate(this->_M_impl._M_start, - this->_M_impl._M_end_of_storage - this->_M_impl._M_start); - this->_M_impl._M_start = __new_start.base(); - this->_M_impl._M_finish = __new_finish.base(); - this->_M_impl._M_end_of_storage = __new_start.base() + __len; - } - } + { + if (size_type(this->_M_impl._M_end_of_storage + - this->_M_impl._M_finish) >= __n) + { + value_type __x_copy = __x; + const size_type __elems_after = end() - __position; + iterator __old_finish(this->_M_impl._M_finish); + if (__elems_after > __n) + { + std::uninitialized_copy(this->_M_impl._M_finish - __n, + this->_M_impl._M_finish, + this->_M_impl._M_finish); + this->_M_impl._M_finish += __n; + std::copy_backward(__position, __old_finish - __n, + __old_finish); + std::fill(__position, __position + __n, __x_copy); + } + else + { + std::uninitialized_fill_n(this->_M_impl._M_finish, + __n - __elems_after, + __x_copy); + this->_M_impl._M_finish += __n - __elems_after; + std::uninitialized_copy(__position, __old_finish, + this->_M_impl._M_finish); + this->_M_impl._M_finish += __elems_after; + std::fill(__position, __old_finish, __x_copy); + } + } + else + { + const size_type __old_size = size(); + const size_type __len = __old_size + std::max(__old_size, __n); + iterator __new_start(this->_M_allocate(__len)); + iterator __new_finish(__new_start); + try + { + __new_finish = std::uninitialized_copy(begin(), __position, + __new_start); + __new_finish = std::uninitialized_fill_n(__new_finish, __n, + __x); + __new_finish = std::uninitialized_copy(__position, end(), + __new_finish); + } + catch(...) + { + std::_Destroy(__new_start,__new_finish); + _M_deallocate(__new_start.base(),__len); + __throw_exception_again; + } + std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish); + _M_deallocate(this->_M_impl._M_start, + this->_M_impl._M_end_of_storage + - this->_M_impl._M_start); + this->_M_impl._M_start = __new_start.base(); + this->_M_impl._M_finish = __new_finish.base(); + this->_M_impl._M_end_of_storage = __new_start.base() + __len; + } + } } template template void vector<_Tp,_Alloc>:: - _M_range_insert(iterator __pos, - _InputIterator __first, _InputIterator __last, - input_iterator_tag) + _M_range_insert(iterator __pos, _InputIterator __first, + _InputIterator __last, input_iterator_tag) { for ( ; __first != __last; ++__first) - { - __pos = insert(__pos, *__first); - ++__pos; - } + { + __pos = insert(__pos, *__first); + ++__pos; + } } - template template - void - vector<_Tp,_Alloc>:: - _M_range_insert(iterator __position,_ForwardIterator __first, - _ForwardIterator __last, forward_iterator_tag) - { - if (__first != __last) + template + template + void + vector<_Tp,_Alloc>:: + _M_range_insert(iterator __position,_ForwardIterator __first, + _ForwardIterator __last, forward_iterator_tag) { - size_type __n = std::distance(__first, __last); - if (size_type(this->_M_impl._M_end_of_storage - this->_M_impl._M_finish) >= __n) - { - const size_type __elems_after = end() - __position; - iterator __old_finish(this->_M_impl._M_finish); - if (__elems_after > __n) - { - std::uninitialized_copy(this->_M_impl._M_finish - __n, - this->_M_impl._M_finish, - this->_M_impl._M_finish); - this->_M_impl._M_finish += __n; - std::copy_backward(__position, __old_finish - __n, __old_finish); - std::copy(__first, __last, __position); - } - else - { - _ForwardIterator __mid = __first; - std::advance(__mid, __elems_after); - std::uninitialized_copy(__mid, __last, this->_M_impl._M_finish); - this->_M_impl._M_finish += __n - __elems_after; - std::uninitialized_copy(__position, __old_finish, this->_M_impl._M_finish); - this->_M_impl._M_finish += __elems_after; - std::copy(__first, __mid, __position); - } - } - else - { - const size_type __old_size = size(); - const size_type __len = __old_size + std::max(__old_size, __n); - iterator __new_start(this->_M_allocate(__len)); - iterator __new_finish(__new_start); - try - { - __new_finish = std::uninitialized_copy(iterator(this->_M_impl._M_start), - __position, __new_start); - __new_finish = std::uninitialized_copy(__first, __last, - __new_finish); - __new_finish = std::uninitialized_copy(__position, - iterator(this->_M_impl._M_finish), - __new_finish); - } - catch(...) - { - std::_Destroy(__new_start,__new_finish); - _M_deallocate(__new_start.base(), __len); - __throw_exception_again; - } - std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish); - _M_deallocate(this->_M_impl._M_start, - this->_M_impl._M_end_of_storage - this->_M_impl._M_start); - this->_M_impl._M_start = __new_start.base(); - this->_M_impl._M_finish = __new_finish.base(); - this->_M_impl._M_end_of_storage = __new_start.base() + __len; - } + if (__first != __last) + { + size_type __n = std::distance(__first, __last); + if (size_type(this->_M_impl._M_end_of_storage + - this->_M_impl._M_finish) >= __n) + { + const size_type __elems_after = end() - __position; + iterator __old_finish(this->_M_impl._M_finish); + if (__elems_after > __n) + { + std::uninitialized_copy(this->_M_impl._M_finish - __n, + this->_M_impl._M_finish, + this->_M_impl._M_finish); + this->_M_impl._M_finish += __n; + std::copy_backward(__position, __old_finish - __n, + __old_finish); + std::copy(__first, __last, __position); + } + else + { + _ForwardIterator __mid = __first; + std::advance(__mid, __elems_after); + std::uninitialized_copy(__mid, __last, + this->_M_impl._M_finish); + this->_M_impl._M_finish += __n - __elems_after; + std::uninitialized_copy(__position, __old_finish, + this->_M_impl._M_finish); + this->_M_impl._M_finish += __elems_after; + std::copy(__first, __mid, __position); + } + } + else + { + const size_type __old_size = size(); + const size_type __len = __old_size + std::max(__old_size, __n); + iterator __new_start(this->_M_allocate(__len)); + iterator __new_finish(__new_start); + try + { + __new_finish = std::uninitialized_copy(iterator(this-> + _M_impl. + _M_start), + __position, + __new_start); + __new_finish = std::uninitialized_copy(__first, __last, + __new_finish); + __new_finish = std::uninitialized_copy(__position, + iterator(this-> + _M_impl. + _M_finish), + __new_finish); + } + catch(...) + { + std::_Destroy(__new_start,__new_finish); + _M_deallocate(__new_start.base(), __len); + __throw_exception_again; + } + std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish); + _M_deallocate(this->_M_impl._M_start, + this->_M_impl._M_end_of_storage + - this->_M_impl._M_start); + this->_M_impl._M_start = __new_start.base(); + this->_M_impl._M_finish = __new_finish.base(); + this->_M_impl._M_end_of_storage = __new_start.base() + __len; + } + } } - } } // namespace std #endif /* _VECTOR_TCC */