Debian Codegraph @

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

raw
1 // { dg-do compile { target c++26 } }
2
3 #include <algorithm>
4 #include <array>
5
6 constexpr auto
7 create_array()
8 {
9 return std::to_array({0, 10, 1, 2, 3, 3, 4, -1, -2, -4, 5, 6});
10 }
11
12 constexpr bool
13 test01()
14 {
15 auto ar = create_array();
16 auto pred = [](int i) { return i % 2 == 0; };
17 std::stable_partition(ar.begin(), ar.end(), pred);
18 return std::is_partitioned(ar.begin(), ar.end(), pred);
19 }
20
21 static_assert(test01());
22
23 constexpr bool
24 test02()
25 {
26 auto ar = create_array();
27 auto pred = [](int i) { return i % 2 == 0; };
28 std::ranges::stable_partition(ar, pred);
29 return std::ranges::is_partitioned(ar, pred);
30 }
31
32 static_assert(test02());
33
34 constexpr bool
35 test03()
36 {
37 auto ar = create_array();
38 auto pred = [](int i) { return i % 2 == 0; };
39 auto proj = [](int i) { return i + 1; };
40 std::ranges::stable_partition(ar, pred, proj);
41 return std::ranges::is_partitioned(ar, pred, proj);
42 }
43
44 static_assert(test03());