1 // Copyright (C) 2020-2021 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 // { dg-options "-std=gnu++2a" }
19 // { dg-do run { target c++2a } }
20 // { dg-require-cstdint "" }
25 #include <testsuite_hooks.h>
26 #include <testsuite_iterators.h>
28 using __gnu_test::test_container
;
29 using __gnu_test::test_range
;
30 using __gnu_test::input_iterator_wrapper
;
31 using __gnu_test::forward_iterator_wrapper
;
32 using __gnu_test::random_access_iterator_wrapper
;
34 namespace ranges
= std::ranges
;
39 for (unsigned size
= 0; size
< 50; ++size
)
41 std::vector
<int> vref(size
);
42 std::iota(vref
.begin(), vref
.end(), 0);
43 std::vector
<int> v1(vref
), v2(vref
);
45 std::ranlux48_base
g1(size
), g2(size
+ 1);
46 ranges::shuffle(v1
, g1
);
47 ranges::shuffle(v2
, g2
);
49 for (unsigned middle
= 0; middle
< 10; ++middle
)
51 test_container
<int, forward_iterator_wrapper
> c
52 = {v1
.data(), v1
.data() + size
};
53 test_range
<int, input_iterator_wrapper
> r
54 = {v2
.data(), v2
.data() + size
};
56 std::vector
<int> o1(middle
), o2(middle
);
57 test_range
<int, random_access_iterator_wrapper
> w1
58 = {o1
.data(), o1
.data()+middle
};
59 test_range
<int, random_access_iterator_wrapper
> w2
60 = {o2
.data(), o2
.data()+middle
};
62 auto [in1
, out1
] = ranges::partial_sort_copy(c
.begin(), c
.end(),
67 VERIFY( in1
== c
.end() );
68 VERIFY( out1
== w1
.begin() + std::min(size
, middle
) );
70 auto [in2
,out2
] = ranges::partial_sort_copy(r
, w2
, ranges::greater
{});
71 VERIFY( in2
== ranges::end(r
) );
72 VERIFY( out2
== w2
.begin() + std::min(size
, middle
) );
74 VERIFY( ranges::equal(w1
.begin(), out1
, w2
.begin(), out2
) );
75 VERIFY( ranges::equal(w1
.begin(), out1
,
77 vref
.rbegin()+(out1
-w1
.begin())) );
85 int x
[] = { 5,4,1,3,2 };
87 const int y
[] = { 1,2,3 };
88 ranges::partial_sort_copy(x
, x
+5, w
, w
+3);
89 return ranges::equal(w
, y
);
96 static_assert(test02());