From bc9053abce09400d12ced72db73bff5dbbd05007 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Thu, 8 Dec 2005 11:32:37 +0000 Subject: [PATCH] re PR libstdc++/24617 (vector vs __erase_at_end) 2005-12-08 Paolo Carlini * 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 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 --- libstdc++-v3/ChangeLog | 25 ++++ libstdc++-v3/include/bits/stl_vector.h | 40 +++--- libstdc++-v3/include/bits/vector.tcc | 129 ++++++++--------- .../23_containers/vector/modifiers/erase/1.cc | 136 ++++++++++++++++++ .../testsuite/23_containers/vector/types/1.cc | 54 +++++++ 5 files changed, 303 insertions(+), 81 deletions(-) create mode 100644 libstdc++-v3/testsuite/23_containers/vector/modifiers/erase/1.cc create mode 100644 libstdc++-v3/testsuite/23_containers/vector/types/1.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 7b5b6591e1e..6785bb39d20 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,28 @@ +2005-12-08 Paolo Carlini + + * 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 + + 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 * docs/html/configopts.html ([--enable-libstdcxx-allocator]): diff --git a/libstdc++-v3/include/bits/stl_vector.h b/libstdc++-v3/include/bits/stl_vector.h index 1fc59dd5bbe..7d8519cdfdd 100644 --- a/libstdc++-v3/include/bits/stl_vector.h +++ b/libstdc++-v3/include/bits/stl_vector.h @@ -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; + } }; diff --git a/libstdc++-v3/include/bits/vector.tcc b/libstdc++-v3/include/bits/vector.tcc index 3a9b66e1d1a..9213057a2ab 100644 --- a/libstdc++-v3/include/bits/vector.tcc +++ b/libstdc++-v3/include/bits/vector.tcc @@ -73,8 +73,7 @@ namespace _GLIBCXX_STD if (this->capacity() < __n) { const size_type __old_size = size(); - pointer __tmp = _M_allocate_and_copy(__n, - this->_M_impl._M_start, + pointer __tmp = _M_allocate_and_copy(__n, 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()); @@ -101,7 +100,7 @@ namespace _GLIBCXX_STD } else _M_insert_aux(__position, __x); - return begin() + __n; + return iterator(this->_M_impl._M_start + __n); } template @@ -121,9 +120,9 @@ namespace _GLIBCXX_STD vector<_Tp, _Alloc>:: erase(iterator __first, iterator __last) { - iterator __i(std::copy(__last, end(), __first)); - std::_Destroy(__i, end(), _M_get_Tp_allocator()); - this->_M_impl._M_finish = this->_M_impl._M_finish - (__last - __first); + if (__last != end()) + std::copy(__last, end(), __first); + _M_erase_at_end(__first.base() + (end() - __last)); return __first; } @@ -149,15 +148,16 @@ namespace _GLIBCXX_STD } else if (size() >= __xlen) { - iterator __i(std::copy(__x.begin(), __x.end(), begin())); - std::_Destroy(__i, end(), _M_get_Tp_allocator()); + std::_Destroy(std::copy(__x.begin(), __x.end(), begin()), + end(), _M_get_Tp_allocator()); } 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); - std::__uninitialized_copy_a(__x.begin() + size(), - __x.end(), this->_M_impl._M_finish, + std::__uninitialized_copy_a(__x._M_impl._M_start + size(), + __x._M_impl._M_finish, + this->_M_impl._M_finish, _M_get_Tp_allocator()); } 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(); } else - erase(std::fill_n(begin(), __n, __val), end()); + _M_erase_at_end(std::fill_n(this->_M_impl._M_start, __n, __val)); } template @@ -194,11 +194,12 @@ namespace _GLIBCXX_STD _M_assign_aux(_InputIterator __first, _InputIterator __last, std::input_iterator_tag) { - iterator __cur(begin()); - for (; __first != __last && __cur != end(); ++__cur, ++__first) + pointer __cur(this->_M_impl._M_start); + for (; __first != __last && __cur != this->_M_impl._M_finish; + ++__cur, ++__first) *__cur = *__first; if (__first == __last) - erase(__cur, end()); + _M_erase_at_end(__cur); else insert(end(), __first, __last); } @@ -225,12 +226,7 @@ namespace _GLIBCXX_STD this->_M_impl._M_end_of_storage = this->_M_impl._M_finish; } else if (size() >= __len) - { - 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(); - } + _M_erase_at_end(std::copy(__first, __last, this->_M_impl._M_start)); else { _ForwardIterator __mid = __first; @@ -254,9 +250,9 @@ namespace _GLIBCXX_STD *(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)); + std::copy_backward(__position.base(), + this->_M_impl._M_finish - 2, + this->_M_impl._M_finish - 1); *__position = __x_copy; } else @@ -272,36 +268,36 @@ namespace _GLIBCXX_STD if (__len < __old_size) __len = this->max_size(); - iterator __new_start(this->_M_allocate(__len)); - iterator __new_finish(__new_start); + pointer __new_start(this->_M_allocate(__len)); + pointer __new_finish(__new_start); try { __new_finish = - std::__uninitialized_copy_a(iterator(this->_M_impl._M_start), - __position, - __new_start, + std::__uninitialized_copy_a(this->_M_impl._M_start, + __position.base(), __new_start, _M_get_Tp_allocator()); - this->_M_impl.construct(__new_finish.base(), __x); + this->_M_impl.construct(__new_finish, __x); ++__new_finish; __new_finish = - std::__uninitialized_copy_a(__position, - iterator(this->_M_impl._M_finish), + std::__uninitialized_copy_a(__position.base(), + this->_M_impl._M_finish, __new_finish, _M_get_Tp_allocator()); } catch(...) { std::_Destroy(__new_start, __new_finish, _M_get_Tp_allocator()); - _M_deallocate(__new_start.base(),__len); + _M_deallocate(__new_start, __len); __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, 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; + this->_M_impl._M_start = __new_start; + this->_M_impl._M_finish = __new_finish; + this->_M_impl._M_end_of_storage = __new_start + __len; } } @@ -317,7 +313,7 @@ namespace _GLIBCXX_STD { value_type __x_copy = __x; 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) { std::__uninitialized_copy_a(this->_M_impl._M_finish - __n, @@ -325,9 +321,10 @@ namespace _GLIBCXX_STD this->_M_impl._M_finish, _M_get_Tp_allocator()); this->_M_impl._M_finish += __n; - std::copy_backward(__position, __old_finish - __n, + std::copy_backward(__position.base(), __old_finish - __n, __old_finish); - std::fill(__position, __position + __n, __x_copy); + std::fill(__position.base(), __position.base() + __n, + __x_copy); } else { @@ -336,11 +333,11 @@ namespace _GLIBCXX_STD __x_copy, _M_get_Tp_allocator()); 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, _M_get_Tp_allocator()); this->_M_impl._M_finish += __elems_after; - std::fill(__position, __old_finish, __x_copy); + std::fill(__position.base(), __old_finish, __x_copy); } } else @@ -354,26 +351,29 @@ namespace _GLIBCXX_STD if (__len < __old_size) __len = this->max_size(); - iterator __new_start(this->_M_allocate(__len)); - iterator __new_finish(__new_start); + pointer __new_start(this->_M_allocate(__len)); + pointer __new_finish(__new_start); try { __new_finish = - std::__uninitialized_copy_a(begin(), __position, + std::__uninitialized_copy_a(this->_M_impl._M_start, + __position.base(), __new_start, _M_get_Tp_allocator()); std::__uninitialized_fill_n_a(__new_finish, __n, __x, _M_get_Tp_allocator()); __new_finish += __n; __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()); } catch(...) { std::_Destroy(__new_start, __new_finish, _M_get_Tp_allocator()); - _M_deallocate(__new_start.base(), __len); + _M_deallocate(__new_start, __len); __throw_exception_again; } 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, 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; + this->_M_impl._M_start = __new_start; + this->_M_impl._M_finish = __new_finish; + this->_M_impl._M_end_of_storage = __new_start + __len; } } } @@ -415,7 +415,7 @@ namespace _GLIBCXX_STD - this->_M_impl._M_finish) >= __n) { 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) { std::__uninitialized_copy_a(this->_M_impl._M_finish - __n, @@ -423,7 +423,7 @@ namespace _GLIBCXX_STD this->_M_impl._M_finish, _M_get_Tp_allocator()); this->_M_impl._M_finish += __n; - std::copy_backward(__position, __old_finish - __n, + std::copy_backward(__position.base(), __old_finish - __n, __old_finish); std::copy(__first, __last, __position); } @@ -435,7 +435,8 @@ namespace _GLIBCXX_STD this->_M_impl._M_finish, _M_get_Tp_allocator()); 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, _M_get_Tp_allocator()); this->_M_impl._M_finish += __elems_after; @@ -453,29 +454,29 @@ namespace _GLIBCXX_STD if (__len < __old_size) __len = this->max_size(); - iterator __new_start(this->_M_allocate(__len)); - iterator __new_finish(__new_start); + pointer __new_start(this->_M_allocate(__len)); + pointer __new_finish(__new_start); try { __new_finish = - std::__uninitialized_copy_a(iterator(this->_M_impl._M_start), - __position, + std::__uninitialized_copy_a(this->_M_impl._M_start, + __position.base(), __new_start, _M_get_Tp_allocator()); __new_finish = std::__uninitialized_copy_a(__first, __last, __new_finish, _M_get_Tp_allocator()); __new_finish = - std::__uninitialized_copy_a(__position, - iterator(this->_M_impl._M_finish), + std::__uninitialized_copy_a(__position.base(), + this->_M_impl._M_finish, __new_finish, _M_get_Tp_allocator()); } catch(...) { - std::_Destroy(__new_start,__new_finish, + std::_Destroy(__new_start, __new_finish, _M_get_Tp_allocator()); - _M_deallocate(__new_start.base(), __len); + _M_deallocate(__new_start, __len); __throw_exception_again; } 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, 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; + this->_M_impl._M_start = __new_start; + this->_M_impl._M_finish = __new_finish; + this->_M_impl._M_end_of_storage = __new_start + __len; } } } diff --git a/libstdc++-v3/testsuite/23_containers/vector/modifiers/erase/1.cc b/libstdc++-v3/testsuite/23_containers/vector/modifiers/erase/1.cc new file mode 100644 index 00000000000..0a3cffb90b2 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/modifiers/erase/1.cc @@ -0,0 +1,136 @@ +// 2005-11-02 Paolo Carlini + +// 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 +#include + +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 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 > 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(1, A[i])); + for (int i = 0; i < N1; ++i) + v1.push_back(std::vector(1, A1[i])); + for (int i = 0; i < N2; ++i) + v2.push_back(std::vector(1, A2[i])); + for (int i = 0; i < N3; ++i) + v3.push_back(std::vector(1, A3[i])); + for (int i = 0; i < N4; ++i) + v4.push_back(std::vector(1, A4[i])); + for (int i = 0; i < N5; ++i) + v5.push_back(std::vector(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; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/types/1.cc b/libstdc++-v3/testsuite/23_containers/vector/types/1.cc new file mode 100644 index 00000000000..09a00dfbf87 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/types/1.cc @@ -0,0 +1,54 @@ +// 2005-12-01 Paolo Carlini + +// 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 + +namespace N +{ + struct X { }; + + template + X operator+(T, std::size_t) + { return X(); } + + template + X operator-(T, T) + { return X(); } +} + +int main() +{ + std::vector v(5); + const std::vector 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; +} -- 2.30.2