]> gcc.gnu.org Git - gcc.git/commitdiff
stl_algobase.h (_GLIBCXX_MOVE3, [...]): Add.
authorPaolo Carlini <pcarlini@suse.de>
Mon, 29 Oct 2007 01:59:49 +0000 (01:59 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Mon, 29 Oct 2007 01:59:49 +0000 (01:59 +0000)
2007-10-28  Paolo Carlini  <pcarlini@suse.de>

* 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
libstdc++-v3/include/bits/deque.tcc
libstdc++-v3/include/bits/stl_algobase.h
libstdc++-v3/include/bits/stl_iterator.h
libstdc++-v3/include/bits/vector.tcc
libstdc++-v3/testsuite/23_containers/deque/modifiers/erase/moveable.cc [new file with mode: 0644]
libstdc++-v3/testsuite/23_containers/vector/capacity/reserve/moveable.cc [new file with mode: 0644]
libstdc++-v3/testsuite/23_containers/vector/modifiers/erase/moveable.cc [new file with mode: 0644]

index aa276488e2aa0ac82404fcf5b60d3e58ce2ac934..440c7cdfc423cb23ae97ae2ff8cd11eb86915202 100644 (file)
@@ -1,3 +1,16 @@
+2007-10-28  Paolo Carlini  <pcarlini@suse.de>
+
+       * 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  <pcarlini@suse.de>
 
        * include/bits/stl_uninitialized.h (uninitialized_copy): Use
index b5cacc1e577627073692f6170215f453b645665f..5e9b8923f2242c49a5312a159af5134934975640 100644 (file)
@@ -117,13 +117,13 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
       if (static_cast<size_type>(__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<size_type>(__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;
index 818c7ee458c9f23079d8d9ee71e7c754b2d10881..358983566c308e07c3ea404b9661c6f76567c5b1 100644 (file)
@@ -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<bool _IsMove, bool, typename>
@@ -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<typename _ForwardIterator, typename _Tp>
index f16ac024b9f2c718a94e77b35e740e5621bdbcb6..bc3cbd9f5029650d69c510b552126bc686235b2d 100644 (file)
@@ -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
index 442447c27f17553d12e118ca5192bc8a64ed6845..e15d80d59b7fed1db6c0d82c033873cda2c64e94 100644 (file)
@@ -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 (file)
index 0000000..879d0c2
--- /dev/null
@@ -0,0 +1,71 @@
+// { dg-options "-std=gnu++0x" }
+
+// 2007-10-28  Paolo Carlini  <pcarlini@suse.de>
+
+// 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 <deque>
+#include <testsuite_hooks.h>
+#include <testsuite_rvalref.h>
+
+void
+test01()
+{
+  bool test __attribute__((unused)) = true;
+  using namespace __gnu_test;
+
+  std::deque<copycounter> 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 (file)
index 0000000..481247f
--- /dev/null
@@ -0,0 +1,56 @@
+// { dg-options "-std=gnu++0x" }
+
+// 2007-10-28  Paolo Carlini  <pcarlini@suse.de>
+
+// 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 <vector>
+#include <testsuite_hooks.h>
+#include <testsuite_rvalref.h>
+
+void
+test01()
+{
+  bool test __attribute__((unused)) = true;
+  using namespace __gnu_test;
+
+  std::vector<copycounter> 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 (file)
index 0000000..39e1ea2
--- /dev/null
@@ -0,0 +1,71 @@
+// { dg-options "-std=gnu++0x" }
+
+// 2007-10-28  Paolo Carlini  <pcarlini@suse.de>
+
+// 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 <vector>
+#include <testsuite_hooks.h>
+#include <testsuite_rvalref.h>
+
+void
+test01()
+{
+  bool test __attribute__((unused)) = true;
+  using namespace __gnu_test;
+
+  std::vector<copycounter> 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;
+}
This page took 0.081474 seconds and 5 git commands to generate.