From fdecf98971de2cd51ad53b29775f5d531ac59008 Mon Sep 17 00:00:00 2001 From: paolo Date: Fri, 11 Dec 2009 22:04:56 +0000 Subject: [PATCH] 2009-12-11 Paolo Carlini PR libstdc++/42352 * include/bits/list.tcc (sort): Use _GLIBCXX_MOVE for list::splice and list::merge calls. * testsuite/23_containers/list/operations/42352.cc: New. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@155180 138bc75d-0d04-0410-961f-82ee72b054a4 --- libstdc++-v3/ChangeLog | 7 ++ libstdc++-v3/include/bits/list.tcc | 12 +- libstdc++-v3/include/parallel/numeric | 138 +++++++++++---------- .../23_containers/list/operations/42352.cc | 66 ++++++++++ 4 files changed, 151 insertions(+), 72 deletions(-) create mode 100644 libstdc++-v3/testsuite/23_containers/list/operations/42352.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 68930acc1d8..ebf8931fc15 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,12 @@ 2009-12-11 Paolo Carlini + PR libstdc++/42352 + * include/bits/list.tcc (sort): Use _GLIBCXX_MOVE for list::splice + and list::merge calls. + * testsuite/23_containers/list/operations/42352.cc: New. + +2009-12-11 Paolo Carlini + PR libstdc++/22634, DR 539 [Ready] * include/bits/stl_numeric.h (adjacent_difference): Use std::move at the end of the loop body, per the Ready resolution. diff --git a/libstdc++-v3/include/bits/list.tcc b/libstdc++-v3/include/bits/list.tcc index 899b4181509..c461a41c80d 100644 --- a/libstdc++-v3/include/bits/list.tcc +++ b/libstdc++-v3/include/bits/list.tcc @@ -312,13 +312,13 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) do { - __carry.splice(__carry.begin(), *this, begin()); + __carry.splice(__carry.begin(), _GLIBCXX_MOVE(*this), begin()); for(__counter = &__tmp[0]; __counter != __fill && !__counter->empty(); ++__counter) { - __counter->merge(__carry); + __counter->merge(_GLIBCXX_MOVE(__carry)); __carry.swap(*__counter); } __carry.swap(*__counter); @@ -328,7 +328,7 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) while ( !empty() ); for (__counter = &__tmp[1]; __counter != __fill; ++__counter) - __counter->merge(*(__counter - 1)); + __counter->merge(_GLIBCXX_MOVE(*(__counter - 1))); swap( *(__fill - 1) ); } } @@ -389,13 +389,13 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) do { - __carry.splice(__carry.begin(), *this, begin()); + __carry.splice(__carry.begin(), _GLIBCXX_MOVE(*this), begin()); for(__counter = &__tmp[0]; __counter != __fill && !__counter->empty(); ++__counter) { - __counter->merge(__carry, __comp); + __counter->merge(_GLIBCXX_MOVE(__carry), __comp); __carry.swap(*__counter); } __carry.swap(*__counter); @@ -405,7 +405,7 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) while ( !empty() ); for (__counter = &__tmp[1]; __counter != __fill; ++__counter) - __counter->merge(*(__counter - 1), __comp); + __counter->merge(_GLIBCXX_MOVE(*(__counter - 1)), __comp); swap(*(__fill - 1)); } } diff --git a/libstdc++-v3/include/parallel/numeric b/libstdc++-v3/include/parallel/numeric index 0fc6ddcf2fc..eff597ea70a 100644 --- a/libstdc++-v3/include/parallel/numeric +++ b/libstdc++-v3/include/parallel/numeric @@ -80,8 +80,7 @@ namespace __parallel __gnu_parallel::sequential_tag()); } // Parallel algorithm for random access iterators. - template + template _Tp __accumulate_switch(__RAIter __begin, __RAIter __end, _Tp __init, _BinaryOperation __binary_op, @@ -99,12 +98,12 @@ namespace __parallel __my_selector; __gnu_parallel:: __for_each_template_random_access_ed(__begin, __end, - __gnu_parallel::_Nothing(), - __my_selector, - __gnu_parallel:: - __accumulate_binop_reduct - <_BinaryOperation>(__binary_op), - __res, __res, -1); + __gnu_parallel::_Nothing(), + __my_selector, + __gnu_parallel:: + __accumulate_binop_reduct + <_BinaryOperation>(__binary_op), + __res, __res, -1); return __res; } else @@ -123,8 +122,8 @@ namespace __parallel typedef typename _IteratorTraits::iterator_category _IteratorCategory; return __accumulate_switch(__begin, __end, __init, - __gnu_parallel::_Plus<_Tp, _ValueType>(), - _IteratorCategory(), __parallelism_tag); + __gnu_parallel::_Plus<_Tp, _ValueType>(), + _IteratorCategory(), __parallelism_tag); } template @@ -136,8 +135,8 @@ namespace __parallel typedef typename _IteratorTraits::iterator_category _IteratorCategory; return __accumulate_switch(__begin, __end, __init, - __gnu_parallel::_Plus<_Tp, _ValueType>(), - _IteratorCategory()); + __gnu_parallel::_Plus<_Tp, _ValueType>(), + _IteratorCategory()); } template @@ -149,7 +148,7 @@ namespace __parallel typedef iterator_traits<_IIter> _IteratorTraits; typedef typename _IteratorTraits::iterator_category _IteratorCategory; return __accumulate_switch(__begin, __end, __init, __binary_op, - _IteratorCategory(), __parallelism_tag); + _IteratorCategory(), __parallelism_tag); } template @@ -160,7 +159,7 @@ namespace __parallel typedef iterator_traits<_IIter> _IteratorTraits; typedef typename _IteratorTraits::iterator_category _IteratorCategory; return __accumulate_switch(__begin, __end, __init, __binary_op, - _IteratorCategory()); + _IteratorCategory()); } @@ -188,14 +187,14 @@ namespace __parallel typename _Tp, typename _BinaryFunction1, typename _BinaryFunction2> _Tp __inner_product_switch(_RAIter1 __first1, - _RAIter1 __last1, - _RAIter2 __first2, _Tp __init, - _BinaryFunction1 __binary_op1, - _BinaryFunction2 __binary_op2, - random_access_iterator_tag, - random_access_iterator_tag, - __gnu_parallel::_Parallelism __parallelism_tag - = __gnu_parallel::parallel_unbalanced) + _RAIter1 __last1, + _RAIter2 __first2, _Tp __init, + _BinaryFunction1 __binary_op1, + _BinaryFunction2 __binary_op2, + random_access_iterator_tag, + random_access_iterator_tag, + __gnu_parallel::_Parallelism __parallelism_tag + = __gnu_parallel::parallel_unbalanced) { if (_GLIBCXX_PARALLEL_CONDITION((__last1 - __first1) >= __gnu_parallel::_Settings::get(). @@ -224,13 +223,12 @@ namespace __parallel typename _IteratorTag1, typename _IteratorTag2> inline _Tp __inner_product_switch(_IIter1 __first1, _IIter1 __last1, - _IIter2 __first2, _Tp __init, - _BinaryFunction1 __binary_op1, - _BinaryFunction2 __binary_op2, - _IteratorTag1, _IteratorTag2) - { return inner_product(__first1, __last1, __first2, __init, - __binary_op1, __binary_op2, - __gnu_parallel::sequential_tag()); } + _IIter2 __first2, _Tp __init, + _BinaryFunction1 __binary_op1, + _BinaryFunction2 __binary_op2, + _IteratorTag1, _IteratorTag2) + { return inner_product(__first1, __last1, __first2, __init, __binary_op1, + __binary_op2, __gnu_parallel::sequential_tag()); } template @@ -246,10 +244,10 @@ namespace __parallel typedef iterator_traits<_IIter2> _TraitsType2; typedef typename _TraitsType2::iterator_category _IteratorCategory2; - return __inner_product_switch( - __first1, __last1, __first2, __init, __binary_op1, - __binary_op2, _IteratorCategory1(), _IteratorCategory2(), - __parallelism_tag); + return __inner_product_switch(__first1, __last1, __first2, __init, + __binary_op1, __binary_op2, + _IteratorCategory1(), _IteratorCategory2(), + __parallelism_tag); } template _TraitsType2; typedef typename _TraitsType2::iterator_category _IteratorCategory2; - return __inner_product_switch( - __first1, __last1, __first2, __init, __binary_op1, __binary_op2, - _IteratorCategory1(), _IteratorCategory2()); + return __inner_product_switch(__first1, __last1, __first2, __init, + __binary_op1, __binary_op2, + _IteratorCategory1(), + _IteratorCategory2()); } template @@ -319,7 +318,7 @@ namespace __parallel // Sequential fallback. template + typename _BinaryOperation> inline _OutputIterator partial_sum(_IIter __begin, _IIter __end, _OutputIterator __result, _BinaryOperation __bin_op, __gnu_parallel::sequential_tag) @@ -331,8 +330,8 @@ namespace __parallel typename _IteratorTag2> inline _OutputIterator __partial_sum_switch(_IIter __begin, _IIter __end, - _OutputIterator __result, _BinaryOperation __bin_op, - _IteratorTag1, _IteratorTag2) + _OutputIterator __result, _BinaryOperation __bin_op, + _IteratorTag1, _IteratorTag2) { return _GLIBCXX_STD_P::partial_sum(__begin, __end, __result, __bin_op); } // Parallel algorithm for random access iterators. @@ -340,14 +339,15 @@ namespace __parallel typename _BinaryOperation> _OutputIterator __partial_sum_switch(_IIter __begin, _IIter __end, - _OutputIterator __result, _BinaryOperation __bin_op, - random_access_iterator_tag, random_access_iterator_tag) + _OutputIterator __result, _BinaryOperation __bin_op, + random_access_iterator_tag, + random_access_iterator_tag) { if (_GLIBCXX_PARALLEL_CONDITION( static_cast<__gnu_parallel::_SequenceIndex>(__end - __begin) >= __gnu_parallel::_Settings::get().partial_sum_minimal_n)) return __gnu_parallel::__parallel_partial_sum(__begin, __end, - __result, __bin_op); + __result, __bin_op); else return partial_sum(__begin, __end, __result, __bin_op, __gnu_parallel::sequential_tag()); @@ -376,7 +376,7 @@ namespace __parallel typedef typename _OTraitsType::iterator_category _OIterCategory; return __partial_sum_switch(__begin, __end, __result, __binary_op, - _IIteratorCategory(), _OIterCategory()); + _IIteratorCategory(), _OIterCategory()); } // Sequential fallback. @@ -393,17 +393,18 @@ namespace __parallel adjacent_difference(_IIter __begin, _IIter __end, _OutputIterator __result, _BinaryOperation __bin_op, __gnu_parallel::sequential_tag) - { return _GLIBCXX_STD_P::adjacent_difference( - __begin, __end, __result, __bin_op); } + { return _GLIBCXX_STD_P::adjacent_difference(__begin, __end, + __result, __bin_op); } // Sequential fallback for input iterator case. template inline _OutputIterator - __adjacent_difference_switch( - _IIter __begin, _IIter __end, _OutputIterator __result, - _BinaryOperation __bin_op, _IteratorTag1, _IteratorTag2) + __adjacent_difference_switch(_IIter __begin, _IIter __end, + _OutputIterator __result, + _BinaryOperation __bin_op, _IteratorTag1, + _IteratorTag2) { return adjacent_difference(__begin, __end, __result, __bin_op, __gnu_parallel::sequential_tag()); } @@ -411,12 +412,14 @@ namespace __parallel template _OutputIterator - __adjacent_difference_switch( - _IIter __begin, _IIter __end, _OutputIterator __result, - _BinaryOperation __bin_op, - random_access_iterator_tag, random_access_iterator_tag, - __gnu_parallel::_Parallelism __parallelism_tag - = __gnu_parallel::parallel_balanced) + __adjacent_difference_switch(_IIter __begin, _IIter __end, + _OutputIterator __result, + _BinaryOperation __bin_op, + random_access_iterator_tag, + random_access_iterator_tag, + __gnu_parallel::_Parallelism + __parallelism_tag + = __gnu_parallel::parallel_balanced) { if (_GLIBCXX_PARALLEL_CONDITION( static_cast<__gnu_parallel::_SequenceIndex>(__end - __begin) @@ -451,9 +454,9 @@ namespace __parallel { typedef iterator_traits<_IIter> _TraitsType; typedef typename _TraitsType::value_type _ValueType; - return adjacent_difference( - __begin, __end, __result, std::minus<_ValueType>(), - __parallelism_tag); + return adjacent_difference(__begin, __end, __result, + std::minus<_ValueType>(), + __parallelism_tag); } template @@ -464,7 +467,7 @@ namespace __parallel typedef iterator_traits<_IIter> _TraitsType; typedef typename _TraitsType::value_type _ValueType; return adjacent_difference(__begin, __end, __result, - std::minus<_ValueType>()); + std::minus<_ValueType>()); } template _OTraitsType; typedef typename _OTraitsType::iterator_category _OIterCategory; - return __adjacent_difference_switch( - __begin, __end, __result, __binary_op, - _IIteratorCategory(), _OIterCategory(), __parallelism_tag); + return __adjacent_difference_switch(__begin, __end, __result, + __binary_op, + _IIteratorCategory(), + _OIterCategory(), + __parallelism_tag); } template + typename _BinaryOperation> inline _OutputIterator adjacent_difference(_IIter __begin, _IIter __end, - _OutputIterator __result, _BinaryOperation __binary_op) + _OutputIterator __result, _BinaryOperation __binary_op) { typedef iterator_traits<_IIter> _ITraitsType; typedef typename _ITraitsType::iterator_category _IIteratorCategory; @@ -497,9 +502,10 @@ namespace __parallel typedef iterator_traits<_OutputIterator> _OTraitsType; typedef typename _OTraitsType::iterator_category _OIterCategory; - return __adjacent_difference_switch( - __begin, __end, __result, __binary_op, - _IIteratorCategory(), _OIterCategory()); + return __adjacent_difference_switch(__begin, __end, __result, + __binary_op, + _IIteratorCategory(), + _OIterCategory()); } } // end namespace } // end namespace diff --git a/libstdc++-v3/testsuite/23_containers/list/operations/42352.cc b/libstdc++-v3/testsuite/23_containers/list/operations/42352.cc new file mode 100644 index 00000000000..a61071acc10 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/operations/42352.cc @@ -0,0 +1,66 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2009 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 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 +// . + +#include +#include + +// PR libstdc++/42352 +void test01() +{ + bool test __attribute__((unused)) = true; + + std::list l{3, 2, 4, 1, 5, 9, 0, 8, 6, 7}; + + l.sort(); + + for (auto it = l.begin(); it != l.end(); ++it) + { + static int nn = 0; + VERIFY( *it == nn++ ); + } +} + +void test02() +{ + bool test __attribute__((unused)) = true; + + std::list l{3, 2, 4, 1, 5, 9, 0, 8, 6, 7}; + + struct compare + { + bool + operator()(int const& one, int const& two) const + { return one > two; } + }; + + l.sort(compare()); + + for (auto it = l.begin(); it != l.end(); ++it) + { + static int nn = 9; + VERIFY( *it == nn-- ); + } +} + +int main() +{ + test01(); + test02(); + return 0; +} -- 2.11.0