From 245a5fe5c0ae5dd48f7adc806117264543f39fdd Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Mon, 29 Oct 2007 01:59:49 +0000 Subject: [PATCH] stl_algobase.h (_GLIBCXX_MOVE3, [...]): Add. 2007-10-28 Paolo Carlini * include/bits/stl_algobase.h (_GLIBCXX_MOVE3, _GLIBCXX_MOVE_BACKWARD3): Add. * include/bits/stl_iterator.h (_GLIBCXX_MAKE_MOVE_ITERATOR): Add. * include/bits/vector.tcc (vector<>::reserve): Use the latter. (vector<>::erase): Use _GLIBCXX_MOVE3. * include/bits/deque.tcc (deque<>::erase): Use _GLIBCXX_MOVE3 and _GLIBCXX_MOVE_BACKWARD3. * testsuite/23_containers/vector/modifiers/erase/moveable.cc: New. * testsuite/23_containers/vector/capacity/reserve/moveable.cc: New. * testsuite/23_containers/deque/modifiers/erase/moveable.cc: New. From-SVN: r129714 --- libstdc++-v3/ChangeLog | 13 ++++ libstdc++-v3/include/bits/deque.tcc | 8 +-- libstdc++-v3/include/bits/stl_algobase.h | 8 +++ libstdc++-v3/include/bits/stl_iterator.h | 3 + libstdc++-v3/include/bits/vector.tcc | 9 +-- .../deque/modifiers/erase/moveable.cc | 71 +++++++++++++++++++ .../vector/capacity/reserve/moveable.cc | 56 +++++++++++++++ .../vector/modifiers/erase/moveable.cc | 71 +++++++++++++++++++ 8 files changed, 231 insertions(+), 8 deletions(-) create mode 100644 libstdc++-v3/testsuite/23_containers/deque/modifiers/erase/moveable.cc create mode 100644 libstdc++-v3/testsuite/23_containers/vector/capacity/reserve/moveable.cc create mode 100644 libstdc++-v3/testsuite/23_containers/vector/modifiers/erase/moveable.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index aa276488e2a..440c7cdfc42 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,16 @@ +2007-10-28 Paolo Carlini + + * include/bits/stl_algobase.h (_GLIBCXX_MOVE3, + _GLIBCXX_MOVE_BACKWARD3): Add. + * include/bits/stl_iterator.h (_GLIBCXX_MAKE_MOVE_ITERATOR): Add. + * include/bits/vector.tcc (vector<>::reserve): Use the latter. + (vector<>::erase): Use _GLIBCXX_MOVE3. + * include/bits/deque.tcc (deque<>::erase): Use _GLIBCXX_MOVE3 + and _GLIBCXX_MOVE_BACKWARD3. + * testsuite/23_containers/vector/modifiers/erase/moveable.cc: New. + * testsuite/23_containers/vector/capacity/reserve/moveable.cc: New. + * testsuite/23_containers/deque/modifiers/erase/moveable.cc: New. + 2007-10-28 Paolo Carlini * include/bits/stl_uninitialized.h (uninitialized_copy): Use diff --git a/libstdc++-v3/include/bits/deque.tcc b/libstdc++-v3/include/bits/deque.tcc index b5cacc1e577..5e9b8923f22 100644 --- a/libstdc++-v3/include/bits/deque.tcc +++ b/libstdc++-v3/include/bits/deque.tcc @@ -117,13 +117,13 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) if (static_cast(__index) < (size() >> 1)) { if (__position != begin()) - std::copy_backward(begin(), __position, __next); + _GLIBCXX_MOVE_BACKWARD3(begin(), __position, __next); pop_front(); } else { if (__next != end()) - std::copy(__next, end(), __position); + _GLIBCXX_MOVE3(__next, end(), __position); pop_back(); } return begin() + __index; @@ -146,13 +146,13 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) if (static_cast(__elems_before) <= (size() - __n) / 2) { if (__first != begin()) - std::copy_backward(begin(), __first, __last); + _GLIBCXX_MOVE_BACKWARD3(begin(), __first, __last); _M_erase_at_begin(begin() + __n); } else { if (__last != end()) - std::copy(__last, end(), __first); + _GLIBCXX_MOVE3(__last, end(), __first); _M_erase_at_end(end() - __n); } return begin() + __elems_before; diff --git a/libstdc++-v3/include/bits/stl_algobase.h b/libstdc++-v3/include/bits/stl_algobase.h index 818c7ee458c..358983566c3 100644 --- a/libstdc++-v3/include/bits/stl_algobase.h +++ b/libstdc++-v3/include/bits/stl_algobase.h @@ -488,6 +488,10 @@ _GLIBCXX_BEGIN_NAMESPACE(std) (std::__miter_base<_II>::__b(__first), std::__miter_base<_II>::__b(__last), __result)); } + +#define _GLIBCXX_MOVE3(_Tp, _Up, _Vp) std::move(_Tp, _Up, _Vp) +#else +#define _GLIBCXX_MOVE3(_Tp, _Up, _Vp) std::copy(_Tp, _Up, _Vp) #endif template @@ -626,6 +630,10 @@ _GLIBCXX_BEGIN_NAMESPACE(std) (std::__miter_base<_BI1>::__b(__first), std::__miter_base<_BI1>::__b(__last), __result)); } + +#define _GLIBCXX_MOVE_BACKWARD3(_Tp, _Up, _Vp) std::move_backward(_Tp, _Up, _Vp) +#else +#define _GLIBCXX_MOVE_BACKWARD3(_Tp, _Up, _Vp) std::copy_backward(_Tp, _Up, _Vp) #endif template diff --git a/libstdc++-v3/include/bits/stl_iterator.h b/libstdc++-v3/include/bits/stl_iterator.h index f16ac024b9f..bc3cbd9f502 100644 --- a/libstdc++-v3/include/bits/stl_iterator.h +++ b/libstdc++-v3/include/bits/stl_iterator.h @@ -1021,6 +1021,9 @@ _GLIBCXX_BEGIN_NAMESPACE(std) _GLIBCXX_END_NAMESPACE +#define _GLIBCXX_MAKE_MOVE_ITERATOR(_Iter) std::make_move_iterator(_Iter) +#else +#define _GLIBCXX_MAKE_MOVE_ITERATOR(_Iter) (_Iter) #endif // __GXX_EXPERIMENTAL_CXX0X__ #endif diff --git a/libstdc++-v3/include/bits/vector.tcc b/libstdc++-v3/include/bits/vector.tcc index 442447c27f1..e15d80d59b7 100644 --- a/libstdc++-v3/include/bits/vector.tcc +++ b/libstdc++-v3/include/bits/vector.tcc @@ -74,8 +74,9 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) if (this->capacity() < __n) { const size_type __old_size = size(); - pointer __tmp = _M_allocate_and_copy(__n, this->_M_impl._M_start, - this->_M_impl._M_finish); + pointer __tmp = _M_allocate_and_copy(__n, + _GLIBCXX_MAKE_MOVE_ITERATOR(this->_M_impl._M_start), + _GLIBCXX_MAKE_MOVE_ITERATOR(this->_M_impl._M_finish)); std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish, _M_get_Tp_allocator()); _M_deallocate(this->_M_impl._M_start, @@ -110,7 +111,7 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) erase(iterator __position) { if (__position + 1 != end()) - std::copy(__position + 1, end(), __position); + _GLIBCXX_MOVE3(__position + 1, end(), __position); --this->_M_impl._M_finish; this->_M_impl.destroy(this->_M_impl._M_finish); return __position; @@ -122,7 +123,7 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) erase(iterator __first, iterator __last) { if (__last != end()) - std::copy(__last, end(), __first); + _GLIBCXX_MOVE3(__last, end(), __first); _M_erase_at_end(__first.base() + (end() - __last)); return __first; } diff --git a/libstdc++-v3/testsuite/23_containers/deque/modifiers/erase/moveable.cc b/libstdc++-v3/testsuite/23_containers/deque/modifiers/erase/moveable.cc new file mode 100644 index 00000000000..879d0c25f98 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/modifiers/erase/moveable.cc @@ -0,0 +1,71 @@ +// { dg-options "-std=gnu++0x" } + +// 2007-10-28 Paolo Carlini + +// Copyright (C) 2007 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +#include +#include +#include + +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace __gnu_test; + + std::deque a(40); + copycounter::copycount = 0; + + a.erase(a.begin() + 20); + VERIFY( copycounter::copycount == 0 ); + + a.erase(a.begin()); + VERIFY( copycounter::copycount == 0 ); + + a.erase(a.end() - 1); + VERIFY( copycounter::copycount == 0 ); + + a.erase(a.begin() + 10, a.end() - 10); + VERIFY( copycounter::copycount == 0 ); + + a.erase(a.begin(), a.begin() + 5); + VERIFY( copycounter::copycount == 0 ); + + a.erase(a.end() - 5, a.end()); + VERIFY( copycounter::copycount == 0 ); + + a.erase(a.begin(), a.end()); + VERIFY( copycounter::copycount == 0 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/capacity/reserve/moveable.cc b/libstdc++-v3/testsuite/23_containers/vector/capacity/reserve/moveable.cc new file mode 100644 index 00000000000..481247f38f7 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/capacity/reserve/moveable.cc @@ -0,0 +1,56 @@ +// { dg-options "-std=gnu++0x" } + +// 2007-10-28 Paolo Carlini + +// Copyright (C) 2007 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +#include +#include +#include + +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace __gnu_test; + + std::vector a(40); + copycounter::copycount = 0; + + a.reserve(50); + VERIFY( copycounter::copycount == 0 ); + + a.reserve(200); + VERIFY( copycounter::copycount == 0 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/modifiers/erase/moveable.cc b/libstdc++-v3/testsuite/23_containers/vector/modifiers/erase/moveable.cc new file mode 100644 index 00000000000..39e1ea26219 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/modifiers/erase/moveable.cc @@ -0,0 +1,71 @@ +// { dg-options "-std=gnu++0x" } + +// 2007-10-28 Paolo Carlini + +// Copyright (C) 2007 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +#include +#include +#include + +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace __gnu_test; + + std::vector a(40); + copycounter::copycount = 0; + + a.erase(a.begin() + 20); + VERIFY( copycounter::copycount == 0 ); + + a.erase(a.begin()); + VERIFY( copycounter::copycount == 0 ); + + a.erase(a.end() - 1); + VERIFY( copycounter::copycount == 0 ); + + a.erase(a.begin() + 10, a.end() - 10); + VERIFY( copycounter::copycount == 0 ); + + a.erase(a.begin(), a.begin() + 5); + VERIFY( copycounter::copycount == 0 ); + + a.erase(a.end() - 5, a.end()); + VERIFY( copycounter::copycount == 0 ); + + a.erase(a.begin(), a.end()); + VERIFY( copycounter::copycount == 0 ); +} + +int main() +{ + test01(); + return 0; +} -- 2.30.2