From e2bf200700a29fc74f9cc7dd4ae942c89f8dff24 Mon Sep 17 00:00:00 2001 From: Paolo Carlini <paolo.carlini@oracle.com> Date: Wed, 23 Dec 2009 17:14:15 +0000 Subject: [PATCH] stl_deque.h (copy(_Deque_iterator, _Deque_iterator, _Deque_iterator), [...]): Declare. 2009-12-23 Paolo Carlini <paolo.carlini@oracle.com> * include/bits/stl_deque.h (copy(_Deque_iterator, _Deque_iterator, _Deque_iterator), move(_Deque_iterator, _Deque_iterator, _Deque_iterator)): Declare. * include/bits/deque.tcc: Implement the latter. * testsuite/performance/25_algorithms/copy_deque_iterators.cc: New. * testsuite/25_algorithms/move/2.cc: Likewise. * testsuite/25_algorithms/copy/5.cc: Likewise. * testsuite/23_containers/deque/requirements/dr438/assign_neg.cc: Adjust dg-error line number. * testsuite/23_containers/deque/requirements/dr438/insert_neg.cc: Likewise. * testsuite/23_containers/deque/requirements/dr438/ constructor_1_neg.cc: Likewise. * testsuite/23_containers/deque/requirements/dr438/ constructor_2_neg.cc: Likewise. From-SVN: r155432 --- libstdc++-v3/ChangeLog | 18 +++++++ libstdc++-v3/include/bits/deque.tcc | 48 ++++++++++++++++- libstdc++-v3/include/bits/stl_deque.h | 36 ++++++++++++- .../deque/requirements/dr438/assign_neg.cc | 2 +- .../requirements/dr438/constructor_1_neg.cc | 2 +- .../requirements/dr438/constructor_2_neg.cc | 2 +- .../deque/requirements/dr438/insert_neg.cc | 2 +- .../testsuite/25_algorithms/copy/5.cc | 51 ++++++++++++++++++ .../testsuite/25_algorithms/move/2.cc | 53 +++++++++++++++++++ .../25_algorithms/copy_deque_iterators.cc | 40 ++++++++++++++ 10 files changed, 247 insertions(+), 7 deletions(-) create mode 100644 libstdc++-v3/testsuite/25_algorithms/copy/5.cc create mode 100644 libstdc++-v3/testsuite/25_algorithms/move/2.cc create mode 100644 libstdc++-v3/testsuite/performance/25_algorithms/copy_deque_iterators.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 117b204bb098..fd3b9f87632b 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,21 @@ +2009-12-23 Paolo Carlini <paolo.carlini@oracle.com> + + * include/bits/stl_deque.h (copy(_Deque_iterator, _Deque_iterator, + _Deque_iterator), move(_Deque_iterator, _Deque_iterator, + _Deque_iterator)): Declare. + * include/bits/deque.tcc: Implement the latter. + * testsuite/performance/25_algorithms/copy_deque_iterators.cc: New. + * testsuite/25_algorithms/move/2.cc: Likewise. + * testsuite/25_algorithms/copy/5.cc: Likewise. + * testsuite/23_containers/deque/requirements/dr438/assign_neg.cc: + Adjust dg-error line number. + * testsuite/23_containers/deque/requirements/dr438/insert_neg.cc: + Likewise. + * testsuite/23_containers/deque/requirements/dr438/ + constructor_1_neg.cc: Likewise. + * testsuite/23_containers/deque/requirements/dr438/ + constructor_2_neg.cc: Likewise. + 2009-12-22 Iain Sandoe <iain.sandoe@sandoe-acoustics.co.uk> PR target/41605 diff --git a/libstdc++-v3/include/bits/deque.tcc b/libstdc++-v3/include/bits/deque.tcc index aac0d590b399..968fc0051c5d 100644 --- a/libstdc++-v3/include/bits/deque.tcc +++ b/libstdc++-v3/include/bits/deque.tcc @@ -837,7 +837,7 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) } // Overload for deque::iterators, exploiting the "segmented-iterator - // optimization". NB: leave const_iterators alone! + // optimization". template<typename _Tp> void fill(const _Deque_iterator<_Tp, _Tp&, _Tp*>& __first, @@ -858,6 +858,52 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) std::fill(__first._M_cur, __last._M_cur, __value); } + template<typename _Tp> + _Deque_iterator<_Tp, _Tp&, _Tp*> + copy(_Deque_iterator<_Tp, const _Tp&, const _Tp*> __first, + _Deque_iterator<_Tp, const _Tp&, const _Tp*> __last, + _Deque_iterator<_Tp, _Tp&, _Tp*> __result) + { + typedef typename _Deque_iterator<_Tp, _Tp&, _Tp*>::_Self _Self; + + typename _Self::difference_type __len = __last - __first; + while (__len > 0) + { + typename _Self::difference_type __clen + = std::min(__len, std::min(__first._M_last - __first._M_cur, + __result._M_last - __result._M_cur)); + std::copy(__first._M_cur, __first._M_cur + __clen, __result._M_cur); + __first += __clen; + __result += __clen; + __len -= __clen; + } + return __result; + } + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + template<typename _Tp> + _Deque_iterator<_Tp, _Tp&, _Tp*> + move(_Deque_iterator<_Tp, const _Tp&, const _Tp*> __first, + _Deque_iterator<_Tp, const _Tp&, const _Tp*> __last, + _Deque_iterator<_Tp, _Tp&, _Tp*> __result) + { + typedef typename _Deque_iterator<_Tp, _Tp&, _Tp*>::_Self _Self; + + typename _Self::difference_type __len = __last - __first; + while (__len > 0) + { + const typename _Self::difference_type __clen + = std::min(__len, std::min(__first._M_last - __first._M_cur, + __result._M_last - __result._M_cur)); + std::move(__first._M_cur, __first._M_cur + __clen, __result._M_cur); + __first += __clen; + __result += __clen; + __len -= __clen; + } + return __result; + } +#endif + _GLIBCXX_END_NESTED_NAMESPACE #endif diff --git a/libstdc++-v3/include/bits/stl_deque.h b/libstdc++-v3/include/bits/stl_deque.h index d7589f71d7aa..99105ebdcd48 100644 --- a/libstdc++-v3/include/bits/stl_deque.h +++ b/libstdc++-v3/include/bits/stl_deque.h @@ -352,8 +352,40 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) template<typename _Tp> void - fill(const _Deque_iterator<_Tp, _Tp&, _Tp*>& __first, - const _Deque_iterator<_Tp, _Tp&, _Tp*>& __last, const _Tp& __value); + fill(const _Deque_iterator<_Tp, _Tp&, _Tp*>&, + const _Deque_iterator<_Tp, _Tp&, _Tp*>&, const _Tp&); + + template<typename _Tp> + _Deque_iterator<_Tp, _Tp&, _Tp*> + copy(_Deque_iterator<_Tp, const _Tp&, const _Tp*>, + _Deque_iterator<_Tp, const _Tp&, const _Tp*>, + _Deque_iterator<_Tp, _Tp&, _Tp*>); + + template<typename _Tp> + inline _Deque_iterator<_Tp, _Tp&, _Tp*> + copy(_Deque_iterator<_Tp, _Tp&, _Tp*> __first, + _Deque_iterator<_Tp, _Tp&, _Tp*> __last, + _Deque_iterator<_Tp, _Tp&, _Tp*> __result) + { return std::copy(_Deque_iterator<_Tp, const _Tp&, const _Tp*>(__first), + _Deque_iterator<_Tp, const _Tp&, const _Tp*>(__last), + __result); } + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + template<typename _Tp> + _Deque_iterator<_Tp, _Tp&, _Tp*> + move(_Deque_iterator<_Tp, const _Tp&, const _Tp*>, + _Deque_iterator<_Tp, const _Tp&, const _Tp*>, + _Deque_iterator<_Tp, _Tp&, _Tp*>); + + template<typename _Tp> + inline _Deque_iterator<_Tp, _Tp&, _Tp*> + move(_Deque_iterator<_Tp, _Tp&, _Tp*> __first, + _Deque_iterator<_Tp, _Tp&, _Tp*> __last, + _Deque_iterator<_Tp, _Tp&, _Tp*> __result) + { return std::move(_Deque_iterator<_Tp, const _Tp&, const _Tp*>(__first), + _Deque_iterator<_Tp, const _Tp&, const _Tp*>(__last), + __result); } +#endif /** * Deque base class. This class provides the unified face for %deque's diff --git a/libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/assign_neg.cc b/libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/assign_neg.cc index 314a13f64e7a..b022e14a6095 100644 --- a/libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/assign_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/assign_neg.cc @@ -18,7 +18,7 @@ // <http://www.gnu.org/licenses/>. // { dg-do compile } -// { dg-error "no matching" "" { target *-*-* } 1502 } +// { dg-error "no matching" "" { target *-*-* } 1534 } // { dg-excess-errors "" } #include <deque> diff --git a/libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/constructor_1_neg.cc b/libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/constructor_1_neg.cc index 2ae51b836d80..a43f2c707a5d 100644 --- a/libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/constructor_1_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/constructor_1_neg.cc @@ -18,7 +18,7 @@ // <http://www.gnu.org/licenses/>. // { dg-do compile } -// { dg-error "no matching" "" { target *-*-* } 1441 } +// { dg-error "no matching" "" { target *-*-* } 1473 } // { dg-excess-errors "" } #include <deque> diff --git a/libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/constructor_2_neg.cc b/libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/constructor_2_neg.cc index 22bb275068b3..71a4ceb3c691 100644 --- a/libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/constructor_2_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/constructor_2_neg.cc @@ -18,7 +18,7 @@ // <http://www.gnu.org/licenses/>. // { dg-do compile } -// { dg-error "no matching" "" { target *-*-* } 1441 } +// { dg-error "no matching" "" { target *-*-* } 1473 } // { dg-excess-errors "" } #include <deque> diff --git a/libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/insert_neg.cc b/libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/insert_neg.cc index cdacae483f93..8709c4658d2b 100644 --- a/libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/insert_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/insert_neg.cc @@ -18,7 +18,7 @@ // <http://www.gnu.org/licenses/>. // { dg-do compile } -// { dg-error "no matching" "" { target *-*-* } 1586 } +// { dg-error "no matching" "" { target *-*-* } 1618 } // { dg-excess-errors "" } #include <deque> diff --git a/libstdc++-v3/testsuite/25_algorithms/copy/5.cc b/libstdc++-v3/testsuite/25_algorithms/copy/5.cc new file mode 100644 index 000000000000..5d100e8714dc --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/copy/5.cc @@ -0,0 +1,51 @@ +// 2009-12-23 Paolo Carlini <paolo.carlini@oracle.com> +// +// 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 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without Pred 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <algorithm> +#include <deque> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + deque<long> data(200); + for (unsigned i = 0; i < data.size(); ++i) + data[i] = i; + + const deque<long> data_1(data.size(), -1); + + for (unsigned i = 0; i < data.size(); i += 2) + for (unsigned j = i; j <= data.size(); j += 3) + for (unsigned k = 0; k + (j - i) <= data.size(); k += 5) + { + deque<long> d(data.size(), -1); + copy(data.begin() + i, data.begin() + j, d.begin() + k); + + VERIFY( equal(data.begin() + i, data.begin() + j, + d.begin() + k) ); + VERIFY( equal(d.begin(), d.begin() + k, data_1.begin()) ); + VERIFY( equal(d.begin() + k + (j - i), d.end(), data_1.begin()) ); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/move/2.cc b/libstdc++-v3/testsuite/25_algorithms/move/2.cc new file mode 100644 index 000000000000..0e0debf7baaa --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/move/2.cc @@ -0,0 +1,53 @@ +// { dg-options "-std=gnu++0x" } + +// 2009-12-23 Paolo Carlini <paolo.carlini@oracle.com> +// +// 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 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without Pred 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <algorithm> +#include <deque> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + deque<long> data(200); + for (unsigned i = 0; i < data.size(); ++i) + data[i] = i; + + const deque<long> data_1(data.size(), -1); + + for (unsigned i = 0; i < data.size(); i += 2) + for (unsigned j = i; j <= data.size(); j += 3) + for (unsigned k = 0; k + (j - i) <= data.size(); k += 5) + { + deque<long> d(data.size(), -1); + move(data.begin() + i, data.begin() + j, d.begin() + k); + + VERIFY( equal(data.begin() + i, data.begin() + j, + d.begin() + k) ); + VERIFY( equal(d.begin(), d.begin() + k, data_1.begin()) ); + VERIFY( equal(d.begin() + k + (j - i), d.end(), data_1.begin()) ); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/performance/25_algorithms/copy_deque_iterators.cc b/libstdc++-v3/testsuite/performance/25_algorithms/copy_deque_iterators.cc new file mode 100644 index 000000000000..4318bd4f4605 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/25_algorithms/copy_deque_iterators.cc @@ -0,0 +1,40 @@ +// 2009-23-12 Paolo Carlini <paolo.carlini@oracle.com> +// +// 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 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without Pred 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <deque> +#include <testsuite_performance.h> + +int main() +{ + using namespace __gnu_test; + + time_counter time; + resource_counter resource; + + const std::deque<int> data(3000, 3); + + std::deque<int> d(3000, 1); + + start_counters(time, resource); + for (int i = 0; i < 1000; ++i) + for (int j = 0; j < 3000; ++j) + std::copy(data.begin(), data.begin() + j, d.begin()); + stop_counters(time, resource); + report_performance(__FILE__, "", time, resource); + + return 0; +} -- GitLab