1 // Copyright (C) 2005 Free Software Foundation, Inc.
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 2, or (at your option)
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING. If not, write to the Free
16 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 // 25.3.1.4 [lib.partial.sort.copy]
22 #include <testsuite_hooks.h>
23 #include <testsuite_iterators.h>
25 using __gnu_test::test_container
;
26 using __gnu_test::random_access_iterator_wrapper
;
27 using __gnu_test::input_iterator_wrapper
;
28 using std::partial_sort_copy
;
30 typedef test_container
<int, random_access_iterator_wrapper
> Rcontainer
;
31 typedef test_container
<int, input_iterator_wrapper
> Icontainer
;
37 Rcontainer
rcon1(array
, array
);
38 Rcontainer
rcon2(array
, array
+ 2);
39 Icontainer
icon1(array
, array
);
40 Icontainer
icon2(array
, array
+ 2);
41 partial_sort_copy(icon1
.begin(), icon1
.end(), rcon1
.begin(), rcon1
.end());
42 partial_sort_copy(icon1
.begin(), icon1
.end(), rcon2
.begin(), rcon2
.end());
43 partial_sort_copy(icon2
.begin(), icon2
.end(), rcon1
.begin(), rcon1
.end());
44 partial_sort_copy(icon2
.begin(), icon2
.end(), rcon2
.begin(), rcon2
.end());
50 int array1
[] = {4, 3, 2, 1, 0};
52 Icontainer
icon(array1
, array1
+ 5);
53 Rcontainer
rcon(array2
, array2
+ 5);
54 partial_sort_copy(icon
.begin(), icon
.end(), rcon
.begin(), rcon
.end());
55 VERIFY(array2
[0] == 0 && array2
[1] == 1 && array2
[2] == 2 &&
56 array2
[3] == 3 && array2
[4] == 4);
62 int array1
[] = {4, 0, 1, 3, 2};
64 Icontainer
icon(array1
, array1
+ 5);
65 Rcontainer
rcon(array2
, array2
+ 2);
66 partial_sort_copy(icon
.begin(), icon
.end(), rcon
.begin(), rcon
.end());
67 VERIFY(array2
[0] == 0 && array2
[1] == 1);
73 int array1
[] = {4, 1, 3, 2, 0};
75 Icontainer
icon(array1
, array1
+ 5);
76 Rcontainer
rcon(array2
, array2
+ 20);
77 partial_sort_copy(icon
.begin(), icon
.end(), rcon
.begin(), rcon
.end());
78 VERIFY(array2
[0] == 0 && array2
[1] == 1 && array2
[2] == 2 &&
79 array2
[3] == 3 && array2
[4] == 4);