re PR libstdc++/24617 (vector vs __erase_at_end)

2005-12-08  Paolo Carlini  <pcarlini@suse.de>

	* include/bits/stl_vector.h (vector<>::size, resize, capacity,
	operator[]): Avoid troubles with ADL, user defined operators
	and __normal_iterator.
	(_M_erase_at_end): Fix to take a pointer.
	(clear): Adjust call.
	* include/bits/vector.tcc (vector<>::insert(iterator, const
	value_type&), erase(iterator, iterator), operator=(const
	vector<>&), _M_assign_aux(input_iterator_tag), _M_insert_aux,
	_M_fill_insert, _M_range_insert): Likewise.
	(_M_fill_assign, _M_assign_aux(forward_iterator_tag)): Adjust
	_M_erase_at_end call.
	* testsuite/23_containers/vector/types/1.cc: New.

2005-12-08  Paolo Carlini  <pcarlini@suse.de>

	PR libstdc++/24617
	* include/bits/stl_vector.h (vector<>::_M_erase_at_end): New.
	(vector<>::clear, resize): Use it.
	* include/bits/vector.tcc (vector<>::erase(iterator, iterator),
	_M_fill_assign, _M_assign_aux): Likewise.

	* testsuite/23_containers/vector/modifiers/erase/1.cc: New.

From-SVN: r108227
This commit is contained in:
Paolo Carlini 2005-12-08 11:32:37 +00:00 committed by Paolo Carlini
parent b2a93c0a5a
commit bc9053abce
5 changed files with 303 additions and 81 deletions

View file

@ -1,3 +1,28 @@
2005-12-08 Paolo Carlini <pcarlini@suse.de>
* include/bits/stl_vector.h (vector<>::size, resize, capacity,
operator[]): Avoid troubles with ADL, user defined operators
and __normal_iterator.
(_M_erase_at_end): Fix to take a pointer.
(clear): Adjust call.
* include/bits/vector.tcc (vector<>::insert(iterator, const
value_type&), erase(iterator, iterator), operator=(const
vector<>&), _M_assign_aux(input_iterator_tag), _M_insert_aux,
_M_fill_insert, _M_range_insert): Likewise.
(_M_fill_assign, _M_assign_aux(forward_iterator_tag)): Adjust
_M_erase_at_end call.
* testsuite/23_containers/vector/types/1.cc: New.
2005-12-08 Paolo Carlini <pcarlini@suse.de>
PR libstdc++/24617
* include/bits/stl_vector.h (vector<>::_M_erase_at_end): New.
(vector<>::clear, resize): Use it.
* include/bits/vector.tcc (vector<>::erase(iterator, iterator),
_M_fill_assign, _M_assign_aux): Likewise.
* testsuite/23_containers/vector/modifiers/erase/1.cc: New.
2005-12-07 Paolo Carlini <pcarlini@suse.de> 2005-12-07 Paolo Carlini <pcarlini@suse.de>
* docs/html/configopts.html ([--enable-libstdcxx-allocator]): * docs/html/configopts.html ([--enable-libstdcxx-allocator]):

View file

@ -266,8 +266,7 @@ namespace _GLIBCXX_STD
*/ */
~vector() ~vector()
{ 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_get_Tp_allocator()); _M_get_Tp_allocator()); }
}
/** /**
* @brief %Vector assignment operator. * @brief %Vector assignment operator.
@ -326,7 +325,7 @@ namespace _GLIBCXX_STD
*/ */
iterator iterator
begin() begin()
{ return iterator (this->_M_impl._M_start); } { 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
@ -335,7 +334,7 @@ namespace _GLIBCXX_STD
*/ */
const_iterator const_iterator
begin() const begin() const
{ return const_iterator (this->_M_impl._M_start); } { 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
@ -344,7 +343,7 @@ namespace _GLIBCXX_STD
*/ */
iterator iterator
end() end()
{ return iterator (this->_M_impl._M_finish); } { 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
@ -353,7 +352,7 @@ namespace _GLIBCXX_STD
*/ */
const_iterator const_iterator
end() const end() const
{ return const_iterator (this->_M_impl._M_finish); } { 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
@ -395,7 +394,7 @@ namespace _GLIBCXX_STD
/** Returns the number of elements in the %vector. */ /** Returns the number of elements in the %vector. */
size_type size_type
size() const size() const
{ return size_type(end() - begin()); } { return size_type(this->_M_impl._M_finish - this->_M_impl._M_start); }
/** Returns the size() of the largest possible %vector. */ /** Returns the size() of the largest possible %vector. */
size_type size_type
@ -417,7 +416,7 @@ namespace _GLIBCXX_STD
resize(size_type __new_size, value_type __x = value_type()) resize(size_type __new_size, value_type __x = value_type())
{ {
if (__new_size < size()) if (__new_size < size())
erase(begin() + __new_size, end()); _M_erase_at_end(this->_M_impl._M_start + __new_size);
else else
insert(end(), __new_size - size(), __x); insert(end(), __new_size - size(), __x);
} }
@ -428,8 +427,8 @@ namespace _GLIBCXX_STD
*/ */
size_type size_type
capacity() const capacity() const
{ return size_type(const_iterator(this->_M_impl._M_end_of_storage) { return size_type(this->_M_impl._M_end_of_storage
- begin()); } - this->_M_impl._M_start); }
/** /**
* Returns true if the %vector is empty. (Thus begin() would * Returns true if the %vector is empty. (Thus begin() would
@ -473,7 +472,7 @@ namespace _GLIBCXX_STD
*/ */
reference reference
operator[](size_type __n) operator[](size_type __n)
{ return *(begin() + __n); } { return *(this->_M_impl._M_start + __n); }
/** /**
* @brief Subscript access to the data contained in the %vector. * @brief Subscript access to the data contained in the %vector.
@ -488,7 +487,7 @@ namespace _GLIBCXX_STD
*/ */
const_reference const_reference
operator[](size_type __n) const operator[](size_type __n) const
{ return *(begin() + __n); } { return *(this->_M_impl._M_start + __n); }
protected: protected:
/// @if maint Safety check used only from at(). @endif /// @if maint Safety check used only from at(). @endif
@ -742,11 +741,7 @@ namespace _GLIBCXX_STD
*/ */
void void
clear() clear()
{ { _M_erase_at_end(this->_M_impl._M_start); }
std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
_M_get_Tp_allocator());
this->_M_impl._M_finish = this->_M_impl._M_start;
}
protected: protected:
/** /**
@ -910,6 +905,17 @@ namespace _GLIBCXX_STD
// Called by insert(p,x) // Called by insert(p,x)
void void
_M_insert_aux(iterator __position, const value_type& __x); _M_insert_aux(iterator __position, const value_type& __x);
// Internal erase functions follow.
// Called by erase(q1,q2), clear(), resize(), _M_fill_assign,
// _M_assign_aux.
void
_M_erase_at_end(pointer __pos)
{
std::_Destroy(__pos, this->_M_impl._M_finish, _M_get_Tp_allocator());
this->_M_impl._M_finish = __pos;
}
}; };

View file

@ -73,8 +73,7 @@ namespace _GLIBCXX_STD
if (this->capacity() < __n) if (this->capacity() < __n)
{ {
const size_type __old_size = size(); const size_type __old_size = size();
pointer __tmp = _M_allocate_and_copy(__n, pointer __tmp = _M_allocate_and_copy(__n, this->_M_impl._M_start,
this->_M_impl._M_start,
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_get_Tp_allocator()); _M_get_Tp_allocator());
@ -101,7 +100,7 @@ namespace _GLIBCXX_STD
} }
else else
_M_insert_aux(__position, __x); _M_insert_aux(__position, __x);
return begin() + __n; return iterator(this->_M_impl._M_start + __n);
} }
template<typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
@ -121,9 +120,9 @@ namespace _GLIBCXX_STD
vector<_Tp, _Alloc>:: vector<_Tp, _Alloc>::
erase(iterator __first, iterator __last) erase(iterator __first, iterator __last)
{ {
iterator __i(std::copy(__last, end(), __first)); if (__last != end())
std::_Destroy(__i, end(), _M_get_Tp_allocator()); std::copy(__last, end(), __first);
this->_M_impl._M_finish = this->_M_impl._M_finish - (__last - __first); _M_erase_at_end(__first.base() + (end() - __last));
return __first; return __first;
} }
@ -149,15 +148,16 @@ namespace _GLIBCXX_STD
} }
else if (size() >= __xlen) else if (size() >= __xlen)
{ {
iterator __i(std::copy(__x.begin(), __x.end(), begin())); std::_Destroy(std::copy(__x.begin(), __x.end(), begin()),
std::_Destroy(__i, end(), _M_get_Tp_allocator()); end(), _M_get_Tp_allocator());
} }
else else
{ {
std::copy(__x.begin(), __x.begin() + size(), std::copy(__x._M_impl._M_start, __x._M_impl._M_start + size(),
this->_M_impl._M_start); this->_M_impl._M_start);
std::__uninitialized_copy_a(__x.begin() + size(), std::__uninitialized_copy_a(__x._M_impl._M_start + size(),
__x.end(), this->_M_impl._M_finish, __x._M_impl._M_finish,
this->_M_impl._M_finish,
_M_get_Tp_allocator()); _M_get_Tp_allocator());
} }
this->_M_impl._M_finish = this->_M_impl._M_start + __xlen; this->_M_impl._M_finish = this->_M_impl._M_start + __xlen;
@ -184,7 +184,7 @@ namespace _GLIBCXX_STD
this->_M_impl._M_finish += __n - size(); this->_M_impl._M_finish += __n - size();
} }
else else
erase(std::fill_n(begin(), __n, __val), end()); _M_erase_at_end(std::fill_n(this->_M_impl._M_start, __n, __val));
} }
template<typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
@ -194,11 +194,12 @@ namespace _GLIBCXX_STD
_M_assign_aux(_InputIterator __first, _InputIterator __last, _M_assign_aux(_InputIterator __first, _InputIterator __last,
std::input_iterator_tag) std::input_iterator_tag)
{ {
iterator __cur(begin()); pointer __cur(this->_M_impl._M_start);
for (; __first != __last && __cur != end(); ++__cur, ++__first) for (; __first != __last && __cur != this->_M_impl._M_finish;
++__cur, ++__first)
*__cur = *__first; *__cur = *__first;
if (__first == __last) if (__first == __last)
erase(__cur, end()); _M_erase_at_end(__cur);
else else
insert(end(), __first, __last); insert(end(), __first, __last);
} }
@ -225,12 +226,7 @@ namespace _GLIBCXX_STD
this->_M_impl._M_end_of_storage = this->_M_impl._M_finish; this->_M_impl._M_end_of_storage = this->_M_impl._M_finish;
} }
else if (size() >= __len) else if (size() >= __len)
{ _M_erase_at_end(std::copy(__first, __last, this->_M_impl._M_start));
iterator __new_finish(std::copy(__first, __last,
this->_M_impl._M_start));
std::_Destroy(__new_finish, end(), _M_get_Tp_allocator());
this->_M_impl._M_finish = __new_finish.base();
}
else else
{ {
_ForwardIterator __mid = __first; _ForwardIterator __mid = __first;
@ -254,9 +250,9 @@ namespace _GLIBCXX_STD
*(this->_M_impl._M_finish - 1)); *(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.base(),
iterator(this->_M_impl._M_finish-2), this->_M_impl._M_finish - 2,
iterator(this->_M_impl._M_finish-1)); this->_M_impl._M_finish - 1);
*__position = __x_copy; *__position = __x_copy;
} }
else else
@ -272,36 +268,36 @@ namespace _GLIBCXX_STD
if (__len < __old_size) if (__len < __old_size)
__len = this->max_size(); __len = this->max_size();
iterator __new_start(this->_M_allocate(__len)); pointer __new_start(this->_M_allocate(__len));
iterator __new_finish(__new_start); pointer __new_finish(__new_start);
try try
{ {
__new_finish = __new_finish =
std::__uninitialized_copy_a(iterator(this->_M_impl._M_start), std::__uninitialized_copy_a(this->_M_impl._M_start,
__position, __position.base(), __new_start,
__new_start,
_M_get_Tp_allocator()); _M_get_Tp_allocator());
this->_M_impl.construct(__new_finish.base(), __x); this->_M_impl.construct(__new_finish, __x);
++__new_finish; ++__new_finish;
__new_finish = __new_finish =
std::__uninitialized_copy_a(__position, std::__uninitialized_copy_a(__position.base(),
iterator(this->_M_impl._M_finish), this->_M_impl._M_finish,
__new_finish, __new_finish,
_M_get_Tp_allocator()); _M_get_Tp_allocator());
} }
catch(...) catch(...)
{ {
std::_Destroy(__new_start, __new_finish, _M_get_Tp_allocator()); std::_Destroy(__new_start, __new_finish, _M_get_Tp_allocator());
_M_deallocate(__new_start.base(),__len); _M_deallocate(__new_start, __len);
__throw_exception_again; __throw_exception_again;
} }
std::_Destroy(begin(), end(), _M_get_Tp_allocator()); std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
_M_get_Tp_allocator());
_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);
this->_M_impl._M_start = __new_start.base(); this->_M_impl._M_start = __new_start;
this->_M_impl._M_finish = __new_finish.base(); this->_M_impl._M_finish = __new_finish;
this->_M_impl._M_end_of_storage = __new_start.base() + __len; this->_M_impl._M_end_of_storage = __new_start + __len;
} }
} }
@ -317,7 +313,7 @@ namespace _GLIBCXX_STD
{ {
value_type __x_copy = __x; value_type __x_copy = __x;
const size_type __elems_after = end() - __position; const size_type __elems_after = end() - __position;
iterator __old_finish(this->_M_impl._M_finish); pointer __old_finish(this->_M_impl._M_finish);
if (__elems_after > __n) if (__elems_after > __n)
{ {
std::__uninitialized_copy_a(this->_M_impl._M_finish - __n, std::__uninitialized_copy_a(this->_M_impl._M_finish - __n,
@ -325,9 +321,10 @@ namespace _GLIBCXX_STD
this->_M_impl._M_finish, this->_M_impl._M_finish,
_M_get_Tp_allocator()); _M_get_Tp_allocator());
this->_M_impl._M_finish += __n; this->_M_impl._M_finish += __n;
std::copy_backward(__position, __old_finish - __n, std::copy_backward(__position.base(), __old_finish - __n,
__old_finish); __old_finish);
std::fill(__position, __position + __n, __x_copy); std::fill(__position.base(), __position.base() + __n,
__x_copy);
} }
else else
{ {
@ -336,11 +333,11 @@ namespace _GLIBCXX_STD
__x_copy, __x_copy,
_M_get_Tp_allocator()); _M_get_Tp_allocator());
this->_M_impl._M_finish += __n - __elems_after; this->_M_impl._M_finish += __n - __elems_after;
std::__uninitialized_copy_a(__position, __old_finish, std::__uninitialized_copy_a(__position.base(), __old_finish,
this->_M_impl._M_finish, this->_M_impl._M_finish,
_M_get_Tp_allocator()); _M_get_Tp_allocator());
this->_M_impl._M_finish += __elems_after; this->_M_impl._M_finish += __elems_after;
std::fill(__position, __old_finish, __x_copy); std::fill(__position.base(), __old_finish, __x_copy);
} }
} }
else else
@ -354,26 +351,29 @@ namespace _GLIBCXX_STD
if (__len < __old_size) if (__len < __old_size)
__len = this->max_size(); __len = this->max_size();
iterator __new_start(this->_M_allocate(__len)); pointer __new_start(this->_M_allocate(__len));
iterator __new_finish(__new_start); pointer __new_finish(__new_start);
try try
{ {
__new_finish = __new_finish =
std::__uninitialized_copy_a(begin(), __position, std::__uninitialized_copy_a(this->_M_impl._M_start,
__position.base(),
__new_start, __new_start,
_M_get_Tp_allocator()); _M_get_Tp_allocator());
std::__uninitialized_fill_n_a(__new_finish, __n, __x, std::__uninitialized_fill_n_a(__new_finish, __n, __x,
_M_get_Tp_allocator()); _M_get_Tp_allocator());
__new_finish += __n; __new_finish += __n;
__new_finish = __new_finish =
std::__uninitialized_copy_a(__position, end(), __new_finish, std::__uninitialized_copy_a(__position.base(),
this->_M_impl._M_finish,
__new_finish,
_M_get_Tp_allocator()); _M_get_Tp_allocator());
} }
catch(...) catch(...)
{ {
std::_Destroy(__new_start, __new_finish, std::_Destroy(__new_start, __new_finish,
_M_get_Tp_allocator()); _M_get_Tp_allocator());
_M_deallocate(__new_start.base(), __len); _M_deallocate(__new_start, __len);
__throw_exception_again; __throw_exception_again;
} }
std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish, std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
@ -381,9 +381,9 @@ namespace _GLIBCXX_STD
_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);
this->_M_impl._M_start = __new_start.base(); this->_M_impl._M_start = __new_start;
this->_M_impl._M_finish = __new_finish.base(); this->_M_impl._M_finish = __new_finish;
this->_M_impl._M_end_of_storage = __new_start.base() + __len; this->_M_impl._M_end_of_storage = __new_start + __len;
} }
} }
} }
@ -415,7 +415,7 @@ namespace _GLIBCXX_STD
- this->_M_impl._M_finish) >= __n) - 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); pointer __old_finish(this->_M_impl._M_finish);
if (__elems_after > __n) if (__elems_after > __n)
{ {
std::__uninitialized_copy_a(this->_M_impl._M_finish - __n, std::__uninitialized_copy_a(this->_M_impl._M_finish - __n,
@ -423,7 +423,7 @@ namespace _GLIBCXX_STD
this->_M_impl._M_finish, this->_M_impl._M_finish,
_M_get_Tp_allocator()); _M_get_Tp_allocator());
this->_M_impl._M_finish += __n; this->_M_impl._M_finish += __n;
std::copy_backward(__position, __old_finish - __n, std::copy_backward(__position.base(), __old_finish - __n,
__old_finish); __old_finish);
std::copy(__first, __last, __position); std::copy(__first, __last, __position);
} }
@ -435,7 +435,8 @@ namespace _GLIBCXX_STD
this->_M_impl._M_finish, this->_M_impl._M_finish,
_M_get_Tp_allocator()); _M_get_Tp_allocator());
this->_M_impl._M_finish += __n - __elems_after; this->_M_impl._M_finish += __n - __elems_after;
std::__uninitialized_copy_a(__position, __old_finish, std::__uninitialized_copy_a(__position.base(),
__old_finish,
this->_M_impl._M_finish, this->_M_impl._M_finish,
_M_get_Tp_allocator()); _M_get_Tp_allocator());
this->_M_impl._M_finish += __elems_after; this->_M_impl._M_finish += __elems_after;
@ -453,29 +454,29 @@ namespace _GLIBCXX_STD
if (__len < __old_size) if (__len < __old_size)
__len = this->max_size(); __len = this->max_size();
iterator __new_start(this->_M_allocate(__len)); pointer __new_start(this->_M_allocate(__len));
iterator __new_finish(__new_start); pointer __new_finish(__new_start);
try try
{ {
__new_finish = __new_finish =
std::__uninitialized_copy_a(iterator(this->_M_impl._M_start), std::__uninitialized_copy_a(this->_M_impl._M_start,
__position, __position.base(),
__new_start, __new_start,
_M_get_Tp_allocator()); _M_get_Tp_allocator());
__new_finish = __new_finish =
std::__uninitialized_copy_a(__first, __last, __new_finish, std::__uninitialized_copy_a(__first, __last, __new_finish,
_M_get_Tp_allocator()); _M_get_Tp_allocator());
__new_finish = __new_finish =
std::__uninitialized_copy_a(__position, std::__uninitialized_copy_a(__position.base(),
iterator(this->_M_impl._M_finish), this->_M_impl._M_finish,
__new_finish, __new_finish,
_M_get_Tp_allocator()); _M_get_Tp_allocator());
} }
catch(...) catch(...)
{ {
std::_Destroy(__new_start,__new_finish, std::_Destroy(__new_start, __new_finish,
_M_get_Tp_allocator()); _M_get_Tp_allocator());
_M_deallocate(__new_start.base(), __len); _M_deallocate(__new_start, __len);
__throw_exception_again; __throw_exception_again;
} }
std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish, std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
@ -483,9 +484,9 @@ namespace _GLIBCXX_STD
_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);
this->_M_impl._M_start = __new_start.base(); this->_M_impl._M_start = __new_start;
this->_M_impl._M_finish = __new_finish.base(); this->_M_impl._M_finish = __new_finish;
this->_M_impl._M_end_of_storage = __new_start.base() + __len; this->_M_impl._M_end_of_storage = __new_start + __len;
} }
} }
} }

View file

@ -0,0 +1,136 @@
// 2005-11-02 Paolo Carlini <pcarlini@suse.de>
// Copyright (C) 2005 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
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// 23.2.4.3 vector modifiers
#include <vector>
#include <testsuite_hooks.h>
const int A[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
const int A1[] = {0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
const int A2[] = {0, 2, 3, 4, 10, 11, 12, 13, 14, 15};
const int A3[] = {0, 2, 3, 4, 10, 11};
const int A4[] = {4, 10, 11};
const int A5[] = {4, 10};
const int N = sizeof(A) / sizeof(int);
const int N1 = sizeof(A1) / sizeof(int);
const int N2 = sizeof(A2) / sizeof(int);
const int N3 = sizeof(A3) / sizeof(int);
const int N4 = sizeof(A4) / sizeof(int);
const int N5 = sizeof(A5) / sizeof(int);
void
test01()
{
bool test __attribute__((unused)) = true;
typedef std::vector<int> vec_type;
typedef vec_type::iterator iterator_type;
vec_type v(A, A + N);
iterator_type it1 = v.erase(v.begin() + 1);
VERIFY( it1 == v.begin() + 1 );
VERIFY( v.size() == N1 );
VERIFY( std::equal(v.begin(), v.end(), A1) );
iterator_type it2 = v.erase(v.begin() + 4, v.begin() + 9);
VERIFY( it2 == v.begin() + 4 );
VERIFY( v.size() == N2 );
VERIFY( std::equal(v.begin(), v.end(), A2) );
iterator_type it3 = v.erase(v.begin() + 6, v.end());
VERIFY( it3 == v.begin() + 6 );
VERIFY( v.size() == N3 );
VERIFY( std::equal(v.begin(), v.end(), A3) );
iterator_type it4 = v.erase(v.begin(), v.begin() + 3);
VERIFY( it4 == v.begin() );
VERIFY( v.size() == N4 );
VERIFY( std::equal(v.begin(), v.end(), A4) );
iterator_type it5 = v.erase(v.begin() + 2);
VERIFY( it5 == v.begin() + 2 );
VERIFY( v.size() == N5 );
VERIFY( std::equal(v.begin(), v.end(), A5) );
iterator_type it6 = v.erase(v.begin(), v.end());
VERIFY( it6 == v.begin() );
VERIFY( v.empty() );
}
void
test02()
{
bool test __attribute__((unused)) = true;
typedef std::vector<std::vector<int> > vec_type;
typedef vec_type::iterator iterator_type;
vec_type v, v1, v2, v3, v4, v5;
for (int i = 0; i < N; ++i)
v.push_back(std::vector<int>(1, A[i]));
for (int i = 0; i < N1; ++i)
v1.push_back(std::vector<int>(1, A1[i]));
for (int i = 0; i < N2; ++i)
v2.push_back(std::vector<int>(1, A2[i]));
for (int i = 0; i < N3; ++i)
v3.push_back(std::vector<int>(1, A3[i]));
for (int i = 0; i < N4; ++i)
v4.push_back(std::vector<int>(1, A4[i]));
for (int i = 0; i < N5; ++i)
v5.push_back(std::vector<int>(1, A5[i]));
iterator_type it1 = v.erase(v.begin() + 1);
VERIFY( it1 == v.begin() + 1 );
VERIFY( v.size() == N1 );
VERIFY( std::equal(v.begin(), v.end(), v1.begin()) );
iterator_type it2 = v.erase(v.begin() + 4, v.begin() + 9);
VERIFY( it2 == v.begin() + 4 );
VERIFY( v.size() == N2 );
VERIFY( std::equal(v.begin(), v.end(), v2.begin()) );
iterator_type it3 = v.erase(v.begin() + 6, v.end());
VERIFY( it3 == v.begin() + 6 );
VERIFY( v.size() == N3 );
VERIFY( std::equal(v.begin(), v.end(), v3.begin()) );
iterator_type it4 = v.erase(v.begin(), v.begin() + 3);
VERIFY( it4 == v.begin() );
VERIFY( v.size() == N4 );
VERIFY( std::equal(v.begin(), v.end(), v4.begin()) );
iterator_type it5 = v.erase(v.begin() + 2);
VERIFY( it5 == v.begin() + 2 );
VERIFY( v.size() == N5 );
VERIFY( std::equal(v.begin(), v.end(), v5.begin()) );
iterator_type it6 = v.erase(v.begin(), v.end());
VERIFY( it6 == v.begin() );
VERIFY( v.empty() );
}
int main()
{
test01();
test02();
return 0;
}

View file

@ -0,0 +1,54 @@
// 2005-12-01 Paolo Carlini <pcarlini@suse.de>
// Copyright (C) 2005 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
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// { dg-do compile }
#include <vector>
namespace N
{
struct X { };
template<typename T>
X operator+(T, std::size_t)
{ return X(); }
template<typename T>
X operator-(T, T)
{ return X(); }
}
int main()
{
std::vector<N::X> v(5);
const std::vector<N::X> w(1);
v[0];
w[0];
v.size();
v.capacity();
v.resize(1);
v.insert(v.begin(), N::X());
v.insert(v.begin(), 1, N::X());
v.insert(v.begin(), w.begin(), w.end());
v = w;
return 0;
}