Commit 874e7baa by Paolo Carlini Committed by Paolo Carlini

stl_vector.h: Trivial formatting fixes.

2004-04-26  Paolo Carlini  <pcarlini@suse.de>

	* include/bits/stl_vector.h: Trivial formatting fixes.
	* include/bits/vector.tcc: Likewise.

From-SVN: r81178
parent 7c95f621
2004-04-26 Paolo Carlini <pcarlini@suse.de>
* include/bits/stl_vector.h: Trivial formatting fixes.
* include/bits/vector.tcc: Likewise.
2004-04-25 Paolo Carlini <pcarlini@suse.de> 2004-04-25 Paolo Carlini <pcarlini@suse.de>
PR libstdc++/15002 (continued again) PR libstdc++/15002 (continued again)
......
// Vector implementation -*- C++ -*- // 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 // 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 // software; you can redistribute it and/or modify it under the
...@@ -76,7 +76,8 @@ namespace _GLIBCXX_STD ...@@ -76,7 +76,8 @@ namespace _GLIBCXX_STD
struct _Vector_base struct _Vector_base
{ {
struct _Vector_impl struct _Vector_impl
: public _Alloc { : public _Alloc
{
_Tp* _M_start; _Tp* _M_start;
_Tp* _M_finish; _Tp* _M_finish;
_Tp* _M_end_of_storage; _Tp* _M_end_of_storage;
...@@ -89,9 +90,11 @@ namespace _GLIBCXX_STD ...@@ -89,9 +90,11 @@ namespace _GLIBCXX_STD
typedef _Alloc allocator_type; typedef _Alloc allocator_type;
allocator_type allocator_type
get_allocator() const { return *static_cast<const _Alloc*>(&this->_M_impl); } get_allocator() const
{ return *static_cast<const _Alloc*>(&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) _Vector_base(size_t __n, const allocator_type& __a)
...@@ -103,18 +106,21 @@ namespace _GLIBCXX_STD ...@@ -103,18 +106,21 @@ namespace _GLIBCXX_STD
} }
~_Vector_base() ~_Vector_base()
{ _M_deallocate(this->_M_impl._M_start, { _M_deallocate(this->_M_impl._M_start, this->_M_impl._M_end_of_storage
this->_M_impl._M_end_of_storage - this->_M_impl._M_start); } - this->_M_impl._M_start); }
public: public:
_Vector_impl _M_impl; _Vector_impl _M_impl;
_Tp* _Tp*
_M_allocate(size_t __n) { return _M_impl.allocate(__n); } _M_allocate(size_t __n)
{ return _M_impl.allocate(__n); }
void void
_M_deallocate(_Tp* __p, size_t __n) _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 ...@@ -179,7 +185,8 @@ namespace _GLIBCXX_STD
*/ */
explicit explicit
vector(const allocator_type& __a = allocator_type()) vector(const allocator_type& __a = allocator_type())
: _Base(__a) { } : _Base(__a)
{ }
/** /**
* @brief Create a %vector with copies of an exemplar element. * @brief Create a %vector with copies of an exemplar element.
...@@ -191,7 +198,8 @@ namespace _GLIBCXX_STD ...@@ -191,7 +198,8 @@ namespace _GLIBCXX_STD
vector(size_type __n, const value_type& __value, vector(size_type __n, const value_type& __value,
const allocator_type& __a = allocator_type()) const allocator_type& __a = allocator_type())
: _Base(__n, __a) : _Base(__n, __a)
{ this->_M_impl._M_finish = std::uninitialized_fill_n(this->_M_impl._M_start, { this->_M_impl._M_finish = std::uninitialized_fill_n(this->
_M_impl._M_start,
__n, __value); } __n, __value); }
/** /**
...@@ -204,8 +212,10 @@ namespace _GLIBCXX_STD ...@@ -204,8 +212,10 @@ namespace _GLIBCXX_STD
explicit explicit
vector(size_type __n) vector(size_type __n)
: _Base(__n, allocator_type()) : _Base(__n, allocator_type())
{ this->_M_impl._M_finish = std::uninitialized_fill_n(this->_M_impl._M_start, { this->_M_impl._M_finish = std::uninitialized_fill_n(this->
__n, value_type()); } _M_impl._M_start,
__n,
value_type()); }
/** /**
* @brief %Vector copy constructor. * @brief %Vector copy constructor.
...@@ -218,8 +228,10 @@ namespace _GLIBCXX_STD ...@@ -218,8 +228,10 @@ namespace _GLIBCXX_STD
*/ */
vector(const vector& __x) vector(const vector& __x)
: _Base(__x.size(), __x.get_allocator()) : _Base(__x.size(), __x.get_allocator())
{ this->_M_impl._M_finish = std::uninitialized_copy(__x.begin(), __x.end(), { this->_M_impl._M_finish = std::uninitialized_copy(__x.begin(),
this->_M_impl._M_start); __x.end(),
this->
_M_impl._M_start);
} }
/** /**
...@@ -253,7 +265,8 @@ namespace _GLIBCXX_STD ...@@ -253,7 +265,8 @@ namespace _GLIBCXX_STD
* not touched in any way. Managing the pointer is the user's * not touched in any way. Managing the pointer is the user's
* responsibilty. * 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. * @brief %Vector assignment operator.
...@@ -311,7 +324,8 @@ namespace _GLIBCXX_STD ...@@ -311,7 +324,8 @@ namespace _GLIBCXX_STD
* element order. * element order.
*/ */
iterator 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 * Returns a read-only (constant) iterator that points to the
...@@ -319,7 +333,8 @@ namespace _GLIBCXX_STD ...@@ -319,7 +333,8 @@ namespace _GLIBCXX_STD
* element order. * element order.
*/ */
const_iterator 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 * Returns a read/write iterator that points one past the last
...@@ -327,7 +342,8 @@ namespace _GLIBCXX_STD ...@@ -327,7 +342,8 @@ namespace _GLIBCXX_STD
* element order. * element order.
*/ */
iterator 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 * Returns a read-only (constant) iterator that points one past
...@@ -335,7 +351,8 @@ namespace _GLIBCXX_STD ...@@ -335,7 +351,8 @@ namespace _GLIBCXX_STD
* ordinary element order. * ordinary element order.
*/ */
const_iterator 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 * Returns a read/write reverse iterator that points to the
...@@ -343,7 +360,8 @@ namespace _GLIBCXX_STD ...@@ -343,7 +360,8 @@ namespace _GLIBCXX_STD
* element order. * element order.
*/ */
reverse_iterator reverse_iterator
rbegin() { return reverse_iterator(end()); } rbegin()
{ return reverse_iterator(end()); }
/** /**
* Returns a read-only (constant) reverse iterator that points * Returns a read-only (constant) reverse iterator that points
...@@ -351,7 +369,8 @@ namespace _GLIBCXX_STD ...@@ -351,7 +369,8 @@ namespace _GLIBCXX_STD
* reverse element order. * reverse element order.
*/ */
const_reverse_iterator 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 * Returns a read/write reverse iterator that points to one
...@@ -359,7 +378,8 @@ namespace _GLIBCXX_STD ...@@ -359,7 +378,8 @@ namespace _GLIBCXX_STD
* in reverse element order. * in reverse element order.
*/ */
reverse_iterator reverse_iterator
rend() { return reverse_iterator(begin()); } rend()
{ return reverse_iterator(begin()); }
/** /**
* Returns a read-only (constant) reverse iterator that points * Returns a read-only (constant) reverse iterator that points
...@@ -367,16 +387,19 @@ namespace _GLIBCXX_STD ...@@ -367,16 +387,19 @@ namespace _GLIBCXX_STD
* is done in reverse element order. * is done in reverse element order.
*/ */
const_reverse_iterator const_reverse_iterator
rend() const { return const_reverse_iterator(begin()); } rend() const
{ return const_reverse_iterator(begin()); }
// [23.2.4.2] capacity // [23.2.4.2] capacity
/** Returns the number of elements in the %vector. */ /** Returns the number of elements in the %vector. */
size_type size_type
size() const { return size_type(end() - begin()); } size() const
{ return size_type(end() - begin()); }
/** Returns the size() of the largest possible %vector. */ /** Returns the size() of the largest possible %vector. */
size_type 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. * @brief Resizes the %vector to the specified number of elements.
...@@ -409,7 +432,8 @@ namespace _GLIBCXX_STD ...@@ -409,7 +432,8 @@ namespace _GLIBCXX_STD
* default-constructed. * default-constructed.
*/ */
void 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 * Returns the total number of elements that the %vector can
...@@ -417,14 +441,16 @@ namespace _GLIBCXX_STD ...@@ -417,14 +441,16 @@ namespace _GLIBCXX_STD
*/ */
size_type size_type
capacity() const 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 * Returns true if the %vector is empty. (Thus begin() would
* equal end().) * equal end().)
*/ */
bool bool
empty() const { return begin() == end(); } empty() const
{ return begin() == end(); }
/** /**
* @brief Attempt to preallocate enough memory for specified number of * @brief Attempt to preallocate enough memory for specified number of
...@@ -459,7 +485,8 @@ namespace _GLIBCXX_STD ...@@ -459,7 +485,8 @@ namespace _GLIBCXX_STD
* see at().) * see at().)
*/ */
reference 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. * @brief Subscript access to the data contained in the %vector.
...@@ -473,7 +500,8 @@ namespace _GLIBCXX_STD ...@@ -473,7 +500,8 @@ namespace _GLIBCXX_STD
* see at().) * see at().)
*/ */
const_reference const_reference
operator[](size_type __n) const { return *(begin() + __n); } operator[](size_type __n) const
{ return *(begin() + __n); }
protected: protected:
/// @if maint Safety check used only from at(). @endif /// @if maint Safety check used only from at(). @endif
...@@ -497,7 +525,11 @@ namespace _GLIBCXX_STD ...@@ -497,7 +525,11 @@ namespace _GLIBCXX_STD
* function throws out_of_range if the check fails. * function throws out_of_range if the check fails.
*/ */
reference 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. * @brief Provides access to the data contained in the %vector.
...@@ -511,35 +543,43 @@ namespace _GLIBCXX_STD ...@@ -511,35 +543,43 @@ namespace _GLIBCXX_STD
* function throws out_of_range if the check fails. * function throws out_of_range if the check fails.
*/ */
const_reference 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 * Returns a read/write reference to the data at the first
* element of the %vector. * element of the %vector.
*/ */
reference reference
front() { return *begin(); } front()
{ return *begin(); }
/** /**
* Returns a read-only (constant) reference to the data at the first * Returns a read-only (constant) reference to the data at the first
* element of the %vector. * element of the %vector.
*/ */
const_reference const_reference
front() const { return *begin(); } front() const
{ return *begin(); }
/** /**
* Returns a read/write reference to the data at the last * Returns a read/write reference to the data at the last
* element of the %vector. * element of the %vector.
*/ */
reference reference
back() { return *(end() - 1); } back()
{ return *(end() - 1); }
/** /**
* Returns a read-only (constant) reference to the data at the * Returns a read-only (constant) reference to the data at the
* last element of the %vector. * last element of the %vector.
*/ */
const_reference const_reference
back() const { return *(end() - 1); } back() const
{ return *(end() - 1); }
// [23.2.4.3] modifiers // [23.2.4.3] modifiers
/** /**
...@@ -688,7 +728,8 @@ namespace _GLIBCXX_STD ...@@ -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_start, __x._M_impl._M_start);
std::swap(this->_M_impl._M_finish, __x._M_impl._M_finish); 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 ...@@ -698,7 +739,8 @@ namespace _GLIBCXX_STD
* the user's responsibilty. * the user's responsibilty.
*/ */
void void
clear() { erase(begin(), end()); } clear()
{ erase(begin(), end()); }
protected: protected:
/** /**
...@@ -735,7 +777,8 @@ namespace _GLIBCXX_STD ...@@ -735,7 +777,8 @@ namespace _GLIBCXX_STD
{ {
this->_M_impl._M_start = _M_allocate(__n); 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_end_of_storage = this->_M_impl._M_start + __n;
this->_M_impl._M_finish = std::uninitialized_fill_n(this->_M_impl._M_start, this->_M_impl._M_finish = std::uninitialized_fill_n(this->
_M_impl._M_start,
__n, __value); __n, __value);
} }
...@@ -770,7 +813,8 @@ namespace _GLIBCXX_STD ...@@ -770,7 +813,8 @@ namespace _GLIBCXX_STD
this->_M_impl._M_start = this->_M_allocate(__n); 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_end_of_storage = this->_M_impl._M_start + __n;
this->_M_impl._M_finish = std::uninitialized_copy(__first, __last, 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 ...@@ -873,11 +917,9 @@ namespace _GLIBCXX_STD
*/ */
template<typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
inline bool 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.size() == __y.size()
return __x.size() == __y.size() && && std::equal(__x.begin(), __x.end(), __y.begin())); }
std::equal(__x.begin(), __x.end(), __y.begin());
}
/** /**
* @brief Vector ordering relation. * @brief Vector ordering relation.
...@@ -892,40 +934,38 @@ namespace _GLIBCXX_STD ...@@ -892,40 +934,38 @@ namespace _GLIBCXX_STD
*/ */
template<typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
inline bool 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 std::lexicographical_compare(__x.begin(), __x.end(),
return std::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end()); }
__y.begin(), __y.end());
}
/// Based on operator== /// Based on operator==
template<typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
inline bool 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); } { return !(__x == __y); }
/// Based on operator< /// Based on operator<
template<typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
inline bool 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; } { return __y < __x; }
/// Based on operator< /// Based on operator<
template<typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
inline bool 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); } { return !(__y < __x); }
/// Based on operator< /// Based on operator<
template<typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
inline bool 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); } { return !(__x < __y); }
/// See std::vector::swap(). /// See std::vector::swap().
template<typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
inline void inline void
swap(vector<_Tp,_Alloc>& __x, vector<_Tp,_Alloc>& __y) swap(vector<_Tp, _Alloc>& __x, vector<_Tp, _Alloc>& __y)
{ __x.swap(__y); } { __x.swap(__y); }
} // namespace std } // namespace std
......
// Vector implementation (out of line) -*- C++ -*- // 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 // 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 // software; you can redistribute it and/or modify it under the
...@@ -65,7 +65,7 @@ namespace _GLIBCXX_STD ...@@ -65,7 +65,7 @@ namespace _GLIBCXX_STD
{ {
template<typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
void void
vector<_Tp,_Alloc>:: vector<_Tp, _Alloc>::
reserve(size_type __n) reserve(size_type __n)
{ {
if (__n > this->max_size()) if (__n > this->max_size())
...@@ -78,7 +78,8 @@ namespace _GLIBCXX_STD ...@@ -78,7 +78,8 @@ namespace _GLIBCXX_STD
this->_M_impl._M_finish); this->_M_impl._M_finish);
std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish); std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish);
_M_deallocate(this->_M_impl._M_start, _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_start = __tmp;
this->_M_impl._M_finish = __tmp + __old_size; this->_M_impl._M_finish = __tmp + __old_size;
this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __n; this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __n;
...@@ -86,12 +87,13 @@ namespace _GLIBCXX_STD ...@@ -86,12 +87,13 @@ namespace _GLIBCXX_STD
} }
template<typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
typename vector<_Tp,_Alloc>::iterator typename vector<_Tp, _Alloc>::iterator
vector<_Tp,_Alloc>:: vector<_Tp, _Alloc>::
insert(iterator __position, const value_type& __x) insert(iterator __position, const value_type& __x)
{ {
size_type __n = __position - begin(); size_type __n = __position - begin();
if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage && __position == end()) if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage
&& __position == end())
{ {
std::_Construct(this->_M_impl._M_finish, __x); std::_Construct(this->_M_impl._M_finish, __x);
++this->_M_impl._M_finish; ++this->_M_impl._M_finish;
...@@ -102,8 +104,8 @@ namespace _GLIBCXX_STD ...@@ -102,8 +104,8 @@ namespace _GLIBCXX_STD
} }
template<typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
typename vector<_Tp,_Alloc>::iterator typename vector<_Tp, _Alloc>::iterator
vector<_Tp,_Alloc>:: vector<_Tp, _Alloc>::
erase(iterator __position) erase(iterator __position)
{ {
if (__position + 1 != end()) if (__position + 1 != end())
...@@ -114,8 +116,8 @@ namespace _GLIBCXX_STD ...@@ -114,8 +116,8 @@ namespace _GLIBCXX_STD
} }
template<typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
typename vector<_Tp,_Alloc>::iterator typename vector<_Tp, _Alloc>::iterator
vector<_Tp,_Alloc>:: vector<_Tp, _Alloc>::
erase(iterator __first, iterator __last) erase(iterator __first, iterator __last)
{ {
iterator __i(copy(__last, end(), __first)); iterator __i(copy(__last, end(), __first));
...@@ -125,19 +127,22 @@ namespace _GLIBCXX_STD ...@@ -125,19 +127,22 @@ namespace _GLIBCXX_STD
} }
template<typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
vector<_Tp,_Alloc>& vector<_Tp, _Alloc>&
vector<_Tp,_Alloc>:: vector<_Tp, _Alloc>::
operator=(const vector<_Tp,_Alloc>& __x) operator=(const vector<_Tp, _Alloc>& __x)
{ {
if (&__x != this) if (&__x != this)
{ {
const size_type __xlen = __x.size(); const size_type __xlen = __x.size();
if (__xlen > capacity()) if (__xlen > capacity())
{ {
pointer __tmp = _M_allocate_and_copy(__xlen, __x.begin(), __x.end()); pointer __tmp = _M_allocate_and_copy(__xlen, __x.begin(),
std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish); __x.end());
std::_Destroy(this->_M_impl._M_start,
this->_M_impl._M_finish);
_M_deallocate(this->_M_impl._M_start, _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_start = __tmp;
this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __xlen; this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __xlen;
} }
...@@ -148,8 +153,10 @@ namespace _GLIBCXX_STD ...@@ -148,8 +153,10 @@ namespace _GLIBCXX_STD
} }
else else
{ {
std::copy(__x.begin(), __x.begin() + size(), this->_M_impl._M_start); std::copy(__x.begin(), __x.begin() + size(),
std::uninitialized_copy(__x.begin() + size(), __x.end(), this->_M_impl._M_finish); 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; this->_M_impl._M_finish = this->_M_impl._M_start + __xlen;
} }
...@@ -158,7 +165,7 @@ namespace _GLIBCXX_STD ...@@ -158,7 +165,7 @@ namespace _GLIBCXX_STD
template<typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
void void
vector<_Tp,_Alloc>:: vector<_Tp, _Alloc>::
_M_fill_assign(size_t __n, const value_type& __val) _M_fill_assign(size_t __n, const value_type& __val)
{ {
if (__n > capacity()) if (__n > capacity())
...@@ -169,17 +176,21 @@ namespace _GLIBCXX_STD ...@@ -169,17 +176,21 @@ namespace _GLIBCXX_STD
else if (__n > size()) else if (__n > size())
{ {
std::fill(begin(), end(), __val); std::fill(begin(), end(), __val);
this->_M_impl._M_finish this->_M_impl._M_finish = std::uninitialized_fill_n(this->
= std::uninitialized_fill_n(this->_M_impl._M_finish, __n - size(), __val); _M_impl._M_finish,
__n - size(),
__val);
} }
else else
erase(fill_n(begin(), __n, __val), end()); erase(fill_n(begin(), __n, __val), end());
} }
template<typename _Tp, typename _Alloc> template<typename _InputIterator> template<typename _Tp, typename _Alloc>
template<typename _InputIterator>
void void
vector<_Tp,_Alloc>:: vector<_Tp, _Alloc>::
_M_assign_aux(_InputIterator __first, _InputIterator __last, input_iterator_tag) _M_assign_aux(_InputIterator __first, _InputIterator __last,
input_iterator_tag)
{ {
iterator __cur(begin()); iterator __cur(begin());
for ( ; __first != __last && __cur != end(); ++__cur, ++__first) for ( ; __first != __last && __cur != end(); ++__cur, ++__first)
...@@ -190,7 +201,8 @@ namespace _GLIBCXX_STD ...@@ -190,7 +201,8 @@ namespace _GLIBCXX_STD
insert(end(), __first, __last); insert(end(), __first, __last);
} }
template<typename _Tp, typename _Alloc> template<typename _ForwardIterator> template<typename _Tp, typename _Alloc>
template<typename _ForwardIterator>
void void
vector<_Tp,_Alloc>:: vector<_Tp,_Alloc>::
_M_assign_aux(_ForwardIterator __first, _ForwardIterator __last, _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,
...@@ -203,13 +215,16 @@ namespace _GLIBCXX_STD ...@@ -203,13 +215,16 @@ namespace _GLIBCXX_STD
pointer __tmp(_M_allocate_and_copy(__len, __first, __last)); pointer __tmp(_M_allocate_and_copy(__len, __first, __last));
std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish); std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish);
_M_deallocate(this->_M_impl._M_start, _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_start = __tmp;
this->_M_impl._M_end_of_storage = this->_M_impl._M_finish = this->_M_impl._M_start + __len; 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) else if (size() >= __len)
{ {
iterator __new_finish(copy(__first, __last, this->_M_impl._M_start)); iterator __new_finish(copy(__first, __last,
this->_M_impl._M_start));
std::_Destroy(__new_finish, end()); std::_Destroy(__new_finish, end());
this->_M_impl._M_finish = __new_finish.base(); this->_M_impl._M_finish = __new_finish.base();
} }
...@@ -218,7 +233,10 @@ namespace _GLIBCXX_STD ...@@ -218,7 +233,10 @@ namespace _GLIBCXX_STD
_ForwardIterator __mid = __first; _ForwardIterator __mid = __first;
std::advance(__mid, size()); std::advance(__mid, size());
std::copy(__first, __mid, this->_M_impl._M_start); std::copy(__first, __mid, this->_M_impl._M_start);
this->_M_impl._M_finish = std::uninitialized_copy(__mid, __last, this->_M_impl._M_finish); this->_M_impl._M_finish = std::uninitialized_copy(__mid,
__last,
this->_M_impl.
_M_finish);
} }
} }
...@@ -229,7 +247,8 @@ namespace _GLIBCXX_STD ...@@ -229,7 +247,8 @@ namespace _GLIBCXX_STD
{ {
if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage) 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)); std::_Construct(this->_M_impl._M_finish,
*(this->_M_impl._M_finish - 1));
++this->_M_impl._M_finish; ++this->_M_impl._M_finish;
_Tp __x_copy = __x; _Tp __x_copy = __x;
std::copy_backward(__position, std::copy_backward(__position,
...@@ -245,13 +264,15 @@ namespace _GLIBCXX_STD ...@@ -245,13 +264,15 @@ namespace _GLIBCXX_STD
iterator __new_finish(__new_start); iterator __new_finish(__new_start);
try try
{ {
__new_finish = std::uninitialized_copy(iterator(this->_M_impl._M_start), __new_finish = std::uninitialized_copy(iterator(this->
_M_impl._M_start),
__position, __position,
__new_start); __new_start);
std::_Construct(__new_finish.base(), __x); std::_Construct(__new_finish.base(), __x);
++__new_finish; ++__new_finish;
__new_finish = std::uninitialized_copy(__position, __new_finish = std::uninitialized_copy(__position,
iterator(this->_M_impl._M_finish), iterator(this->_M_impl.
_M_finish),
__new_finish); __new_finish);
} }
catch(...) catch(...)
...@@ -262,7 +283,8 @@ namespace _GLIBCXX_STD ...@@ -262,7 +283,8 @@ namespace _GLIBCXX_STD
} }
std::_Destroy(begin(), end()); std::_Destroy(begin(), end());
_M_deallocate(this->_M_impl._M_start, _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 = __new_start.base(); this->_M_impl._M_start = __new_start.base();
this->_M_impl._M_finish = __new_finish.base(); this->_M_impl._M_finish = __new_finish.base();
this->_M_impl._M_end_of_storage = __new_start.base() + __len; this->_M_impl._M_end_of_storage = __new_start.base() + __len;
...@@ -276,7 +298,8 @@ namespace _GLIBCXX_STD ...@@ -276,7 +298,8 @@ namespace _GLIBCXX_STD
{ {
if (__n != 0) if (__n != 0)
{ {
if (size_type(this->_M_impl._M_end_of_storage - this->_M_impl._M_finish) >= __n) if (size_type(this->_M_impl._M_end_of_storage
- this->_M_impl._M_finish) >= __n)
{ {
value_type __x_copy = __x; value_type __x_copy = __x;
const size_type __elems_after = end() - __position; const size_type __elems_after = end() - __position;
...@@ -287,7 +310,8 @@ namespace _GLIBCXX_STD ...@@ -287,7 +310,8 @@ namespace _GLIBCXX_STD
this->_M_impl._M_finish, this->_M_impl._M_finish,
this->_M_impl._M_finish); this->_M_impl._M_finish);
this->_M_impl._M_finish += __n; this->_M_impl._M_finish += __n;
std::copy_backward(__position, __old_finish - __n, __old_finish); std::copy_backward(__position, __old_finish - __n,
__old_finish);
std::fill(__position, __position + __n, __x_copy); std::fill(__position, __position + __n, __x_copy);
} }
else else
...@@ -296,7 +320,8 @@ namespace _GLIBCXX_STD ...@@ -296,7 +320,8 @@ namespace _GLIBCXX_STD
__n - __elems_after, __n - __elems_after,
__x_copy); __x_copy);
this->_M_impl._M_finish += __n - __elems_after; this->_M_impl._M_finish += __n - __elems_after;
std::uninitialized_copy(__position, __old_finish, this->_M_impl._M_finish); std::uninitialized_copy(__position, __old_finish,
this->_M_impl._M_finish);
this->_M_impl._M_finish += __elems_after; this->_M_impl._M_finish += __elems_after;
std::fill(__position, __old_finish, __x_copy); std::fill(__position, __old_finish, __x_copy);
} }
...@@ -311,7 +336,8 @@ namespace _GLIBCXX_STD ...@@ -311,7 +336,8 @@ namespace _GLIBCXX_STD
{ {
__new_finish = std::uninitialized_copy(begin(), __position, __new_finish = std::uninitialized_copy(begin(), __position,
__new_start); __new_start);
__new_finish = std::uninitialized_fill_n(__new_finish, __n, __x); __new_finish = std::uninitialized_fill_n(__new_finish, __n,
__x);
__new_finish = std::uninitialized_copy(__position, end(), __new_finish = std::uninitialized_copy(__position, end(),
__new_finish); __new_finish);
} }
...@@ -323,7 +349,8 @@ namespace _GLIBCXX_STD ...@@ -323,7 +349,8 @@ namespace _GLIBCXX_STD
} }
std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish); std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish);
_M_deallocate(this->_M_impl._M_start, _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 = __new_start.base(); this->_M_impl._M_start = __new_start.base();
this->_M_impl._M_finish = __new_finish.base(); this->_M_impl._M_finish = __new_finish.base();
this->_M_impl._M_end_of_storage = __new_start.base() + __len; this->_M_impl._M_end_of_storage = __new_start.base() + __len;
...@@ -334,9 +361,8 @@ namespace _GLIBCXX_STD ...@@ -334,9 +361,8 @@ namespace _GLIBCXX_STD
template<typename _Tp, typename _Alloc> template<typename _InputIterator> template<typename _Tp, typename _Alloc> template<typename _InputIterator>
void void
vector<_Tp,_Alloc>:: vector<_Tp,_Alloc>::
_M_range_insert(iterator __pos, _M_range_insert(iterator __pos, _InputIterator __first,
_InputIterator __first, _InputIterator __last, _InputIterator __last, input_iterator_tag)
input_iterator_tag)
{ {
for ( ; __first != __last; ++__first) for ( ; __first != __last; ++__first)
{ {
...@@ -345,7 +371,8 @@ namespace _GLIBCXX_STD ...@@ -345,7 +371,8 @@ namespace _GLIBCXX_STD
} }
} }
template<typename _Tp, typename _Alloc> template<typename _ForwardIterator> template<typename _Tp, typename _Alloc>
template<typename _ForwardIterator>
void void
vector<_Tp,_Alloc>:: vector<_Tp,_Alloc>::
_M_range_insert(iterator __position,_ForwardIterator __first, _M_range_insert(iterator __position,_ForwardIterator __first,
...@@ -354,7 +381,8 @@ namespace _GLIBCXX_STD ...@@ -354,7 +381,8 @@ namespace _GLIBCXX_STD
if (__first != __last) if (__first != __last)
{ {
size_type __n = std::distance(__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) if (size_type(this->_M_impl._M_end_of_storage
- this->_M_impl._M_finish) >= __n)
{ {
const size_type __elems_after = end() - __position; const size_type __elems_after = end() - __position;
iterator __old_finish(this->_M_impl._M_finish); iterator __old_finish(this->_M_impl._M_finish);
...@@ -364,16 +392,19 @@ namespace _GLIBCXX_STD ...@@ -364,16 +392,19 @@ namespace _GLIBCXX_STD
this->_M_impl._M_finish, this->_M_impl._M_finish,
this->_M_impl._M_finish); this->_M_impl._M_finish);
this->_M_impl._M_finish += __n; this->_M_impl._M_finish += __n;
std::copy_backward(__position, __old_finish - __n, __old_finish); std::copy_backward(__position, __old_finish - __n,
__old_finish);
std::copy(__first, __last, __position); std::copy(__first, __last, __position);
} }
else else
{ {
_ForwardIterator __mid = __first; _ForwardIterator __mid = __first;
std::advance(__mid, __elems_after); std::advance(__mid, __elems_after);
std::uninitialized_copy(__mid, __last, this->_M_impl._M_finish); std::uninitialized_copy(__mid, __last,
this->_M_impl._M_finish);
this->_M_impl._M_finish += __n - __elems_after; this->_M_impl._M_finish += __n - __elems_after;
std::uninitialized_copy(__position, __old_finish, this->_M_impl._M_finish); std::uninitialized_copy(__position, __old_finish,
this->_M_impl._M_finish);
this->_M_impl._M_finish += __elems_after; this->_M_impl._M_finish += __elems_after;
std::copy(__first, __mid, __position); std::copy(__first, __mid, __position);
} }
...@@ -386,12 +417,17 @@ namespace _GLIBCXX_STD ...@@ -386,12 +417,17 @@ namespace _GLIBCXX_STD
iterator __new_finish(__new_start); iterator __new_finish(__new_start);
try try
{ {
__new_finish = std::uninitialized_copy(iterator(this->_M_impl._M_start), __new_finish = std::uninitialized_copy(iterator(this->
__position, __new_start); _M_impl.
_M_start),
__position,
__new_start);
__new_finish = std::uninitialized_copy(__first, __last, __new_finish = std::uninitialized_copy(__first, __last,
__new_finish); __new_finish);
__new_finish = std::uninitialized_copy(__position, __new_finish = std::uninitialized_copy(__position,
iterator(this->_M_impl._M_finish), iterator(this->
_M_impl.
_M_finish),
__new_finish); __new_finish);
} }
catch(...) catch(...)
...@@ -402,7 +438,8 @@ namespace _GLIBCXX_STD ...@@ -402,7 +438,8 @@ namespace _GLIBCXX_STD
} }
std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish); std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish);
_M_deallocate(this->_M_impl._M_start, _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 = __new_start.base(); this->_M_impl._M_start = __new_start.base();
this->_M_impl._M_finish = __new_finish.base(); this->_M_impl._M_finish = __new_finish.base();
this->_M_impl._M_end_of_storage = __new_start.base() + __len; this->_M_impl._M_end_of_storage = __new_start.base() + __len;
......
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