Commit bc9053ab by Paolo Carlini Committed by Paolo Carlini

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