Debian Codegraph @

libstdc++-v3/testsuite/25_algorithms/inplace_merge/constexpr.cc

raw
1 // { dg-do compile { target c++26 } }
2
3 #include <algorithm>
4 #include <array>
5 #include <functional>
6 #include <utility>
7
8 // returns a pair [array, index of partitioning point]
9 constexpr auto
10 create_array()
11 {
12 return std::make_pair(
13 std::to_array({0, 2, 2, 2, 4, 6, 1, 2, 3, 3, 4, 4, 5}),
14 6);
15 }
16
17 constexpr bool
18 test01()
19 {
20 auto [ar, index] = create_array();
21 std::inplace_merge(ar.begin(), ar.begin() + index, ar.end());
22 return std::is_sorted(ar.begin(), ar.end());
23 }
24
25 static_assert(test01());
26
27 constexpr bool
28 test02()
29 {
30 auto [ar, index] = create_array();
31 auto index_it = ar.begin() + index;
32 std::reverse(ar.begin(), index_it);
33 std::reverse(index_it, ar.end());
34 std::inplace_merge(ar.begin(), index_it, ar.end(), std::greater<>());
35 return std::is_sorted(ar.begin(), ar.end(), std::greater<>());
36 }
37
38 static_assert(test02());
39
40 constexpr bool
41 test03()
42 {
43 auto [ar, index] = create_array();
44 std::ranges::inplace_merge(ar, ar.begin() + index);
45 return std::ranges::is_sorted(ar);
46 }
47
48 static_assert(test03());
49
50 constexpr bool
51 test04()
52 {
53 auto [ar, index] = create_array();
54 auto index_it = ar.begin() + index;
55 std::ranges::reverse(ar.begin(), index_it);
56 std::ranges::reverse(index_it, ar.end());
57 std::ranges::inplace_merge(ar, index_it, std::ranges::greater());
58 return std::ranges::is_sorted(ar, std::ranges::greater());
59 }
60
61 static_assert(test04());
62
63 constexpr bool
64 test05()
65 {
66 auto [ar, index] = create_array();
67 auto proj = [](int i) { return -i; };
68 std::ranges::inplace_merge(ar, ar.begin() + index, std::ranges::greater(), proj);
69 return std::ranges::is_sorted(ar, std::ranges::greater(), proj);
70 }
71
72 static_assert(test05());