diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index d1418e3efa4b..f13105a2262b 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,19 @@ +2009-10-05 Paolo Carlini + + * testsuite/lib/libstdc++.exp (check_v3_target_rvalref): Remove. + * testsuite/lib/dg-options.exp (dg-require-rvalref): Likewise. + +2009-10-05 Chris Jefferson + + * include/bits/stl_algo.h (__stable_partition_adaptive, + __rotate_adaptive, __merge_adaptive, __merge_sort_loop): + Extend to work with rvalue references in C++0x mode. + * testsuite/25_algorithms/inplace_merge/moveable2.cc: New. + * testsuite/25_algorithms/inplace_merge/moveable.cc: Likewise. + * testsuite/25_algorithms/stable_partition/moveable.cc: Likewise. + * testsuite/25_algorithms/stable_sort/moveable2.cc: Likewise. + * testsuite/25_algorithms/stable_sort/moveable.cc: Likewise. + 2009-10-04 Benjamin Kosnik * doc/xml/manual/using.xml: Add profile headers. diff --git a/libstdc++-v3/include/bits/stl_algo.h b/libstdc++-v3/include/bits/stl_algo.h index a745295e9b02..70cde1a4bf04 100644 --- a/libstdc++-v3/include/bits/stl_algo.h +++ b/libstdc++-v3/include/bits/stl_algo.h @@ -1862,15 +1862,15 @@ _GLIBCXX_BEGIN_NAMESPACE(std) for (; __first != __last; ++__first) if (__pred(*__first)) { - *__result1 = *__first; + *__result1 = _GLIBCXX_MOVE(*__first); ++__result1; } else { - *__result2 = *__first; + *__result2 = _GLIBCXX_MOVE(*__first); ++__result2; } - std::copy(__buffer, __result2, __result1); + _GLIBCXX_MOVE3(__buffer, __result2, __result1); return __result1; } else @@ -2926,15 +2926,15 @@ _GLIBCXX_BEGIN_NAMESPACE(std) _BidirectionalIterator2 __buffer_end; if (__len1 > __len2 && __len2 <= __buffer_size) { - __buffer_end = std::copy(__middle, __last, __buffer); - std::copy_backward(__first, __middle, __last); - return std::copy(__buffer, __buffer_end, __first); + __buffer_end = _GLIBCXX_MOVE3(__middle, __last, __buffer); + _GLIBCXX_MOVE_BACKWARD3(__first, __middle, __last); + return _GLIBCXX_MOVE3(__buffer, __buffer_end, __first); } else if (__len1 <= __buffer_size) { - __buffer_end = std::copy(__first, __middle, __buffer); - std::copy(__middle, __last, __first); - return std::copy_backward(__buffer, __buffer_end, __last); + __buffer_end = _GLIBCXX_MOVE3(__first, __middle, __buffer); + _GLIBCXX_MOVE3(__middle, __last, __first); + return _GLIBCXX_MOVE_BACKWARD3(__buffer, __buffer_end, __last); } else { @@ -2956,15 +2956,21 @@ _GLIBCXX_BEGIN_NAMESPACE(std) { if (__len1 <= __len2 && __len1 <= __buffer_size) { - _Pointer __buffer_end = std::copy(__first, __middle, __buffer); - _GLIBCXX_STD_P::merge(__buffer, __buffer_end, __middle, __last, + _Pointer __buffer_end = _GLIBCXX_MOVE3(__first, __middle, __buffer); + _GLIBCXX_STD_P::merge(_GLIBCXX_MAKE_MOVE_ITERATOR(__buffer), + _GLIBCXX_MAKE_MOVE_ITERATOR(__buffer_end), + _GLIBCXX_MAKE_MOVE_ITERATOR(__middle), + _GLIBCXX_MAKE_MOVE_ITERATOR(__last), __first); } else if (__len2 <= __buffer_size) { - _Pointer __buffer_end = std::copy(__middle, __last, __buffer); - std::__merge_backward(__first, __middle, __buffer, - __buffer_end, __last); + _Pointer __buffer_end = _GLIBCXX_MOVE3(__middle, __last, __buffer); + std::__merge_backward(_GLIBCXX_MAKE_MOVE_ITERATOR(__first), + _GLIBCXX_MAKE_MOVE_ITERATOR(__middle), + _GLIBCXX_MAKE_MOVE_ITERATOR(__buffer), + _GLIBCXX_MAKE_MOVE_ITERATOR(__buffer_end), + __last); } else { @@ -3013,15 +3019,21 @@ _GLIBCXX_BEGIN_NAMESPACE(std) { if (__len1 <= __len2 && __len1 <= __buffer_size) { - _Pointer __buffer_end = std::copy(__first, __middle, __buffer); - _GLIBCXX_STD_P::merge(__buffer, __buffer_end, __middle, __last, + _Pointer __buffer_end = _GLIBCXX_MOVE3(__first, __middle, __buffer); + _GLIBCXX_STD_P::merge(_GLIBCXX_MAKE_MOVE_ITERATOR(__buffer), + _GLIBCXX_MAKE_MOVE_ITERATOR(__buffer_end), + _GLIBCXX_MAKE_MOVE_ITERATOR(__middle), + _GLIBCXX_MAKE_MOVE_ITERATOR(__last), __first, __comp); } else if (__len2 <= __buffer_size) { - _Pointer __buffer_end = std::copy(__middle, __last, __buffer); - std::__merge_backward(__first, __middle, __buffer, __buffer_end, - __last, __comp); + _Pointer __buffer_end = _GLIBCXX_MOVE3(__middle, __last, __buffer); + std::__merge_backward(_GLIBCXX_MAKE_MOVE_ITERATOR(__first), + _GLIBCXX_MAKE_MOVE_ITERATOR(__middle), + _GLIBCXX_MAKE_MOVE_ITERATOR(__buffer), + _GLIBCXX_MAKE_MOVE_ITERATOR(__buffer_end), + __last,__comp); } else { @@ -3270,16 +3282,22 @@ _GLIBCXX_BEGIN_NAMESPACE(std) while (__last - __first >= __two_step) { - __result = _GLIBCXX_STD_P::merge(__first, __first + __step_size, - __first + __step_size, - __first + __two_step, - __result); + __result = _GLIBCXX_STD_P::merge( + _GLIBCXX_MAKE_MOVE_ITERATOR(__first), + _GLIBCXX_MAKE_MOVE_ITERATOR(__first + __step_size), + _GLIBCXX_MAKE_MOVE_ITERATOR(__first + __step_size), + _GLIBCXX_MAKE_MOVE_ITERATOR(__first + __two_step), + __result); __first += __two_step; } __step_size = std::min(_Distance(__last - __first), __step_size); - _GLIBCXX_STD_P::merge(__first, __first + __step_size, - __first + __step_size, __last, + _GLIBCXX_STD_P::merge(_GLIBCXX_MAKE_MOVE_ITERATOR(__first), + _GLIBCXX_MAKE_MOVE_ITERATOR(__first + + __step_size), + _GLIBCXX_MAKE_MOVE_ITERATOR(__first + + __step_size), + _GLIBCXX_MAKE_MOVE_ITERATOR(__last), __result); } @@ -3295,16 +3313,23 @@ _GLIBCXX_BEGIN_NAMESPACE(std) while (__last - __first >= __two_step) { - __result = _GLIBCXX_STD_P::merge(__first, __first + __step_size, - __first + __step_size, __first + __two_step, - __result, - __comp); + __result = _GLIBCXX_STD_P::merge( + _GLIBCXX_MAKE_MOVE_ITERATOR(__first), + _GLIBCXX_MAKE_MOVE_ITERATOR(__first + __step_size), + _GLIBCXX_MAKE_MOVE_ITERATOR(__first + __step_size), + _GLIBCXX_MAKE_MOVE_ITERATOR(__first + __two_step), + __result, __comp); __first += __two_step; } __step_size = std::min(_Distance(__last - __first), __step_size); - _GLIBCXX_STD_P::merge(__first, __first + __step_size, - __first + __step_size, __last, __result, __comp); + _GLIBCXX_STD_P::merge(_GLIBCXX_MAKE_MOVE_ITERATOR(__first), + _GLIBCXX_MAKE_MOVE_ITERATOR(__first + + __step_size), + _GLIBCXX_MAKE_MOVE_ITERATOR(__first + + __step_size), + _GLIBCXX_MAKE_MOVE_ITERATOR(__last), + __result, __comp); } template diff --git a/libstdc++-v3/testsuite/25_algorithms/inplace_merge/moveable.cc b/libstdc++-v3/testsuite/25_algorithms/inplace_merge/moveable.cc new file mode 100644 index 000000000000..4b07a63edee3 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/inplace_merge/moveable.cc @@ -0,0 +1,52 @@ +// { 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 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 COPYING3. If not see +// . + +// 25.3.4 [lib.alg.merge] + +#include +#include +#include +#include + +using __gnu_test::test_container; +using __gnu_test::bidirectional_iterator_wrapper; +using __gnu_test::rvalstruct; + +typedef test_container container; + +void +test01() +{ + bool test __attribute__((unused)) = true; + + int array[]={0,2,4,1,3,5}; + rvalstruct rv_array[6]; + std::copy(array, array + 6, rv_array); + container con(rv_array, rv_array + 6); + std::inplace_merge(con.begin(), con.it(3), con.end()); + VERIFY( rv_array[0] == 0 && rv_array[1] == 1 && rv_array[2] == 2 + && rv_array[3] == 3 && rv_array[4] == 4 && rv_array[5] == 5 ); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/inplace_merge/moveable2.cc b/libstdc++-v3/testsuite/25_algorithms/inplace_merge/moveable2.cc new file mode 100644 index 000000000000..32ab3c70c6b5 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/inplace_merge/moveable2.cc @@ -0,0 +1,56 @@ +// { 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 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 COPYING3. If not see +// . + +// 25.3.4 [lib.alg.merge] + +#include +#include +#include +#include + +using __gnu_test::test_container; +using __gnu_test::bidirectional_iterator_wrapper; +using __gnu_test::rvalstruct; + +typedef test_container container; + +bool +are_ordered(const rvalstruct& lhs, const rvalstruct& rhs) +{ return lhs < rhs; } + +void +test01() +{ + bool test __attribute__((unused)) = true; + + int array[]={0,2,4,1,3,5}; + rvalstruct rv_array[6]; + std::copy(array, array + 6, rv_array); + container con(rv_array, rv_array + 6); + std::inplace_merge(con.begin(), con.it(3), con.end(), are_ordered); + VERIFY( rv_array[0] == 0 && rv_array[1] == 1 && rv_array[2] == 2 + && rv_array[3] == 3 && rv_array[4] == 4 && rv_array[5] == 5 ); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/stable_partition/moveable.cc b/libstdc++-v3/testsuite/25_algorithms/stable_partition/moveable.cc new file mode 100644 index 000000000000..193f1312849b --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/stable_partition/moveable.cc @@ -0,0 +1,64 @@ +// { 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 +// . + +// 25.2.12 [lib.alg.partitions] Partitions. + +#include +#include +#include +#include +#include + +using __gnu_test::test_container; +using __gnu_test::random_access_iterator_wrapper; +using __gnu_test::rvalstruct; + +typedef test_container Container; + +const int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17}; +const int B[] = {2, 4, 6, 8, 10, 12, 14, 16, 1, 3, 5, 7, 9, 11, 13, 15, 17}; +const int N = sizeof(A) / sizeof(int); + +struct Pred +{ + bool + operator()(const rvalstruct& x) const + { return (x.val % 2) == 0; } +}; + +// 25.2.12 stable_partition() +void +test01() +{ + bool test __attribute__((unused)) = true; + + rvalstruct s1[N]; + std::copy(A, A + N, s1); + Container con(s1, s1 + N); + + std::stable_partition(con.begin(), con.end(), Pred()); + VERIFY( std::equal(s1, s1 + N, B) ); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/stable_sort/moveable.cc b/libstdc++-v3/testsuite/25_algorithms/stable_sort/moveable.cc new file mode 100644 index 000000000000..09d6129c06c7 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/stable_sort/moveable.cc @@ -0,0 +1,59 @@ +// { 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 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 COPYING3. If not see +// . + +// 25.3.1.2 [lib.stable.sort] + +#undef _GLIBCXX_CONCEPT_CHECKS + +#include +#include +#include +#include + +using __gnu_test::test_container; +using __gnu_test::random_access_iterator_wrapper; +using __gnu_test::rvalstruct; + +typedef test_container Container; + +const int A[] = { 10, 20, 1, 11, 2, 12, 3, 13, 4, 14, 5, 15, 6, 16, 7, + 17, 8, 18, 9, 19 }; +const int N = sizeof(A) / sizeof(int); + +// 25.3.1.2 stable_sort() +void +test01() +{ + bool test __attribute__((unused)) = true; + + rvalstruct s1[N]; + std::copy(A, A + N, s1); + Container con(s1, s1 + N); + std::stable_sort(con.begin(), con.end()); + VERIFY( s1[0].valid ); + for(int i = 1; i < N; ++i) + VERIFY( s1[i].val>s1[i-1].val && s1[i].valid ); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/stable_sort/moveable2.cc b/libstdc++-v3/testsuite/25_algorithms/stable_sort/moveable2.cc new file mode 100644 index 000000000000..86ff353967d7 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/stable_sort/moveable2.cc @@ -0,0 +1,62 @@ +// { 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 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 COPYING3. If not see +// . + +// 25.3.1.2 [lib.stable.sort] + +#undef _GLIBCXX_CONCEPT_CHECKS + +#include +#include +#include +#include + +using __gnu_test::test_container; +using __gnu_test::random_access_iterator_wrapper; +using __gnu_test::rvalstruct; + +typedef test_container Container; + +const int A[] = { 10, 20, 1, 11, 2, 12, 3, 13, 4, 14, 5, 15, 6, 16, 7, + 17, 8, 18, 9, 19 }; +const int N = sizeof(A) / sizeof(int); + +bool order(const rvalstruct& lhs, const rvalstruct& rhs) +{ return lhs < rhs; } + +// 25.3.1.2 stable_sort() +void +test01() +{ + bool test __attribute__((unused)) = true; + + rvalstruct s1[N]; + std::copy(A, A + N, s1); + Container con(s1, s1 + N); + std::stable_sort(con.begin(), con.end(), order); + VERIFY( s1[0].valid ); + for(int i = 1; i < N; ++i) + VERIFY( s1[i].val>s1[i-1].val && s1[i].valid ); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/lib/dg-options.exp b/libstdc++-v3/testsuite/lib/dg-options.exp index 1d9af09a3a60..60e9b78fdbad 100644 --- a/libstdc++-v3/testsuite/lib/dg-options.exp +++ b/libstdc++-v3/testsuite/lib/dg-options.exp @@ -80,15 +80,6 @@ proc dg-require-time { args } { return } -proc dg-require-rvalref { args } { - if { ![ check_v3_target_rvalref ] } { - upvar dg-do-what dg-do-what - set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"] - return - } - return -} - proc dg-require-cstdint { args } { if { ![ check_v3_target_cstdint ] } { upvar dg-do-what dg-do-what diff --git a/libstdc++-v3/testsuite/lib/libstdc++.exp b/libstdc++-v3/testsuite/lib/libstdc++.exp index 05a9b5db860e..c71991afc90d 100644 --- a/libstdc++-v3/testsuite/lib/libstdc++.exp +++ b/libstdc++-v3/testsuite/lib/libstdc++.exp @@ -805,61 +805,6 @@ proc check_v3_target_time { } { return $et_time_saved } -proc check_v3_target_rvalref { } { - global et_rvalref_saved - global et_rvalref_target_name - global tool - - if { ![info exists et_rvalref_target_name] } { - set et_rvalref_target_name "" - } - - # If the target has changed since we set the cached value, clear it. - set current_target [current_target_name] - if { $current_target != $et_rvalref_target_name } { - verbose "check_v3_target_rvalref: `$et_rvalref_target_name'" 2 - set et_rvalref_target_name $current_target - if [info exists et_rvalref_saved] { - verbose "check_v3_target_rvalref: removing cached result" 2 - unset et_rvalref_saved - } - } - - if [info exists et_rvalref_saved] { - verbose "check_v3_target_rvalref: using cached result" 2 - } else { - set et_rvalref_saved 0 - - # Set up and compile a C++ test program that tries to use - # the library components of rval references - set src rvalref[pid].cc - set exe rvalref[pid].x - - set f [open $src "w"] - puts $f "#include " - puts $f "#include " - puts $f "using std::move;" - puts $f "using std::identity;" - puts $f "using std::forward;" - puts $f "using std::move_iterator;" - puts $f "using std::make_move_iterator;" - close $f - - set lines [v3_target_compile $src $exe executable ""] - file delete $src - - if [string match "" $lines] { - # No error message, compilation succeeded. - verbose "check_v3_target_rvalref: compilation succeeded" 2 - remote_file build delete $exe - set et_rvalref_saved 1 - } else { - verbose "check_v3_target_rvalref: compilation failed" 2 - } - } - return $et_rvalref_saved -} - proc check_v3_target_namedlocale { } { global et_namedlocale_saved global et_namedlocale_target_name