1 // Copyright (C) 2005-2013 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 3, 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 COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
18 // 25.3.1.4 [lib.partial.sort.copy]
21 #include <testsuite_hooks.h>
22 #include <testsuite_iterators.h>
24 using __gnu_test::test_container
;
25 using __gnu_test::random_access_iterator_wrapper
;
26 using __gnu_test::input_iterator_wrapper
;
27 using std::partial_sort_copy
;
29 typedef test_container
<int, random_access_iterator_wrapper
> Rcontainer
;
30 typedef test_container
<int, input_iterator_wrapper
> Icontainer
;
36 Rcontainer
rcon1(array
, array
);
37 Rcontainer
rcon2(array
, array
+ 2);
38 Icontainer
icon1(array
, array
);
39 Icontainer
icon2(array
, array
+ 2);
40 partial_sort_copy(icon1
.begin(), icon1
.end(), rcon1
.begin(), rcon1
.end());
41 partial_sort_copy(icon1
.begin(), icon1
.end(), rcon2
.begin(), rcon2
.end());
42 partial_sort_copy(icon2
.begin(), icon2
.end(), rcon1
.begin(), rcon1
.end());
43 partial_sort_copy(icon2
.begin(), icon2
.end(), rcon2
.begin(), rcon2
.end());
49 int array1
[] = {4, 3, 2, 1, 0};
51 Icontainer
icon(array1
, array1
+ 5);
52 Rcontainer
rcon(array2
, array2
+ 5);
53 partial_sort_copy(icon
.begin(), icon
.end(), rcon
.begin(), rcon
.end());
54 VERIFY(array2
[0] == 0 && array2
[1] == 1 && array2
[2] == 2 &&
55 array2
[3] == 3 && array2
[4] == 4);
61 int array1
[] = {4, 0, 1, 3, 2};
63 Icontainer
icon(array1
, array1
+ 5);
64 Rcontainer
rcon(array2
, array2
+ 2);
65 partial_sort_copy(icon
.begin(), icon
.end(), rcon
.begin(), rcon
.end());
66 VERIFY(array2
[0] == 0 && array2
[1] == 1);
72 int array1
[] = {4, 1, 3, 2, 0};
74 Icontainer
icon(array1
, array1
+ 5);
75 Rcontainer
rcon(array2
, array2
+ 20);
76 partial_sort_copy(icon
.begin(), icon
.end(), rcon
.begin(), rcon
.end());
77 VERIFY(array2
[0] == 0 && array2
[1] == 1 && array2
[2] == 2 &&
78 array2
[3] == 3 && array2
[4] == 4);