]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
stl_deque.h (copy_backward(_Deque_iterator, _Deque_iterator, _Deque_iterator), [...
authorPaolo Carlini <paolo.carlini@oracle.com>
Thu, 24 Dec 2009 12:47:37 +0000 (12:47 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Thu, 24 Dec 2009 12:47:37 +0000 (12:47 +0000)
2009-12-24  Paolo Carlini  <paolo.carlini@oracle.com>

* include/bits/stl_deque.h (copy_backward(_Deque_iterator,
_Deque_iterator, _Deque_iterator), move_backward(_Deque_iterator,
_Deque_iterator, _Deque_iterator)): Declare.
* include/bits/deque.tcc: Implement the latter.
* testsuite/performance/25_algorithms/
copy_backward_deque_iterators.cc: New.
* testsuite/25_algorithms/move_backward/deque_iterators/1.cc: Likewise.
* testsuite/25_algorithms/copy_backward/deque_iterators/1.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: r155455

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/deque.tcc
libstdc++-v3/include/bits/stl_deque.h
libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/assign_neg.cc
libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/constructor_1_neg.cc
libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/constructor_2_neg.cc
libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/insert_neg.cc
libstdc++-v3/testsuite/25_algorithms/copy_backward/deque_iterators/1.cc [new file with mode: 0644]
libstdc++-v3/testsuite/25_algorithms/move_backward/deque_iterators/1.cc [new file with mode: 0644]
libstdc++-v3/testsuite/performance/25_algorithms/copy_backward_deque_iterators.cc [new file with mode: 0644]

index e6c277ccfd1b979ea1099c9c2ad088158d61a328..4ca96b2878aa8cae671847132b0e1fb68280f1e5 100644 (file)
@@ -1,3 +1,22 @@
+2009-12-24  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       * include/bits/stl_deque.h (copy_backward(_Deque_iterator,
+       _Deque_iterator, _Deque_iterator), move_backward(_Deque_iterator,
+       _Deque_iterator, _Deque_iterator)): Declare.
+       * include/bits/deque.tcc: Implement the latter.
+       * testsuite/performance/25_algorithms/
+       copy_backward_deque_iterators.cc: New.
+       * testsuite/25_algorithms/move_backward/deque_iterators/1.cc: Likewise.
+       * testsuite/25_algorithms/copy_backward/deque_iterators/1.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-23  Paolo Carlini  <paolo.carlini@oracle.com>
 
        * testsuite/25_algorithms/copy/5.cc: Move...
index 968fc0051c5da67dac42493104cfff23b8505b3f..cde067cf382c1da5aa4bc2573912b97bfeb74eee 100644 (file)
@@ -865,11 +865,12 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
         _Deque_iterator<_Tp, _Tp&, _Tp*> __result)
     {
       typedef typename _Deque_iterator<_Tp, _Tp&, _Tp*>::_Self _Self;
+      typedef typename _Self::difference_type difference_type;
 
-      typename _Self::difference_type __len = __last - __first;
+      difference_type __len = __last - __first;
       while (__len > 0)
        {
-         typename _Self::difference_type __clen
+         const 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);
@@ -880,6 +881,45 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
       return __result;
     }
 
+  template<typename _Tp>
+    _Deque_iterator<_Tp, _Tp&, _Tp*>
+    copy_backward(_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;
+      typedef typename _Self::difference_type difference_type;
+
+      difference_type __len = __last - __first;
+      while (__len > 0)
+       {
+         difference_type __llen = __last._M_cur - __last._M_first;
+         _Tp* __lend = __last._M_cur;
+
+         difference_type __rlen = __result._M_cur - __result._M_first;
+         _Tp* __rend = __result._M_cur;
+
+         if (!__llen)
+           {
+             __llen = _Self::_S_buffer_size();
+             __lend = *(__last._M_node - 1) + __llen;
+           }
+         if (!__rlen)
+           {
+             __rlen = _Self::_S_buffer_size();
+             __rend = *(__result._M_node - 1) + __rlen;
+           }
+
+         const difference_type __clen = std::min(__len,
+                                                 std::min(__llen, __rlen));
+         std::copy_backward(__lend - __clen, __lend, __rend);
+         __last -= __clen;
+         __result -= __clen;
+         __len -= __clen;
+       }
+      return __result;
+    }
+
 #ifdef __GXX_EXPERIMENTAL_CXX0X__
   template<typename _Tp>
     _Deque_iterator<_Tp, _Tp&, _Tp*>
@@ -888,11 +928,12 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
         _Deque_iterator<_Tp, _Tp&, _Tp*> __result)
     {
       typedef typename _Deque_iterator<_Tp, _Tp&, _Tp*>::_Self _Self;
+      typedef typename _Self::difference_type difference_type;
 
-      typename _Self::difference_type __len = __last - __first;
+      difference_type __len = __last - __first;
       while (__len > 0)
        {
-         const typename _Self::difference_type __clen
+         const 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);
@@ -902,6 +943,45 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
        }
       return __result;
     }
+
+  template<typename _Tp>
+    _Deque_iterator<_Tp, _Tp&, _Tp*>
+    move_backward(_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;
+      typedef typename _Self::difference_type difference_type;
+
+      difference_type __len = __last - __first;
+      while (__len > 0)
+       {
+         difference_type __llen = __last._M_cur - __last._M_first;
+         _Tp* __lend = __last._M_cur;
+
+         difference_type __rlen = __result._M_cur - __result._M_first;
+         _Tp* __rend = __result._M_cur;
+
+         if (!__llen)
+           {
+             __llen = _Self::_S_buffer_size();
+             __lend = *(__last._M_node - 1) + __llen;
+           }
+         if (!__rlen)
+           {
+             __rlen = _Self::_S_buffer_size();
+             __rend = *(__result._M_node - 1) + __rlen;
+           }
+
+         const difference_type __clen = std::min(__len,
+                                                 std::min(__llen, __rlen));
+         std::move_backward(__lend - __clen, __lend, __rend);
+         __last -= __clen;
+         __result -= __clen;
+         __len -= __clen;
+       }
+      return __result;
+    }
 #endif
 
 _GLIBCXX_END_NESTED_NAMESPACE
index 99105ebdcd48e46c3dec4dd9196c198b02805e75..647d5476874381652dc559710acdf0049095fcf0 100644 (file)
@@ -370,6 +370,23 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
                       _Deque_iterator<_Tp, const _Tp&, const _Tp*>(__last),
                       __result); }
 
+  template<typename _Tp>
+    _Deque_iterator<_Tp, _Tp&, _Tp*>
+    copy_backward(_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_backward(_Deque_iterator<_Tp, _Tp&, _Tp*> __first,
+                 _Deque_iterator<_Tp, _Tp&, _Tp*> __last,
+                 _Deque_iterator<_Tp, _Tp&, _Tp*> __result)
+    { return std::copy_backward(_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*>
@@ -385,6 +402,23 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
     { return std::move(_Deque_iterator<_Tp, const _Tp&, const _Tp*>(__first),
                       _Deque_iterator<_Tp, const _Tp&, const _Tp*>(__last),
                       __result); }
+
+  template<typename _Tp>
+    _Deque_iterator<_Tp, _Tp&, _Tp*>
+    move_backward(_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_backward(_Deque_iterator<_Tp, _Tp&, _Tp*> __first,
+                 _Deque_iterator<_Tp, _Tp&, _Tp*> __last,
+                 _Deque_iterator<_Tp, _Tp&, _Tp*> __result)
+    { return std::move_backward(_Deque_iterator<_Tp,
+                               const _Tp&, const _Tp*>(__first),
+                               _Deque_iterator<_Tp,
+                               const _Tp&, const _Tp*>(__last),
+                               __result); }
 #endif
 
   /**
index b022e14a6095578366a9450a6cac4076a2ccf043..0b948aed7fbf426e3e2808662507d86514395d78 100644 (file)
@@ -18,7 +18,7 @@
 // <http://www.gnu.org/licenses/>.
 
 // { dg-do compile }
-// { dg-error "no matching" "" { target *-*-* } 1534 }
+// { dg-error "no matching" "" { target *-*-* } 1568 }
 // { dg-excess-errors "" }
 
 #include <deque>
index a43f2c707a5d7e58b59ac0d30dcbce0dd5af32cc..2f88aa8eb8035d3a88237f97130975dc432eea95 100644 (file)
@@ -18,7 +18,7 @@
 // <http://www.gnu.org/licenses/>.
 
 // { dg-do compile }
-// { dg-error "no matching" "" { target *-*-* } 1473 }
+// { dg-error "no matching" "" { target *-*-* } 1507 }
 // { dg-excess-errors "" }
 
 #include <deque>
index 71a4ceb3c6910898201bb9001668fe6d13451fa8..3895d1e875866c350470381fdc56003a73c44d89 100644 (file)
@@ -18,7 +18,7 @@
 // <http://www.gnu.org/licenses/>.
 
 // { dg-do compile }
-// { dg-error "no matching" "" { target *-*-* } 1473 }
+// { dg-error "no matching" "" { target *-*-* } 1507 }
 // { dg-excess-errors "" }
 
 #include <deque>
index 8709c4658d2b19911e2fc4e471c03fa819d9a62f..50d8d4657a13b416a69c8fd4507d027ac5e9f839 100644 (file)
@@ -18,7 +18,7 @@
 // <http://www.gnu.org/licenses/>.
 
 // { dg-do compile }
-// { dg-error "no matching" "" { target *-*-* } 1618 }
+// { dg-error "no matching" "" { target *-*-* } 1652 }
 // { dg-excess-errors "" }
 
 #include <deque>
diff --git a/libstdc++-v3/testsuite/25_algorithms/copy_backward/deque_iterators/1.cc b/libstdc++-v3/testsuite/25_algorithms/copy_backward/deque_iterators/1.cc
new file mode 100644 (file)
index 0000000..57405cc
--- /dev/null
@@ -0,0 +1,52 @@
+// 2009-12-24  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_backward(data.begin() + i, data.begin() + j,
+                       d.begin() + k + (j - i));
+
+         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_backward/deque_iterators/1.cc b/libstdc++-v3/testsuite/25_algorithms/move_backward/deque_iterators/1.cc
new file mode 100644 (file)
index 0000000..9a8ba71
--- /dev/null
@@ -0,0 +1,54 @@
+// { dg-options "-std=gnu++0x" }
+
+// 2009-12-24  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_backward(data.begin() + i, data.begin() + j,
+                       d.begin() + k + (j - i));
+
+         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_backward_deque_iterators.cc b/libstdc++-v3/testsuite/performance/25_algorithms/copy_backward_deque_iterators.cc
new file mode 100644 (file)
index 0000000..c7dbdc0
--- /dev/null
@@ -0,0 +1,40 @@
+// 2009-24-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_backward(data.begin(), data.begin() + j, d.end());
+  stop_counters(time, resource);
+  report_performance(__FILE__, "", time, resource);
+
+  return 0;
+}