diff options
author | paolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-10-19 17:04:59 +0000 |
---|---|---|
committer | paolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-10-19 17:04:59 +0000 |
commit | 43356e9370933c52e09fa4d63db50a968f813a30 (patch) | |
tree | e051d19e5b8a4a223957782a1cae73c554c01892 /libstdc++-v3 | |
parent | b35a8f4864f6fdabc2a47ad3c650248bbc6a4be7 (diff) | |
download | gcc-43356e9370933c52e09fa4d63db50a968f813a30.tar.gz |
2007-10-19 Paolo Carlini <pcarlini@suse.de>
* include/bits/stl_algobase.h (struct __cm_assign,
struct __copy_move, struct __copy_move_backward, move,
move_backward): Add.
(struct __copy, struct __copy_backward): Remove.
(__copy_aux, __copy_backward_aux): Rename to...
(__copy_move_a, __copy_move_backward_a): ... this, and
adjust calls.
(copy, copy_backward): Adjust calls.
* include/bits/streambuf_iterator.h (__copy_aux): Rename
to ...
(__copy_move_a): ... this; add bool template parameter.
* include/std/streambuf: Adjust friend declarations.
* testsuite/util/testsuite_iterators.h
(WritableObject<>::operator=(U&&)): Add.
* testsuite/25_algorithms/move/1.cc: New.
* testsuite/25_algorithms/move/requirements/
explicit_instantiation/2.cc: Likewise.
* testsuite/25_algorithms/move/requirements/
explicit_instantiation/pod.cc: Likewise.
* testsuite/25_algorithms/move_backward/1.cc: Likewise.
* testsuite/25_algorithms/move_backward/requirements/
explicit_instantiation/2.cc: Likewise.
* testsuite/25_algorithms/move_backward/requirements/
explicit_instantiation/pod.cc: Likewise.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@129492 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3')
11 files changed, 505 insertions, 63 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 6d3ed26b139..b12b8b38306 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,30 @@ +2007-10-19 Paolo Carlini <pcarlini@suse.de> + + * include/bits/stl_algobase.h (struct __cm_assign, + struct __copy_move, struct __copy_move_backward, move, + move_backward): Add. + (struct __copy, struct __copy_backward): Remove. + (__copy_aux, __copy_backward_aux): Rename to... + (__copy_move_a, __copy_move_backward_a): ... this, and + adjust calls. + (copy, copy_backward): Adjust calls. + * include/bits/streambuf_iterator.h (__copy_aux): Rename + to ... + (__copy_move_a): ... this; add bool template parameter. + * include/std/streambuf: Adjust friend declarations. + * testsuite/util/testsuite_iterators.h + (WritableObject<>::operator=(U&&)): Add. + * testsuite/25_algorithms/move/1.cc: New. + * testsuite/25_algorithms/move/requirements/ + explicit_instantiation/2.cc: Likewise. + * testsuite/25_algorithms/move/requirements/ + explicit_instantiation/pod.cc: Likewise. + * testsuite/25_algorithms/move_backward/1.cc: Likewise. + * testsuite/25_algorithms/move_backward/requirements/ + explicit_instantiation/2.cc: Likewise. + * testsuite/25_algorithms/move_backward/requirements/ + explicit_instantiation/pod.cc: Likewise. + 2007-10-18 Kaz Kojima <kkojima@gcc.gnu.org> * testsuite/tr1/5_numerical_facilities/special_functions/ diff --git a/libstdc++-v3/include/bits/stl_algobase.h b/libstdc++-v3/include/bits/stl_algobase.h index 55c0eb24e50..6a6e2e03bd4 100644 --- a/libstdc++-v3/include/bits/stl_algobase.h +++ b/libstdc++-v3/include/bits/stl_algobase.h @@ -282,36 +282,57 @@ _GLIBCXX_BEGIN_NAMESPACE(std) { return __it.base(); } }; + // Used in __copy_move and __copy_move_backward below. + template<bool _IsCopy> + struct __cm_assign + { + template<typename _IteratorL, typename _IteratorR> + static void + __a(_IteratorL __lhs, _IteratorR __rhs) + { *__lhs = *__rhs; } + }; + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + template<> + struct __cm_assign<false> + { + template<typename _IteratorL, typename _IteratorR> + static void + __a(_IteratorL __lhs, _IteratorR __rhs) + { *__lhs = std::move(*__rhs); } + }; +#endif + // All of these auxiliary structs serve two purposes. (1) Replace // calls to copy with memmove whenever possible. (Memmove, not memcpy, // because the input and output ranges are permitted to overlap.) // (2) If we're using random access iterators, then write the loop as // a for loop with an explicit count. - template<bool, typename> - struct __copy + template<bool _IsCopy, bool, typename> + struct __copy_move { template<typename _II, typename _OI> static _OI - copy(_II __first, _II __last, _OI __result) + __copy_m(_II __first, _II __last, _OI __result) { for (; __first != __last; ++__result, ++__first) - *__result = *__first; + std::__cm_assign<_IsCopy>::__a(__result, __first); return __result; } }; - template<bool _BoolType> - struct __copy<_BoolType, random_access_iterator_tag> + template<bool _IsCopy, bool _IsSimple> + struct __copy_move<_IsCopy, _IsSimple, random_access_iterator_tag> { template<typename _II, typename _OI> static _OI - copy(_II __first, _II __last, _OI __result) + __copy_m(_II __first, _II __last, _OI __result) { typedef typename iterator_traits<_II>::difference_type _Distance; for(_Distance __n = __last - __first; __n > 0; --__n) { - *__result = *__first; + std::__cm_assign<_IsCopy>::__a(__result, __first); ++__first; ++__result; } @@ -319,22 +340,22 @@ _GLIBCXX_BEGIN_NAMESPACE(std) } }; - template<> - struct __copy<true, random_access_iterator_tag> + template<bool _IsCopy> + struct __copy_move<_IsCopy, true, random_access_iterator_tag> { template<typename _Tp> static _Tp* - copy(const _Tp* __first, const _Tp* __last, _Tp* __result) - { + __copy_m(const _Tp* __first, const _Tp* __last, _Tp* __result) + { __builtin_memmove(__result, __first, sizeof(_Tp) * (__last - __first)); return __result + (__last - __first); } }; - template<typename _II, typename _OI> + template<bool _IsCopy, typename _II, typename _OI> inline _OI - __copy_aux(_II __first, _II __last, _OI __result) + __copy_move_a(_II __first, _II __last, _OI __result) { typedef typename iterator_traits<_II>::value_type _ValueTypeI; typedef typename iterator_traits<_OI>::value_type _ValueTypeO; @@ -344,7 +365,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std) && __is_pointer<_OI>::__value && __are_same<_ValueTypeI, _ValueTypeO>::__value); - return std::__copy<__simple, _Category>::copy(__first, __last, __result); + return std::__copy_move<_IsCopy, __simple, + _Category>::__copy_m(__first, __last, __result); } // Helpers for streambuf iterators (either istream or ostream). @@ -358,23 +380,23 @@ _GLIBCXX_BEGIN_NAMESPACE(std) template<typename _CharT, typename _Traits> class ostreambuf_iterator; - template<typename _CharT> + template<bool _IsCopy, typename _CharT> typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value, ostreambuf_iterator<_CharT, char_traits<_CharT> > >::__type - __copy_aux(_CharT*, _CharT*, - ostreambuf_iterator<_CharT, char_traits<_CharT> >); + __copy_move_a(_CharT*, _CharT*, + ostreambuf_iterator<_CharT, char_traits<_CharT> >); - template<typename _CharT> + template<bool _IsCopy, typename _CharT> typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value, ostreambuf_iterator<_CharT, char_traits<_CharT> > >::__type - __copy_aux(const _CharT*, const _CharT*, - ostreambuf_iterator<_CharT, char_traits<_CharT> >); + __copy_move_a(const _CharT*, const _CharT*, + ostreambuf_iterator<_CharT, char_traits<_CharT> >); - template<typename _CharT> + template<bool _IsCopy, typename _CharT> typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value, _CharT*>::__type - __copy_aux(istreambuf_iterator<_CharT, char_traits<_CharT> >, - istreambuf_iterator<_CharT, char_traits<_CharT> >, _CharT*); + __copy_move_a(istreambuf_iterator<_CharT, char_traits<_CharT> >, + istreambuf_iterator<_CharT, char_traits<_CharT> >, _CharT*); /** * @brief Copies the range [first,last) into result. @@ -402,55 +424,89 @@ _GLIBCXX_BEGIN_NAMESPACE(std) typename iterator_traits<_II>::value_type>) __glibcxx_requires_valid_range(__first, __last); - return _OI(std::__copy_aux(__niter_base<_II>::__b(__first), - __niter_base<_II>::__b(__last), - __niter_base<_OI>::__b(__result))); + return _OI(std::__copy_move_a<true> + (std::__niter_base<_II>::__b(__first), + std::__niter_base<_II>::__b(__last), + std::__niter_base<_OI>::__b(__result))); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + /** + * @brief Moves the range [first,last) into result. + * @param first An input iterator. + * @param last An input iterator. + * @param result An output iterator. + * @return result + (first - last) + * + * This inline function will boil down to a call to @c memmove whenever + * possible. Failing that, if random access iterators are passed, then the + * loop count will be known (and therefore a candidate for compiler + * optimizations such as unrolling). Result may not be contained within + * [first,last); the move_backward function should be used instead. + * + * Note that the end of the output range is permitted to be contained + * within [first,last). + */ + template<typename _II, typename _OI> + inline _OI + move(_II __first, _II __last, _OI __result) + { + // concept requirements + __glibcxx_function_requires(_InputIteratorConcept<_II>) + __glibcxx_function_requires(_OutputIteratorConcept<_OI, + typename iterator_traits<_II>::value_type>) + __glibcxx_requires_valid_range(__first, __last); - template<bool, typename> - struct __copy_backward + return _OI(std::__copy_move_a<false> + (std::__niter_base<_II>::__b(__first), + std::__niter_base<_II>::__b(__last), + std::__niter_base<_OI>::__b(__result))); + } +#endif + + template<bool _IsCopy, bool, typename> + struct __copy_move_backward { template<typename _BI1, typename _BI2> static _BI2 - __copy_b(_BI1 __first, _BI1 __last, _BI2 __result) - { + __copy_move_b(_BI1 __first, _BI1 __last, _BI2 __result) + { while (__first != __last) - *--__result = *--__last; + std::__cm_assign<_IsCopy>::__a(--__result, --__last); return __result; } }; - template<bool _BoolType> - struct __copy_backward<_BoolType, random_access_iterator_tag> + template<bool _IsCopy, bool _IsSimple> + struct __copy_move_backward<_IsCopy, _IsSimple, random_access_iterator_tag> { template<typename _BI1, typename _BI2> static _BI2 - __copy_b(_BI1 __first, _BI1 __last, _BI2 __result) - { + __copy_move_b(_BI1 __first, _BI1 __last, _BI2 __result) + { typename iterator_traits<_BI1>::difference_type __n; for (__n = __last - __first; __n > 0; --__n) - *--__result = *--__last; + std::__cm_assign<_IsCopy>::__a(--__result, --__last); return __result; } }; - template<> - struct __copy_backward<true, random_access_iterator_tag> + template<bool _IsCopy> + struct __copy_move_backward<_IsCopy, true, random_access_iterator_tag> { template<typename _Tp> static _Tp* - __copy_b(const _Tp* __first, const _Tp* __last, _Tp* __result) - { + __copy_move_b(const _Tp* __first, const _Tp* __last, _Tp* __result) + { const ptrdiff_t _Num = __last - __first; __builtin_memmove(__result - _Num, __first, sizeof(_Tp) * _Num); return __result - _Num; } }; - template<typename _BI1, typename _BI2> + template<bool _IsCopy, typename _BI1, typename _BI2> inline _BI2 - __copy_backward_aux(_BI1 __first, _BI1 __last, _BI2 __result) + __copy_move_backward_a(_BI1 __first, _BI1 __last, _BI2 __result) { typedef typename iterator_traits<_BI1>::value_type _ValueType1; typedef typename iterator_traits<_BI2>::value_type _ValueType2; @@ -460,7 +516,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std) && __is_pointer<_BI2>::__value && __are_same<_ValueType1, _ValueType2>::__value); - return std::__copy_backward<__simple, _Category>::__copy_b(__first, + return std::__copy_move_backward<_IsCopy, __simple, + _Category>::__copy_move_b(__first, __last, __result); } @@ -494,11 +551,48 @@ _GLIBCXX_BEGIN_NAMESPACE(std) typename iterator_traits<_BI2>::value_type>) __glibcxx_requires_valid_range(__first, __last); - return _BI2(std::__copy_backward_aux(__niter_base<_BI1>::__b(__first), - __niter_base<_BI1>::__b(__last), - __niter_base<_BI2>::__b(__result))); + return _BI2(std::__copy_move_backward_a<true> + (std::__niter_base<_BI1>::__b(__first), + std::__niter_base<_BI1>::__b(__last), + std::__niter_base<_BI2>::__b(__result))); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + /** + * @brief Moves the range [first,last) into result. + * @param first A bidirectional iterator. + * @param last A bidirectional iterator. + * @param result A bidirectional iterator. + * @return result - (first - last) + * + * The function has the same effect as move, but starts at the end of the + * range and works its way to the start, returning the start of the result. + * This inline function will boil down to a call to @c memmove whenever + * possible. Failing that, if random access iterators are passed, then the + * loop count will be known (and therefore a candidate for compiler + * optimizations such as unrolling). + * + * Result may not be in the range [first,last). Use move instead. Note + * that the start of the output range may overlap [first,last). + */ + template<typename _BI1, typename _BI2> + inline _BI2 + move_backward(_BI1 __first, _BI1 __last, _BI2 __result) + { + // concept requirements + __glibcxx_function_requires(_BidirectionalIteratorConcept<_BI1>) + __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<_BI2>) + __glibcxx_function_requires(_ConvertibleConcept< + typename iterator_traits<_BI1>::value_type, + typename iterator_traits<_BI2>::value_type>) + __glibcxx_requires_valid_range(__first, __last); + + return _BI2(std::__copy_move_backward_a<false> + (std::__niter_base<_BI1>::__b(__first), + std::__niter_base<_BI1>::__b(__last), + std::__niter_base<_BI2>::__b(__result))); + } +#endif template<typename _ForwardIterator, typename _Tp> inline typename diff --git a/libstdc++-v3/include/bits/streambuf_iterator.h b/libstdc++-v3/include/bits/streambuf_iterator.h index 26cc00f8b22..1461f024b67 100644 --- a/libstdc++-v3/include/bits/streambuf_iterator.h +++ b/libstdc++-v3/include/bits/streambuf_iterator.h @@ -1,6 +1,7 @@ // Streambuf iterators -// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, +// 2006, 2007 // Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free @@ -67,11 +68,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) copy(istreambuf_iterator<_CharT2>, istreambuf_iterator<_CharT2>, ostreambuf_iterator<_CharT2>); - template<typename _CharT2> + template<bool _IsCopy, typename _CharT2> friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value, _CharT2*>::__type - __copy_aux(istreambuf_iterator<_CharT2>, istreambuf_iterator<_CharT2>, - _CharT2*); + __copy_move_a(istreambuf_iterator<_CharT2>, + istreambuf_iterator<_CharT2>, _CharT2*); template<typename _CharT2> friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value, @@ -291,11 +292,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) return __result; } - template<typename _CharT> + template<bool _IsCopy, typename _CharT> typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value, ostreambuf_iterator<_CharT> >::__type - __copy_aux(_CharT* __first, _CharT* __last, - ostreambuf_iterator<_CharT> __result) + __copy_move_a(_CharT* __first, _CharT* __last, + ostreambuf_iterator<_CharT> __result) { const streamsize __num = __last - __first; if (__num > 0) @@ -303,11 +304,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) return __result; } - template<typename _CharT> + template<bool _IsCopy, typename _CharT> typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value, ostreambuf_iterator<_CharT> >::__type - __copy_aux(const _CharT* __first, const _CharT* __last, - ostreambuf_iterator<_CharT> __result) + __copy_move_a(const _CharT* __first, const _CharT* __last, + ostreambuf_iterator<_CharT> __result) { const streamsize __num = __last - __first; if (__num > 0) @@ -315,11 +316,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) return __result; } - template<typename _CharT> + template<bool _IsCopy, typename _CharT> typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value, _CharT*>::__type - __copy_aux(istreambuf_iterator<_CharT> __first, - istreambuf_iterator<_CharT> __last, _CharT* __result) + __copy_move_a(istreambuf_iterator<_CharT> __first, + istreambuf_iterator<_CharT> __last, _CharT* __result) { typedef istreambuf_iterator<_CharT> __is_iterator_type; typedef typename __is_iterator_type::traits_type traits_type; diff --git a/libstdc++-v3/include/std/streambuf b/libstdc++-v3/include/std/streambuf index 5e710377ab4..6402e40d7c8 100644 --- a/libstdc++-v3/include/std/streambuf +++ b/libstdc++-v3/include/std/streambuf @@ -155,11 +155,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) friend streamsize __copy_streambufs_eof<>(__streambuf_type*, __streambuf_type*, bool&); - template<typename _CharT2> + template<bool _IsCopy, typename _CharT2> friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value, _CharT2*>::__type - __copy_aux(istreambuf_iterator<_CharT2>, - istreambuf_iterator<_CharT2>, _CharT2*); + __copy_move_a(istreambuf_iterator<_CharT2>, + istreambuf_iterator<_CharT2>, _CharT2*); template<typename _CharT2> friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value, diff --git a/libstdc++-v3/testsuite/25_algorithms/move/1.cc b/libstdc++-v3/testsuite/25_algorithms/move/1.cc new file mode 100644 index 00000000000..7fa0f784054 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/move/1.cc @@ -0,0 +1,64 @@ +// { dg-options "-std=gnu++0x" } + +// 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 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 COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +#undef _GLIBCXX_CONCEPT_CHECKS +#define _GLIBCXX_TESTSUITE_ALLOW_RVALREF_ALIASING + +#include <algorithm> +#include <testsuite_hooks.h> +#include <testsuite_iterators.h> +#include <testsuite_rvalref.h> + +using __gnu_test::test_container; +using __gnu_test::input_iterator_wrapper; +using __gnu_test::output_iterator_wrapper; +using __gnu_test::rvalstruct; +using std::move; + +typedef test_container<rvalstruct, input_iterator_wrapper> container_in; +typedef test_container<rvalstruct, output_iterator_wrapper> container_out; + +void test01() +{ + bool test __attribute__((unused)) = true; + + int inarray[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + const int size = sizeof(inarray) / sizeof(int); + + rvalstruct in[size], out[size]; + std::copy(inarray, inarray + size, in); + std::fill(out, out + size, 0); + + container_in incon(in, in + size); + container_out outcon(out, out + size); + + move(incon.begin(), incon.end(), outcon.begin()); + VERIFY( std::equal(out, out + size, inarray) ); + for (int z = 0; z < size; ++z) + VERIFY( out[z].valid ); + for (int z = 0; z < size; ++z) + VERIFY( !in[z].valid ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/move/requirements/explicit_instantiation/2.cc b/libstdc++-v3/testsuite/25_algorithms/move/requirements/explicit_instantiation/2.cc new file mode 100644 index 00000000000..532c290f9dd --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/move/requirements/explicit_instantiation/2.cc @@ -0,0 +1,44 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// 2007-10-19 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// 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 <algorithm> +#include <testsuite_api.h> + +namespace std +{ + using __gnu_test::NonDefaultConstructible; + + typedef NonDefaultConstructible value_type; + typedef value_type* iterator_type; + + template iterator_type move(iterator_type, iterator_type, iterator_type); +} diff --git a/libstdc++-v3/testsuite/25_algorithms/move/requirements/explicit_instantiation/pod.cc b/libstdc++-v3/testsuite/25_algorithms/move/requirements/explicit_instantiation/pod.cc new file mode 100644 index 00000000000..37aa958670d --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/move/requirements/explicit_instantiation/pod.cc @@ -0,0 +1,44 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// 2007-10-19 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// 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 <algorithm> +#include <testsuite_character.h> + +namespace std +{ + using __gnu_test::pod_int; + + typedef pod_int value_type; + typedef value_type* iterator_type; + + template iterator_type move(iterator_type, iterator_type, iterator_type); +} diff --git a/libstdc++-v3/testsuite/25_algorithms/move_backward/1.cc b/libstdc++-v3/testsuite/25_algorithms/move_backward/1.cc new file mode 100644 index 00000000000..ed742f30ffe --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/move_backward/1.cc @@ -0,0 +1,66 @@ +// { dg-options "-std=gnu++0x" } + +// 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 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 COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +#undef _GLIBCXX_CONCEPT_CHECKS +#define _GLIBCXX_TESTSUITE_ALLOW_RVALREF_ALIASING + +#include <algorithm> +#include <testsuite_hooks.h> +#include <testsuite_iterators.h> +#include <testsuite_rvalref.h> + +using __gnu_test::test_container; +using __gnu_test::bidirectional_iterator_wrapper; +using __gnu_test::rvalstruct; +using std::move_backward; + +typedef test_container<rvalstruct, + bidirectional_iterator_wrapper> container_in; +typedef test_container<rvalstruct, + bidirectional_iterator_wrapper> container_out; + +void test01() +{ + bool test __attribute__((unused)) = true; + + int inarray[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + const int size = sizeof(inarray) / sizeof(int); + + rvalstruct in[size], out[size]; + std::copy(inarray, inarray + size, in); + std::fill(out, out + size, 0); + + container_in incon(in, in + size); + container_out outcon(out, out + size); + + move_backward(incon.begin(), incon.end(), outcon.end()); + VERIFY( std::equal(out, out + size, inarray) ); + for (int z = 0; z < size; ++z) + VERIFY( out[z].valid ); + for (int z = 0; z < size; ++z) + VERIFY( !in[z].valid ); +} + + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/move_backward/requirements/explicit_instantiation/2.cc b/libstdc++-v3/testsuite/25_algorithms/move_backward/requirements/explicit_instantiation/2.cc new file mode 100644 index 00000000000..430ac7af827 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/move_backward/requirements/explicit_instantiation/2.cc @@ -0,0 +1,45 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// 2007-10-19 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// 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 <algorithm> +#include <testsuite_api.h> + +namespace std +{ + using __gnu_test::NonDefaultConstructible; + + typedef NonDefaultConstructible value_type; + typedef value_type* iterator_type; + + template iterator_type move_backward(iterator_type, iterator_type, + iterator_type); +} diff --git a/libstdc++-v3/testsuite/25_algorithms/move_backward/requirements/explicit_instantiation/pod.cc b/libstdc++-v3/testsuite/25_algorithms/move_backward/requirements/explicit_instantiation/pod.cc new file mode 100644 index 00000000000..a1c32417719 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/move_backward/requirements/explicit_instantiation/pod.cc @@ -0,0 +1,45 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// 2007-10-19 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// 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 <algorithm> +#include <testsuite_character.h> + +namespace std +{ + using __gnu_test::pod_int; + + typedef pod_int value_type; + typedef value_type* iterator_type; + + template iterator_type move_backward(iterator_type, iterator_type, + iterator_type); +} diff --git a/libstdc++-v3/testsuite/util/testsuite_iterators.h b/libstdc++-v3/testsuite/util/testsuite_iterators.h index 760086710e6..7a124196137 100644 --- a/libstdc++-v3/testsuite/util/testsuite_iterators.h +++ b/libstdc++-v3/testsuite/util/testsuite_iterators.h @@ -38,6 +38,7 @@ #include <testsuite_hooks.h> #include <bits/stl_iterator_base_types.h> +#include <bits/stl_move.h> #ifndef _TESTSUITE_ITERATORS #define _TESTSUITE_ITERATORS @@ -103,6 +104,17 @@ namespace __gnu_test SharedInfo->writtento[ptr - SharedInfo->first] = 1; *ptr = new_val; } + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + template<class U> + void + operator=(U&& new_val) + { + ITERATOR_VERIFY(SharedInfo->writtento[ptr - SharedInfo->first] == 0); + SharedInfo->writtento[ptr - SharedInfo->first] = 1; + *ptr = std::move(new_val); + } +#endif }; /** |