// 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
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)
{ }
};
typedef _Alloc 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)
- : _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;
}
~_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);
+ }
};
*/
explicit
vector(const allocator_type& __a = allocator_type())
- : _Base(__a) { }
+ : _Base(__a)
+ { }
/**
* @brief Create a %vector with copies of an exemplar element.
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.
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.
*/
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);
}
/**
* 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.
* 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
* 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
* 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
* 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
* element order.
*/
reverse_iterator
- rbegin() { return reverse_iterator(end()); }
+ rbegin()
+ { return reverse_iterator(end()); }
/**
* Returns a read-only (constant) reverse iterator that points
* 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
* 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
* 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.
* 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
*/
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
* 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.
* 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
* 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.
* 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
/**
{
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);
}
/**
* the user's responsibilty.
*/
void
- clear() { erase(begin(), end()); }
+ clear()
+ { erase(begin(), end()); }
protected:
/**
{
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
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);
}
*/
template<typename _Tp, typename _Alloc>
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.
*/
template<typename _Tp, typename _Alloc>
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<typename _Tp, typename _Alloc>
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<typename _Tp, typename _Alloc>
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<typename _Tp, typename _Alloc>
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<typename _Tp, typename _Alloc>
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<typename _Tp, typename _Alloc>
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
// 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
{
template<typename _Tp, typename _Alloc>
void
- vector<_Tp,_Alloc>::
+ vector<_Tp, _Alloc>::
reserve(size_type __n)
{
if (__n > this->max_size())
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;
}
template<typename _Tp, typename _Alloc>
- 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 _Tp, typename _Alloc>
- typename vector<_Tp,_Alloc>::iterator
- vector<_Tp,_Alloc>::
+ typename vector<_Tp, _Alloc>::iterator
+ vector<_Tp, _Alloc>::
erase(iterator __position)
{
if (__position + 1 != end())
}
template<typename _Tp, typename _Alloc>
- 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));
}
template<typename _Tp, typename _Alloc>
- 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<typename _Tp, typename _Alloc>
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<typename _Tp, typename _Alloc> template<typename _InputIterator>
- 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<typename _Tp, typename _Alloc> template<typename _ForwardIterator>
- 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;
- }
- else if (size() >= __len)
+ template<typename _Tp, typename _Alloc>
+ template<typename _InputIterator>
+ void
+ vector<_Tp, _Alloc>::
+ _M_assign_aux(_InputIterator __first, _InputIterator __last,
+ input_iterator_tag)
{
- iterator __new_finish(copy(__first, __last, this->_M_impl._M_start));
- std::_Destroy(__new_finish, end());
- this->_M_impl._M_finish = __new_finish.base();
+ iterator __cur(begin());
+ for ( ; __first != __last && __cur != end(); ++__cur, ++__first)
+ *__cur = *__first;
+ if (__first == __last)
+ erase(__cur, end());
+ else
+ insert(end(), __first, __last);
}
- else
+
+ template<typename _Tp, typename _Alloc>
+ template<typename _ForwardIterator>
+ void
+ vector<_Tp,_Alloc>::
+ _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,
+ forward_iterator_tag)
{
- _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);
+ 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_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);
+ }
}
- }
template<typename _Tp, typename _Alloc>
void
_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);
- }
- catch(...)
- {
- std::_Destroy(__new_start,__new_finish);
- _M_deallocate(__new_start.base(),__len);
- __throw_exception_again;
+ {
+ 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);
}
- 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<typename _Tp, typename _Alloc>
_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<typename _Tp, typename _Alloc> template<typename _InputIterator>
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<typename _Tp, typename _Alloc> template<typename _ForwardIterator>
- void
- vector<_Tp,_Alloc>::
- _M_range_insert(iterator __position,_ForwardIterator __first,
- _ForwardIterator __last, forward_iterator_tag)
- {
- if (__first != __last)
+ template<typename _Tp, typename _Alloc>
+ template<typename _ForwardIterator>
+ 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 */