mirror of git://gcc.gnu.org/git/gcc.git
stl_algobase.h (_GLIBCXX_MOVE3, [...]): Add.
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
This commit is contained in:
parent
a3ef23490a
commit
245a5fe5c0
|
@ -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>
|
2007-10-28 Paolo Carlini <pcarlini@suse.de>
|
||||||
|
|
||||||
* include/bits/stl_uninitialized.h (uninitialized_copy): Use
|
* include/bits/stl_uninitialized.h (uninitialized_copy): Use
|
||||||
|
|
|
@ -117,13 +117,13 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
|
||||||
if (static_cast<size_type>(__index) < (size() >> 1))
|
if (static_cast<size_type>(__index) < (size() >> 1))
|
||||||
{
|
{
|
||||||
if (__position != begin())
|
if (__position != begin())
|
||||||
std::copy_backward(begin(), __position, __next);
|
_GLIBCXX_MOVE_BACKWARD3(begin(), __position, __next);
|
||||||
pop_front();
|
pop_front();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (__next != end())
|
if (__next != end())
|
||||||
std::copy(__next, end(), __position);
|
_GLIBCXX_MOVE3(__next, end(), __position);
|
||||||
pop_back();
|
pop_back();
|
||||||
}
|
}
|
||||||
return begin() + __index;
|
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 (static_cast<size_type>(__elems_before) <= (size() - __n) / 2)
|
||||||
{
|
{
|
||||||
if (__first != begin())
|
if (__first != begin())
|
||||||
std::copy_backward(begin(), __first, __last);
|
_GLIBCXX_MOVE_BACKWARD3(begin(), __first, __last);
|
||||||
_M_erase_at_begin(begin() + __n);
|
_M_erase_at_begin(begin() + __n);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (__last != end())
|
if (__last != end())
|
||||||
std::copy(__last, end(), __first);
|
_GLIBCXX_MOVE3(__last, end(), __first);
|
||||||
_M_erase_at_end(end() - __n);
|
_M_erase_at_end(end() - __n);
|
||||||
}
|
}
|
||||||
return begin() + __elems_before;
|
return begin() + __elems_before;
|
||||||
|
|
|
@ -488,6 +488,10 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
|
||||||
(std::__miter_base<_II>::__b(__first),
|
(std::__miter_base<_II>::__b(__first),
|
||||||
std::__miter_base<_II>::__b(__last), __result));
|
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
|
#endif
|
||||||
|
|
||||||
template<bool _IsMove, bool, typename>
|
template<bool _IsMove, bool, typename>
|
||||||
|
@ -626,6 +630,10 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
|
||||||
(std::__miter_base<_BI1>::__b(__first),
|
(std::__miter_base<_BI1>::__b(__first),
|
||||||
std::__miter_base<_BI1>::__b(__last), __result));
|
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
|
#endif
|
||||||
|
|
||||||
template<typename _ForwardIterator, typename _Tp>
|
template<typename _ForwardIterator, typename _Tp>
|
||||||
|
|
|
@ -1021,6 +1021,9 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
|
||||||
|
|
||||||
_GLIBCXX_END_NAMESPACE
|
_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 // __GXX_EXPERIMENTAL_CXX0X__
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -74,8 +74,9 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
|
||||||
if (this->capacity() < __n)
|
if (this->capacity() < __n)
|
||||||
{
|
{
|
||||||
const size_type __old_size = size();
|
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_finish);
|
_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,
|
std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
|
||||||
_M_get_Tp_allocator());
|
_M_get_Tp_allocator());
|
||||||
_M_deallocate(this->_M_impl._M_start,
|
_M_deallocate(this->_M_impl._M_start,
|
||||||
|
@ -110,7 +111,7 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
|
||||||
erase(iterator __position)
|
erase(iterator __position)
|
||||||
{
|
{
|
||||||
if (__position + 1 != end())
|
if (__position + 1 != end())
|
||||||
std::copy(__position + 1, end(), __position);
|
_GLIBCXX_MOVE3(__position + 1, end(), __position);
|
||||||
--this->_M_impl._M_finish;
|
--this->_M_impl._M_finish;
|
||||||
this->_M_impl.destroy(this->_M_impl._M_finish);
|
this->_M_impl.destroy(this->_M_impl._M_finish);
|
||||||
return __position;
|
return __position;
|
||||||
|
@ -122,7 +123,7 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
|
||||||
erase(iterator __first, iterator __last)
|
erase(iterator __first, iterator __last)
|
||||||
{
|
{
|
||||||
if (__last != end())
|
if (__last != end())
|
||||||
std::copy(__last, end(), __first);
|
_GLIBCXX_MOVE3(__last, end(), __first);
|
||||||
_M_erase_at_end(__first.base() + (end() - __last));
|
_M_erase_at_end(__first.base() + (end() - __last));
|
||||||
return __first;
|
return __first;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
Loading…
Reference in New Issue