Debian Codegraph @

libstdc++-v3/testsuite/25_algorithms/default_template_value.cc

raw
1 // { dg-do compile { target c++26 } }
2
3 #include <algorithm>
4
5 #if !defined(__cpp_lib_algorithm_default_value_type)
6 #error "Feature test macro for default template type for algorithms' values is missing"
7 #elif __cpp_lib_algorithm_default_value_type < 202403L
8 #error "Feature test macro for default template type for algorithms' values is wrong"
9 #endif
10
11 #include <execution>
12 #include <ranges>
13 #include <iterator>
14 #include <vector>
15
16 // Conversions from Input to Output will be used in certain algorithms.
17 // Make Output have a different number of arguments to its constructor
18 // so we can check whether a braced-init-list is indeed matching Input
19 // or Output
20 struct Output
21 {
22 Output(char, float, long);
23 };
24
25 #define OUTPUT_VAL {'x', 1.171f, 10L}
26
27 struct Input
28 {
29 Input(int, double);
30 friend auto operator<=>(const Input &, const Input &) = default;
31 friend Input operator+(const Input &, const Input &);
32 operator Output() const;
33 };
34
35 #define INPUT_VAL {1, 3.14}
36
37 void
38 test()
39 {
40 extern std::vector<Input> in;
41 extern std::vector<Output> out;
42
43 const auto pred = [](auto &&) { return true; };
44
45 // [alg.find]
46 (void) std::find(in.begin(), in.end(), INPUT_VAL);
47 (void) std::find(std::execution::seq, in.begin(), in.end(), INPUT_VAL);
48 (void) std::ranges::find(in.begin(), in.end(), INPUT_VAL);
49 (void) std::ranges::find(in, INPUT_VAL);
50
51 // [alg.count]
52 (void) std::count(in.begin(), in.end(), INPUT_VAL);
53 (void) std::count(std::execution::seq, in.begin(), in.end(), INPUT_VAL);
54 (void) std::ranges::count(in.begin(), in.end(), INPUT_VAL);
55 (void) std::ranges::count(in, INPUT_VAL);
56
57 // [alg.search]
58 (void) std::search_n(in.begin(), in.end(), 10, INPUT_VAL);
59 (void) std::search_n(in.begin(), in.end(), 10, INPUT_VAL, std::equal_to{});
60 (void) std::search_n(std::execution::seq, in.begin(), in.end(), 10, INPUT_VAL);
61 (void) std::search_n(std::execution::seq, in.begin(), in.end(), 10, INPUT_VAL, std::equal_to{});
62 (void) std::ranges::search_n(in.begin(), in.end(), 10, INPUT_VAL);
63 (void) std::ranges::search_n(in, 10, INPUT_VAL);
64
65 // [alg.replace]
66 (void) std::replace(in.begin(), in.end(), INPUT_VAL, INPUT_VAL);
67 (void) std::replace(std::execution::seq, in.begin(), in.end(), INPUT_VAL, INPUT_VAL);
68 (void) std::replace_if(in.begin(), in.end(), pred, INPUT_VAL);
69 (void) std::replace_if(std::execution::seq, in.begin(), in.end(), pred, INPUT_VAL);
70
71 (void) std::ranges::replace(in.begin(), in.end(), INPUT_VAL, INPUT_VAL);
72 (void) std::ranges::replace(in, INPUT_VAL, INPUT_VAL);
73 (void) std::ranges::replace_if(in.begin(), in.end(), pred, INPUT_VAL);
74 (void) std::ranges::replace_if(in, pred, INPUT_VAL);
75
76 (void) std::replace_copy_if(in.begin(), in.end(), out.begin(), pred, OUTPUT_VAL);
77 (void) std::replace_copy_if(std::execution::seq, in.begin(), in.end(), out.begin(), pred, OUTPUT_VAL);
78 (void) std::ranges::replace_copy_if(in.begin(), in.end(), out.begin(), pred, OUTPUT_VAL);
79 (void) std::ranges::replace_copy_if(in, out.begin(), pred, OUTPUT_VAL);
80
81 // Non-range replace_copy is deliberately skipped by P2248
82 (void) std::ranges::replace_copy(in.begin(), in.end(), out.begin(), INPUT_VAL, OUTPUT_VAL);
83 (void) std::ranges::replace_copy(in, out.begin(), INPUT_VAL, OUTPUT_VAL);
84
85 // [alg.fill]
86 (void) std::fill(in.begin(), in.end(), INPUT_VAL);
87 (void) std::fill(std::execution::seq, in.begin(), in.end(), INPUT_VAL);
88 (void) std::ranges::fill(in.begin(), in.end(), INPUT_VAL);
89 (void) std::ranges::fill(in, INPUT_VAL);
90
91 (void) std::fill_n(in.begin(), 10, INPUT_VAL);
92 (void) std::fill_n(std::execution::seq, in.begin(), 10, INPUT_VAL);
93 (void) std::ranges::fill_n(in.begin(), 10, INPUT_VAL);
94
95 // [alg.remove]
96 (void) std::remove(in.begin(), in.end(), INPUT_VAL);
97 (void) std::remove(std::execution::seq, in.begin(), in.end(), INPUT_VAL);
98 (void) std::ranges::remove(in.begin(), in.end(), INPUT_VAL);
99 (void) std::ranges::remove(in, INPUT_VAL);
100
101 (void) std::remove_copy(in.begin(), in.end(), out.begin(), INPUT_VAL);
102 (void) std::remove_copy(std::execution::seq, in.begin(), in.end(), out.begin(), INPUT_VAL);
103 (void) std::ranges::remove_copy(in.begin(), in.end(), out.begin(), INPUT_VAL);
104 (void) std::ranges::remove_copy(in, out.begin(), INPUT_VAL);
105
106 // [alg.binary.search]
107 (void) std::lower_bound(in.begin(), in.end(), INPUT_VAL);
108 (void) std::lower_bound(in.begin(), in.end(), INPUT_VAL, std::less{});
109 (void) std::ranges::lower_bound(in.begin(), in.end(), INPUT_VAL);
110 (void) std::ranges::lower_bound(in, INPUT_VAL);
111
112 (void) std::upper_bound(in.begin(), in.end(), INPUT_VAL);
113 (void) std::upper_bound(in.begin(), in.end(), INPUT_VAL, std::less{});
114 (void) std::ranges::upper_bound(in.begin(), in.end(), INPUT_VAL);
115 (void) std::ranges::upper_bound(in, INPUT_VAL);
116
117 (void) std::equal_range(in.begin(), in.end(), INPUT_VAL);
118 (void) std::equal_range(in.begin(), in.end(), INPUT_VAL, std::less{});
119 (void) std::ranges::equal_range(in.begin(), in.end(), INPUT_VAL);
120 (void) std::ranges::equal_range(in, INPUT_VAL);
121
122 (void) std::binary_search(in.begin(), in.end(), INPUT_VAL);
123 (void) std::binary_search(in.begin(), in.end(), INPUT_VAL, std::less{});
124 (void) std::ranges::binary_search(in.begin(), in.end(), INPUT_VAL);
125 (void) std::ranges::binary_search(in, INPUT_VAL);
126
127 // [alg.fold]
128 (void) std::ranges::fold_left(in.begin(), in.end(), INPUT_VAL, std::plus<>{});
129 (void) std::ranges::fold_left(in, INPUT_VAL, std::plus<>{});
130 (void) std::ranges::fold_right(in.begin(), in.end(), INPUT_VAL, std::plus<>{});
131 (void) std::ranges::fold_right(in, INPUT_VAL, std::plus<>{});
132 (void) std::ranges::fold_left_with_iter(in.begin(), in.end(), INPUT_VAL, std::plus<>{});
133 (void) std::ranges::fold_left_with_iter(in, INPUT_VAL, std::plus<>{});
134
135 // [alg.contains]
136 (void) std::ranges::contains(in.begin(), in.end(), INPUT_VAL);
137 (void) std::ranges::contains(in, INPUT_VAL);
138
139 // [alg.find.last]
140 (void) std::ranges::find_last(in.begin(), in.end(), INPUT_VAL);
141 (void) std::ranges::find_last(in, INPUT_VAL);
142 }