blob: d5ec99388f549c7eeb81ad25eeffd3cbbbf430d5 [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
Louis Dionne9bd93882021-11-17 16:25:01 -05002//===----------------------------------------------------------------------===//
Howard Hinnantc51e1022010-05-11 19:42:16 +00003//
Chandler Carruthd2012102019-01-19 10:56:40 +00004// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Howard Hinnantc51e1022010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_ALGORITHM
11#define _LIBCPP_ALGORITHM
12
13/*
14 algorithm synopsis
15
16#include <initializer_list>
17
18namespace std
19{
20
Nikolas Klauserf74be4e2022-01-14 02:55:51 +010021namespace ranges {
Nikolas Klauser671b4752022-02-11 17:01:58 +010022 template <class I, class F>
Nikolas Klauser2e263162022-02-21 22:48:36 +010023 struct in_fun_result; // since C++20
Nikolas Klauser671b4752022-02-11 17:01:58 +010024
Nikolas Klauserf74be4e2022-01-14 02:55:51 +010025 template <class I1, class I2>
Nikolas Klauser2e263162022-02-21 22:48:36 +010026 struct in_in_result; // since C++20
Nikolas Klauser05e2cd82022-01-25 11:21:47 +010027
28 template <class I1, class I2, class O>
Nikolas Klauser2e263162022-02-21 22:48:36 +010029 struct in_in_out_result; // since C++20
Nikolas Klauser61ce8162022-02-03 02:17:03 +010030
31 template <class I, class O1, class O2>
32 struct in_out_out_result; // since C++20
Nikolas Klauser671b4752022-02-11 17:01:58 +010033
Nikolas Klauser2e263162022-02-21 22:48:36 +010034 template <class I1, class I2>
35 struct min_max_result; // since C++20
36
Nikolas Klauserdd5ad212022-02-21 23:07:02 +010037 template <class I>
38 struct in_found_result; // since C++20
39
Nikolas Klauser0a62a172022-02-11 13:11:57 +010040 template<forward_iterator I, sentinel_for<I> S, class Proj = identity,
41 indirect_strict_weak_order<projected<I, Proj>> Comp = ranges::less> // since C++20
42 constexpr I min_element(I first, S last, Comp comp = {}, Proj proj = {});
43
44 template<forward_range R, class Proj = identity,
45 indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less> // since C++20
46 constexpr borrowed_iterator_t<R> min_element(R&& r, Comp comp = {}, Proj proj = {});
Nikolas Klauser12fc9bf2022-03-08 23:12:35 +010047
Nikolas Klauser10c612d2022-05-22 13:43:37 +020048 template<forward_iterator I, sentinel_for<I> S, class Proj = identity,
49 indirect_strict_weak_order<projected<I, Proj>> Comp = ranges::less>
50 constexpr I ranges::max_element(I first, S last, Comp comp = {}, Proj proj = {}); // since C++20
51
52 template<forward_range R, class Proj = identity,
53 indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less>
54 constexpr borrowed_iterator_t<R> ranges::max_element(R&& r, Comp comp = {}, Proj proj = {}); // since C++20
55
Nikolas Klauser12fc9bf2022-03-08 23:12:35 +010056 template <input_iterator I1, sentinel_for<_I1> S1, input_iterator I2, sentinel_for<_I2> S2,
57 class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
58 requires indirectly_comparable<I1, I2, Pred, Proj1, Proj2>
59 constexpr mismatch_result<_I1, _I2>
60 mismatch()(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}) // since C++20
61
62 template <input_range R1, input_range R2,
63 class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
64 requires indirectly_comparable<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
65 constexpr mismatch_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>>
66 mismatch(R1&& r1, R2&& r2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}) // since C++20
Nikolas Klauser37d076e2022-03-12 01:45:35 +010067
Nikolas Klauser37d076e2022-03-12 01:45:35 +010068 requires indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T*>
69 constexpr I find(I first, S last, const T& value, Proj proj = {}); // since C++20
70
71 template<input_range R, class T, class Proj = identity>
72 requires indirect_binary_predicate<ranges::equal_to, projected<iterator_t<R>, Proj>, const T*>
73 constexpr borrowed_iterator_t<R>
74 find(R&& r, const T& value, Proj proj = {}); // since C++20
75
76 template<input_iterator I, sentinel_for<I> S, class Proj = identity,
77 indirect_unary_predicate<projected<I, Proj>> Pred>
78 constexpr I find_if(I first, S last, Pred pred, Proj proj = {}); // since C++20
79
80 template<input_range R, class Proj = identity,
81 indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
82 constexpr borrowed_iterator_t<R>
83 find_if(R&& r, Pred pred, Proj proj = {}); // since C++20
84
85 template<input_iterator I, sentinel_for<I> S, class Proj = identity,
86 indirect_unary_predicate<projected<I, Proj>> Pred>
87 constexpr I find_if_not(I first, S last, Pred pred, Proj proj = {}); // since C++20
88
89 template<input_range R, class Proj = identity,
90 indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
91 constexpr borrowed_iterator_t<R>
92 find_if_not(R&& r, Pred pred, Proj proj = {}); // since C++20
Nikolas Klauser3559e452022-03-18 02:57:08 +010093
Nikolas Klauser573cd6f2022-04-03 09:17:01 +020094 template<class T, class Proj = identity,
95 indirect_strict_weak_order<projected<const T*, Proj>> Comp = ranges::less>
96 constexpr const T& min(const T& a, const T& b, Comp comp = {}, Proj proj = {}); // since C++20
Nikolas Klauser3559e452022-03-18 02:57:08 +010097
Nikolas Klauser573cd6f2022-04-03 09:17:01 +020098 template<copyable T, class Proj = identity,
99 indirect_strict_weak_order<projected<const T*, Proj>> Comp = ranges::less>
100 constexpr T min(initializer_list<T> r, Comp comp = {}, Proj proj = {}); // since C++20
Nikolas Klauser3559e452022-03-18 02:57:08 +0100101
102 template<input_range R, class Proj = identity,
103 indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less>
104 requires indirectly_copyable_storable<iterator_t<R>, range_value_t<R>*>
105 constexpr range_value_t<R>
106 min(R&& r, Comp comp = {}, Proj proj = {}); // since C++20
Nikolas Klauser573cd6f2022-04-03 09:17:01 +0200107
108 template<class T, class Proj = identity,
109 indirect_strict_weak_order<projected<const T*, Proj>> Comp = ranges::less>
110 constexpr const T& max(const T& a, const T& b, Comp comp = {}, Proj proj = {}); // since C++20
111
112 template<copyable T, class Proj = identity,
113 indirect_strict_weak_order<projected<const T*, Proj>> Comp = ranges::less>
114 constexpr T max(initializer_list<T> r, Comp comp = {}, Proj proj = {}); // since C++20
115
116 template<input_range R, class Proj = identity,
117 indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less>
118 requires indirectly_copyable_storable<iterator_t<R>, range_value_t<R>*>
119 constexpr range_value_t<R>
120 max(R&& r, Comp comp = {}, Proj proj = {}); // since C++20
Nikolas Klauser559a1772022-04-05 11:05:36 +0200121
122 template<class I, class O>
123 using unary_transform_result = in_out_result<I, O>; // since C++20
124
125 template<class I1, class I2, class O>
126 using binary_transform_result = in_in_out_result<I1, I2, O>; // since C++20
127
128 template<input_iterator I, sentinel_for<I> S, weakly_incrementable O,
129 copy_constructible F, class Proj = identity>
130 requires indirectly_writable<O, indirect_result_t<F&, projected<I, Proj>>>
131 constexpr ranges::unary_transform_result<I, O>
132 transform(I first1, S last1, O result, F op, Proj proj = {}); // since C++20
133
134 template<input_range R, weakly_incrementable O, copy_constructible F,
135 class Proj = identity>
136 requires indirectly_writable<O, indirect_result_t<F&, projected<iterator_t<R>, Proj>>>
137 constexpr ranges::unary_transform_result<borrowed_iterator_t<R>, O>
138 transform(R&& r, O result, F op, Proj proj = {}); // since C++20
139
140 template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2,
141 weakly_incrementable O, copy_constructible F, class Proj1 = identity,
142 class Proj2 = identity>
143 requires indirectly_writable<O, indirect_result_t<F&, projected<I1, Proj1>,
144 projected<I2, Proj2>>>
145 constexpr ranges::binary_transform_result<I1, I2, O>
146 transform(I1 first1, S1 last1, I2 first2, S2 last2, O result,
147 F binary_op, Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
148
149 template<input_range R1, input_range R2, weakly_incrementable O,
150 copy_constructible F, class Proj1 = identity, class Proj2 = identity>
151 requires indirectly_writable<O, indirect_result_t<F&, projected<iterator_t<R1>, Proj1>,
152 projected<iterator_t<R2>, Proj2>>>
153 constexpr ranges::binary_transform_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>, O>
154 transform(R1&& r1, R2&& r2, O result,
155 F binary_op, Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
Nikolas Klauserf1373d02022-04-07 13:02:02 +0200156
157 template<input_iterator I, sentinel_for<I> S, class T, class Proj = identity>
158 requires indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T*>
159 constexpr iter_difference_t<I>
160 count(I first, S last, const T& value, Proj proj = {}); // since C++20
161
162 template<input_range R, class T, class Proj = identity>
163 requires indirect_binary_predicate<ranges::equal_to, projected<iterator_t<R>, Proj>, const T*>
164 constexpr range_difference_t<R>
165 count(R&& r, const T& value, Proj proj = {}); // since C++20
166
167 template<input_iterator I, sentinel_for<I> S, class Proj = identity,
168 indirect_unary_predicate<projected<I, Proj>> Pred>
169 constexpr iter_difference_t<I>
170 count_if(I first, S last, Pred pred, Proj proj = {}); // since C++20
171
172 template<input_range R, class Proj = identity,
173 indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
174 constexpr range_difference_t<R>
175 count_if(R&& r, Pred pred, Proj proj = {}); // since C++20
Nikolas Klauser0a2f44f2022-04-13 22:59:09 +0200176
177 template<class T, class Proj = identity,
178 indirect_strict_weak_order<projected<const T*, Proj>> Comp = ranges::less>
179 constexpr ranges::minmax_result<const T&>
180 minmax(const T& a, const T& b, Comp comp = {}, Proj proj = {}); // since C++20
181
182 template<copyable T, class Proj = identity,
183 indirect_strict_weak_order<projected<const T*, Proj>> Comp = ranges::less>
184 constexpr ranges::minmax_result<T>
185 minmax(initializer_list<T> r, Comp comp = {}, Proj proj = {}); // since C++20
186
187 template<input_range R, class Proj = identity,
188 indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less>
189 requires indirectly_copyable_storable<iterator_t<R>, range_value_t<R>*>
190 constexpr ranges::minmax_result<range_value_t<R>>
191 minmax(R&& r, Comp comp = {}, Proj proj = {}); // since C++20
192
193 template<forward_iterator I, sentinel_for<I> S, class Proj = identity,
194 indirect_strict_weak_order<projected<I, Proj>> Comp = ranges::less>
195 constexpr ranges::minmax_element_result<I>
196 minmax_element(I first, S last, Comp comp = {}, Proj proj = {}); // since C++20
197
198 template<forward_range R, class Proj = identity,
199 indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less>
200 constexpr ranges::minmax_element_result<borrowed_iterator_t<R>>
201 minmax_element(R&& r, Comp comp = {}, Proj proj = {}); // since C++20
Nikolas Klauserd959d842022-04-15 13:43:40 +0200202
203 template<class I, class O>
204 using copy_result = in_out_result<I, O>; // since C++20
205
206 template<class I, class O>
207 using copy_n_result = in_out_result<I, O>; // since C++20
208
209 template<class I, class O>
210 using copy_if_result = in_out_result<I, O>; // since C++20
211
212 template<class I1, class I2>
213 using copy_backward_result = in_out_result<I1, I2>; // since C++20
214
215 template<input_iterator I, sentinel_for<I> S, weakly_incrementable O>
216 requires indirectly_copyable<I, O>
217 constexpr ranges::copy_result<I, O> ranges::copy(I first, S last, O result); // since C++20
218
219 template<input_range R, weakly_incrementable O>
220 requires indirectly_copyable<iterator_t<R>, O>
221 constexpr ranges::copy_result<borrowed_iterator_t<R>, O> ranges::copy(R&& r, O result); // since C++20
222
223 template<input_iterator I, weakly_incrementable O>
224 requires indirectly_copyable<I, O>
225 constexpr ranges::copy_n_result<I, O>
226 ranges::copy_n(I first, iter_difference_t<I> n, O result); // since C++20
227
228 template<input_iterator I, sentinel_for<I> S, weakly_incrementable O, class Proj = identity,
229 indirect_unary_predicate<projected<I, Proj>> Pred>
230 requires indirectly_copyable<I, O>
231 constexpr ranges::copy_if_result<I, O>
232 ranges::copy_if(I first, S last, O result, Pred pred, Proj proj = {}); // since C++20
233
234 template<input_range R, weakly_incrementable O, class Proj = identity,
235 indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
236 requires indirectly_copyable<iterator_t<R>, O>
237 constexpr ranges::copy_if_result<borrowed_iterator_t<R>, O>
238 ranges::copy_if(R&& r, O result, Pred pred, Proj proj = {}); // since C++20
239
240 template<bidirectional_iterator I1, sentinel_for<I1> S1, bidirectional_iterator I2>
241 requires indirectly_copyable<I1, I2>
242 constexpr ranges::copy_backward_result<I1, I2>
243 ranges::copy_backward(I1 first, S1 last, I2 result); // since C++20
244
245 template<bidirectional_range R, bidirectional_iterator I>
246 requires indirectly_copyable<iterator_t<R>, I>
247 constexpr ranges::copy_backward_result<borrowed_iterator_t<R>, I>
248 ranges::copy_backward(R&& r, I result); // since C++20
Nikolas Klauser58de98c2022-05-04 20:27:07 +0200249
250 template<class I, class F>
251 using for_each_result = in_fun_result<I, F>; // since C++20
252
253 template<input_iterator I, sentinel_for<I> S, class Proj = identity,
254 indirectly_unary_invocable<projected<I, Proj>> Fun>
255 constexpr ranges::for_each_result<I, Fun>
256 ranges::for_each(I first, S last, Fun f, Proj proj = {}); // since C++20
257
258 template<input_range R, class Proj = identity,
259 indirectly_unary_invocable<projected<iterator_t<R>, Proj>> Fun>
260 constexpr ranges::for_each_result<borrowed_iterator_t<R>, Fun>
261 ranges::for_each(R&& r, Fun f, Proj proj = {}); // since C++20
262
263 template<input_iterator I, class Proj = identity,
264 indirectly_unary_invocable<projected<I, Proj>> Fun>
265 constexpr ranges::for_each_n_result<I, Fun>
266 ranges::for_each_n(I first, iter_difference_t<I> n, Fun f, Proj proj = {}); // since C++20
Nikolas Klauserbb9049d2022-05-04 14:19:09 +0200267
268 template<input_iterator I, sentinel_for<I> S, class Proj = identity,
269 indirect_unary_predicate<projected<I, Proj>> Pred>
270 constexpr bool ranges::is_partitioned(I first, S last, Pred pred, Proj proj = {}); // since C++20
271
272 template<input_range R, class Proj = identity,
273 indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
274 constexpr bool ranges::is_partitioned(R&& r, Pred pred, Proj proj = {}); // since C++20
275
Nikolas Klauser52f20072022-05-24 10:32:50 +0200276
277 template<bidirectional_iterator I, sentinel_for<I> S>
278 requires permutable<I>
279 constexpr I ranges::reverse(I first, S last); // since C++20
280
281 template<bidirectional_range R>
282 requires permutable<iterator_t<R>>
283 constexpr borrowed_iterator_t<R> ranges::reverse(R&& r); // since C++20
284
Konstantin Varlamov55e39a82022-06-16 15:20:53 -0700285 template<random_access_iterator I, sentinel_for<I> S, class Comp = ranges::less,
286 class Proj = identity>
287 requires sortable<I, Comp, Proj>
288 constexpr I
289 sort(I first, S last, Comp comp = {}, Proj proj = {}); // since C++20
290
291 template<random_access_range R, class Comp = ranges::less, class Proj = identity>
292 requires sortable<iterator_t<R>, Comp, Proj>
293 constexpr borrowed_iterator_t<R>
294 sort(R&& r, Comp comp = {}, Proj proj = {}); // since C++20
295
Nikolas Klausereb49c2a2022-05-21 18:26:29 +0200296 template<class T, output_iterator<const T&> O, sentinel_for<O> S>
297 constexpr O ranges::fill(O first, S last, const T& value); // since C++20
298
299 template<class T, output_range<const T&> R>
300 constexpr borrowed_iterator_t<R> ranges::fill(R&& r, const T& value); // since C++20
301
302 template<class T, output_iterator<const T&> O>
303 constexpr O ranges::fill_n(O first, iter_difference_t<O> n, const T& value); // since C++20
Nikolas Klauser353f1dd2022-05-25 11:09:43 +0200304
305 template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2,
306 class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
307 requires indirectly_comparable<I1, I2, Pred, Proj1, Proj2>
308 constexpr bool ranges::equal(I1 first1, S1 last1, I2 first2, S2 last2,
309 Pred pred = {},
310 Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
311
312 template<input_range R1, input_range R2, class Pred = ranges::equal_to,
313 class Proj1 = identity, class Proj2 = identity>
314 requires indirectly_comparable<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
315 constexpr bool ranges::equal(R1&& r1, R2&& r2, Pred pred = {},
316 Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
317
Nikolas Klausered3f0e82022-05-26 16:42:46 +0200318 template<input_iterator I, sentinel_for<I> S, class Proj = identity,
319 indirect_unary_predicate<projected<I, Proj>> Pred>
320 constexpr bool ranges::all_of(I first, S last, Pred pred, Proj proj = {}); // since C++20
321
322 template<input_range R, class Proj = identity,
323 indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
324 constexpr bool ranges::all_of(R&& r, Pred pred, Proj proj = {}); // since C++20
325
326 template<input_iterator I, sentinel_for<I> S, class Proj = identity,
327 indirect_unary_predicate<projected<I, Proj>> Pred>
328 constexpr bool ranges::any_of(I first, S last, Pred pred, Proj proj = {}); // since C++20
329
330 template<input_range R, class Proj = identity,
331 indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
332 constexpr bool ranges::any_of(R&& r, Pred pred, Proj proj = {}); // since C++20
333
334 template<input_iterator I, sentinel_for<I> S, class Proj = identity,
335 indirect_unary_predicate<projected<I, Proj>> Pred>
336 constexpr bool ranges::none_of(I first, S last, Pred pred, Proj proj = {}); // since C++20
337
338 template<input_range R, class Proj = identity,
339 indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
340 constexpr bool ranges::none_of(R&& r, Pred pred, Proj proj = {}); // since C++20
341
Nikolas Klauserab0b7af2022-05-26 16:08:55 +0200342 template<forward_iterator I, sentinel_for<I> S, class Proj = identity,
343 indirect_strict_weak_order<projected<I, Proj>> Comp = ranges::less>
344 constexpr bool ranges::is_sorted(I first, S last, Comp comp = {}, Proj proj = {}); // since C++20
345
346 template<forward_range R, class Proj = identity,
347 indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less>
348 constexpr bool ranges::is_sorted(R&& r, Comp comp = {}, Proj proj = {}); // since C++20
349
350 template<forward_iterator I, sentinel_for<I> S, class Proj = identity,
351 indirect_strict_weak_order<projected<I, Proj>> Comp = ranges::less>
352 constexpr I ranges::is_sorted_until(I first, S last, Comp comp = {}, Proj proj = {}); // since C++20
353
354 template<forward_range R, class Proj = identity,
355 indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less>
356 constexpr borrowed_iterator_t<R>
357 ranges::is_sorted_until(R&& r, Comp comp = {}, Proj proj = {}); // since C++20
Nikolas Klauser8b381972022-06-05 21:15:16 +0200358
359 template<forward_iterator I, sentinel_for<I> S, class T, class Proj = identity,
360 indirect_strict_weak_order<const T*, projected<I, Proj>> Comp = ranges::less>
361 constexpr I upper_bound(I first, S last, const T& value, Comp comp = {}, Proj proj = {}); // since C++20
362
363 template<forward_range R, class T, class Proj = identity,
364 indirect_strict_weak_order<const T*, projected<iterator_t<R>, Proj>> Comp =
365 ranges::less>
366 constexpr borrowed_iterator_t<R>
367 upper_bound(R&& r, const T& value, Comp comp = {}, Proj proj = {}); // since C++20
368
369 template<forward_iterator I, sentinel_for<I> S, class T, class Proj = identity,
370 indirect_strict_weak_order<const T*, projected<I, Proj>> Comp = ranges::less>
371 constexpr I lower_bound(I first, S last, const T& value, Comp comp = {},
372 Proj proj = {}); // since C++20
373 template<forward_range R, class T, class Proj = identity,
374 indirect_strict_weak_order<const T*, projected<iterator_t<R>, Proj>> Comp =
375 ranges::less>
376 constexpr borrowed_iterator_t<R>
377 lower_bound(R&& r, const T& value, Comp comp = {}, Proj proj = {}); // since C++20
378
379 template<forward_iterator I, sentinel_for<I> S, class T, class Proj = identity,
380 indirect_strict_weak_order<const T*, projected<I, Proj>> Comp = ranges::less>
381 constexpr bool binary_search(I first, S last, const T& value, Comp comp = {},
382 Proj proj = {}); // since C++20
Nikolas Klauser0a7e46d2022-06-06 13:57:34 +0200383
Nikolas Klauser8b381972022-06-05 21:15:16 +0200384 template<forward_range R, class T, class Proj = identity,
385 indirect_strict_weak_order<const T*, projected<iterator_t<R>, Proj>> Comp =
386 ranges::less>
387 constexpr bool binary_search(R&& r, const T& value, Comp comp = {},
388 Proj proj = {}); // since C++20
Nikolas Klauser0a7e46d2022-06-06 13:57:34 +0200389 template<input_iterator I1, sentinel_for<I1> S1, forward_iterator I2, sentinel_for<I2> S2,
390 class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
391 requires indirectly_comparable<I1, I2, Pred, Proj1, Proj2>
392 constexpr I1 ranges::find_first_of(I1 first1, S1 last1, I2 first2, S2 last2,
393 Pred pred = {},
394 Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
395
396 template<input_range R1, forward_range R2,
397 class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
398 requires indirectly_comparable<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
399 constexpr borrowed_iterator_t<R1>
400 ranges::find_first_of(R1&& r1, R2&& r2,
401 Pred pred = {},
402 Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
Nikolas Klauser8b381972022-06-05 21:15:16 +0200403
Nikolas Klauser5ae708f2022-06-08 12:14:12 +0200404 template<forward_iterator I, sentinel_for<I> S, class Proj = identity,
405 indirect_binary_predicate<projected<I, Proj>,
406 projected<I, Proj>> Pred = ranges::equal_to>
407 constexpr I ranges::adjacent_find(I first, S last, Pred pred = {}, Proj proj = {}); // since C+20
408
409 template<forward_range R, class Proj = identity,
410 indirect_binary_predicate<projected<iterator_t<R>, Proj>,
411 projected<iterator_t<R>, Proj>> Pred = ranges::equal_to>
412 constexpr borrowed_iterator_t<R> ranges::adjacent_find(R&& r, Pred pred = {}, Proj proj = {}); // since C++20
413
Nikolas Klauserfadea392022-06-07 09:42:10 +0200414 template<input_iterator I, sentinel_for<I> S, class T1, class T2, class Proj = identity>
415 requires indirectly_writable<I, const T2&> &&
416 indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T1*>
417 constexpr I
418 ranges::replace(I first, S last, const T1& old_value, const T2& new_value, Proj proj = {}); // since C++20
419
420 template<input_range R, class T1, class T2, class Proj = identity>
421 requires indirectly_writable<iterator_t<R>, const T2&> &&
422 indirect_binary_predicate<ranges::equal_to, projected<iterator_t<R>, Proj>, const T1*>
423 constexpr borrowed_iterator_t<R>
424 ranges::replace(R&& r, const T1& old_value, const T2& new_value, Proj proj = {}); // since C++20
425
426 template<input_iterator I, sentinel_for<I> S, class T, class Proj = identity,
427 indirect_unary_predicate<projected<I, Proj>> Pred>
428 requires indirectly_writable<I, const T&>
429 constexpr I ranges::replace_if(I first, S last, Pred pred, const T& new_value, Proj proj = {}); // since C++20
430
431 template<input_range R, class T, class Proj = identity,
432 indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
433 requires indirectly_writable<iterator_t<R>, const T&>
434 constexpr borrowed_iterator_t<R>
435 ranges::replace_if(R&& r, Pred pred, const T& new_value, Proj proj = {}); // since C++20
436
Nikolas Klauser2fd677c2022-06-15 16:24:43 +0200437 template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2,
438 class Proj1 = identity, class Proj2 = identity,
439 indirect_strict_weak_order<projected<I1, Proj1>,
440 projected<I2, Proj2>> Comp = ranges::less>
441 constexpr bool
442 ranges::lexicographical_compare(I1 first1, S1 last1, I2 first2, S2 last2,
443 Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
444
445 template<input_range R1, input_range R2, class Proj1 = identity,
446 class Proj2 = identity,
447 indirect_strict_weak_order<projected<iterator_t<R1>, Proj1>,
448 projected<iterator_t<R2>, Proj2>> Comp = ranges::less>
449 constexpr bool
450 ranges::lexicographical_compare(R1&& r1, R2&& r2, Comp comp = {},
451 Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
452
Nikolas Klauserf74be4e2022-01-14 02:55:51 +0100453}
454
Marshall Clowd607fdb2018-01-15 17:20:36 +0000455 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000456 all_of(InputIterator first, InputIterator last, Predicate pred);
457
458template <class InputIterator, class Predicate>
Marshall Clowd607fdb2018-01-15 17:20:36 +0000459 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000460 any_of(InputIterator first, InputIterator last, Predicate pred);
461
462template <class InputIterator, class Predicate>
Marshall Clowd607fdb2018-01-15 17:20:36 +0000463 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000464 none_of(InputIterator first, InputIterator last, Predicate pred);
465
466template <class InputIterator, class Function>
Marshall Clow5492c8a2018-01-22 20:44:33 +0000467 constexpr Function // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000468 for_each(InputIterator first, InputIterator last, Function f);
469
Marshall Clowde0169c2017-05-25 02:29:54 +0000470template<class InputIterator, class Size, class Function>
Marshall Clow5492c8a2018-01-22 20:44:33 +0000471 constexpr InputIterator // constexpr in C++20
472 for_each_n(InputIterator first, Size n, Function f); // C++17
Marshall Clowde0169c2017-05-25 02:29:54 +0000473
Howard Hinnantc51e1022010-05-11 19:42:16 +0000474template <class InputIterator, class T>
Marshall Clowee0161e2018-01-15 19:26:05 +0000475 constexpr InputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000476 find(InputIterator first, InputIterator last, const T& value);
477
478template <class InputIterator, class Predicate>
Marshall Clowee0161e2018-01-15 19:26:05 +0000479 constexpr InputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000480 find_if(InputIterator first, InputIterator last, Predicate pred);
481
482template<class InputIterator, class Predicate>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500483 constexpr InputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000484 find_if_not(InputIterator first, InputIterator last, Predicate pred);
485
486template <class ForwardIterator1, class ForwardIterator2>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500487 constexpr ForwardIterator1 // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000488 find_end(ForwardIterator1 first1, ForwardIterator1 last1,
489 ForwardIterator2 first2, ForwardIterator2 last2);
490
491template <class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500492 constexpr ForwardIterator1 // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000493 find_end(ForwardIterator1 first1, ForwardIterator1 last1,
494 ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred);
495
496template <class ForwardIterator1, class ForwardIterator2>
Marshall Clowee0161e2018-01-15 19:26:05 +0000497 constexpr ForwardIterator1 // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000498 find_first_of(ForwardIterator1 first1, ForwardIterator1 last1,
499 ForwardIterator2 first2, ForwardIterator2 last2);
500
501template <class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
Marshall Clowee0161e2018-01-15 19:26:05 +0000502 constexpr ForwardIterator1 // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000503 find_first_of(ForwardIterator1 first1, ForwardIterator1 last1,
504 ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred);
505
506template <class ForwardIterator>
Marshall Clowee0161e2018-01-15 19:26:05 +0000507 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000508 adjacent_find(ForwardIterator first, ForwardIterator last);
509
510template <class ForwardIterator, class BinaryPredicate>
Marshall Clowee0161e2018-01-15 19:26:05 +0000511 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000512 adjacent_find(ForwardIterator first, ForwardIterator last, BinaryPredicate pred);
513
514template <class InputIterator, class T>
Marshall Clow3c0558f2018-01-15 19:40:34 +0000515 constexpr typename iterator_traits<InputIterator>::difference_type // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000516 count(InputIterator first, InputIterator last, const T& value);
517
518template <class InputIterator, class Predicate>
Marshall Clow3c0558f2018-01-15 19:40:34 +0000519 constexpr typename iterator_traits<InputIterator>::difference_type // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000520 count_if(InputIterator first, InputIterator last, Predicate pred);
521
522template <class InputIterator1, class InputIterator2>
Marshall Clow30bf3022018-01-16 02:04:10 +0000523 constexpr pair<InputIterator1, InputIterator2> // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000524 mismatch(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2);
525
Marshall Clow96b42b22013-05-09 21:14:23 +0000526template <class InputIterator1, class InputIterator2>
Marshall Clow30bf3022018-01-16 02:04:10 +0000527 constexpr pair<InputIterator1, InputIterator2> // constexpr in C++20
Aditya Kumar3a0179a2016-08-25 11:52:38 +0000528 mismatch(InputIterator1 first1, InputIterator1 last1,
Marshall Clow96b42b22013-05-09 21:14:23 +0000529 InputIterator2 first2, InputIterator2 last2); // **C++14**
530
Howard Hinnantc51e1022010-05-11 19:42:16 +0000531template <class InputIterator1, class InputIterator2, class BinaryPredicate>
Marshall Clow30bf3022018-01-16 02:04:10 +0000532 constexpr pair<InputIterator1, InputIterator2> // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000533 mismatch(InputIterator1 first1, InputIterator1 last1,
534 InputIterator2 first2, BinaryPredicate pred);
535
Marshall Clow96b42b22013-05-09 21:14:23 +0000536template <class InputIterator1, class InputIterator2, class BinaryPredicate>
Marshall Clow30bf3022018-01-16 02:04:10 +0000537 constexpr pair<InputIterator1, InputIterator2> // constexpr in C++20
Marshall Clow96b42b22013-05-09 21:14:23 +0000538 mismatch(InputIterator1 first1, InputIterator1 last1,
539 InputIterator2 first2, InputIterator2 last2,
540 BinaryPredicate pred); // **C++14**
541
Howard Hinnantc51e1022010-05-11 19:42:16 +0000542template <class InputIterator1, class InputIterator2>
Marshall Clow30bf3022018-01-16 02:04:10 +0000543 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000544 equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2);
545
Marshall Clow96b42b22013-05-09 21:14:23 +0000546template <class InputIterator1, class InputIterator2>
Marshall Clow30bf3022018-01-16 02:04:10 +0000547 constexpr bool // constexpr in C++20
Aditya Kumar3a0179a2016-08-25 11:52:38 +0000548 equal(InputIterator1 first1, InputIterator1 last1,
Marshall Clow96b42b22013-05-09 21:14:23 +0000549 InputIterator2 first2, InputIterator2 last2); // **C++14**
550
Howard Hinnantc51e1022010-05-11 19:42:16 +0000551template <class InputIterator1, class InputIterator2, class BinaryPredicate>
Marshall Clow30bf3022018-01-16 02:04:10 +0000552 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000553 equal(InputIterator1 first1, InputIterator1 last1,
554 InputIterator2 first2, BinaryPredicate pred);
555
Marshall Clow96b42b22013-05-09 21:14:23 +0000556template <class InputIterator1, class InputIterator2, class BinaryPredicate>
Marshall Clow30bf3022018-01-16 02:04:10 +0000557 constexpr bool // constexpr in C++20
Marshall Clow96b42b22013-05-09 21:14:23 +0000558 equal(InputIterator1 first1, InputIterator1 last1,
559 InputIterator2 first2, InputIterator2 last2,
560 BinaryPredicate pred); // **C++14**
561
Howard Hinnantc51e1022010-05-11 19:42:16 +0000562template<class ForwardIterator1, class ForwardIterator2>
Marshall Clow96d050a2018-01-15 16:16:32 +0000563 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000564 is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
565 ForwardIterator2 first2);
566
Marshall Clow96b42b22013-05-09 21:14:23 +0000567template<class ForwardIterator1, class ForwardIterator2>
Marshall Clow96d050a2018-01-15 16:16:32 +0000568 constexpr bool // constexpr in C++20
Marshall Clow96b42b22013-05-09 21:14:23 +0000569 is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
570 ForwardIterator2 first2, ForwardIterator2 last2); // **C++14**
571
Howard Hinnantc51e1022010-05-11 19:42:16 +0000572template<class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
Marshall Clow96d050a2018-01-15 16:16:32 +0000573 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000574 is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
575 ForwardIterator2 first2, BinaryPredicate pred);
576
Marshall Clow96b42b22013-05-09 21:14:23 +0000577template<class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
Marshall Clow96d050a2018-01-15 16:16:32 +0000578 constexpr bool // constexpr in C++20
Marshall Clow96b42b22013-05-09 21:14:23 +0000579 is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
580 ForwardIterator2 first2, ForwardIterator2 last2,
581 BinaryPredicate pred); // **C++14**
582
Howard Hinnantc51e1022010-05-11 19:42:16 +0000583template <class ForwardIterator1, class ForwardIterator2>
Marshall Clow323fc5b2018-01-16 15:48:27 +0000584 constexpr ForwardIterator1 // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000585 search(ForwardIterator1 first1, ForwardIterator1 last1,
586 ForwardIterator2 first2, ForwardIterator2 last2);
587
588template <class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
Marshall Clow323fc5b2018-01-16 15:48:27 +0000589 constexpr ForwardIterator1 // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000590 search(ForwardIterator1 first1, ForwardIterator1 last1,
591 ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred);
592
593template <class ForwardIterator, class Size, class T>
Marshall Clow323fc5b2018-01-16 15:48:27 +0000594 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000595 search_n(ForwardIterator first, ForwardIterator last, Size count, const T& value);
596
597template <class ForwardIterator, class Size, class T, class BinaryPredicate>
Marshall Clow323fc5b2018-01-16 15:48:27 +0000598 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000599 search_n(ForwardIterator first, ForwardIterator last,
600 Size count, const T& value, BinaryPredicate pred);
601
602template <class InputIterator, class OutputIterator>
Louis Dionne65b433b2019-11-06 12:02:41 +0000603 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000604 copy(InputIterator first, InputIterator last, OutputIterator result);
605
606template<class InputIterator, class OutputIterator, class Predicate>
Louis Dionne65b433b2019-11-06 12:02:41 +0000607 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000608 copy_if(InputIterator first, InputIterator last,
609 OutputIterator result, Predicate pred);
610
611template<class InputIterator, class Size, class OutputIterator>
Louis Dionne65b433b2019-11-06 12:02:41 +0000612 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000613 copy_n(InputIterator first, Size n, OutputIterator result);
614
615template <class BidirectionalIterator1, class BidirectionalIterator2>
Louis Dionne65b433b2019-11-06 12:02:41 +0000616 constexpr BidirectionalIterator2 // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000617 copy_backward(BidirectionalIterator1 first, BidirectionalIterator1 last,
618 BidirectionalIterator2 result);
619
620template <class ForwardIterator1, class ForwardIterator2>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500621 constexpr ForwardIterator2 // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000622 swap_ranges(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2);
623
Nikolas Klauser4ceab5f2022-02-10 13:33:03 +0100624template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2>
625 requires indirectly_swappable<I1, I2>
626 constexpr ranges::swap_ranges_result<I1, I2>
627 ranges::swap_ranges(I1 first1, S1 last1, I2 first2, S2 last2);
628
629template<input_range R1, input_range R2>
630 requires indirectly_swappable<iterator_t<R1>, iterator_t<R2>>
631 constexpr ranges::swap_ranges_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>>
632 ranges::swap_ranges(R1&& r1, R2&& r2);
633
Howard Hinnantc51e1022010-05-11 19:42:16 +0000634template <class ForwardIterator1, class ForwardIterator2>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500635 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000636 iter_swap(ForwardIterator1 a, ForwardIterator2 b);
637
638template <class InputIterator, class OutputIterator, class UnaryOperation>
Marshall Clow31427c62018-01-19 17:45:39 +0000639 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000640 transform(InputIterator first, InputIterator last, OutputIterator result, UnaryOperation op);
641
642template <class InputIterator1, class InputIterator2, class OutputIterator, class BinaryOperation>
Marshall Clow31427c62018-01-19 17:45:39 +0000643 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000644 transform(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2,
645 OutputIterator result, BinaryOperation binary_op);
646
647template <class ForwardIterator, class T>
Marshall Clow01bbbd22018-01-19 18:07:29 +0000648 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000649 replace(ForwardIterator first, ForwardIterator last, const T& old_value, const T& new_value);
650
651template <class ForwardIterator, class Predicate, class T>
Marshall Clow01bbbd22018-01-19 18:07:29 +0000652 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000653 replace_if(ForwardIterator first, ForwardIterator last, Predicate pred, const T& new_value);
654
655template <class InputIterator, class OutputIterator, class T>
Marshall Clow01bbbd22018-01-19 18:07:29 +0000656 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000657 replace_copy(InputIterator first, InputIterator last, OutputIterator result,
658 const T& old_value, const T& new_value);
659
660template <class InputIterator, class OutputIterator, class Predicate, class T>
Marshall Clow01bbbd22018-01-19 18:07:29 +0000661 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000662 replace_copy_if(InputIterator first, InputIterator last, OutputIterator result, Predicate pred, const T& new_value);
663
664template <class ForwardIterator, class T>
Marshall Clowe9cdc5c2018-01-20 20:14:32 +0000665 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000666 fill(ForwardIterator first, ForwardIterator last, const T& value);
667
668template <class OutputIterator, class Size, class T>
Marshall Clowe9cdc5c2018-01-20 20:14:32 +0000669 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000670 fill_n(OutputIterator first, Size n, const T& value);
671
672template <class ForwardIterator, class Generator>
Marshall Clowe9cdc5c2018-01-20 20:14:32 +0000673 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000674 generate(ForwardIterator first, ForwardIterator last, Generator gen);
675
676template <class OutputIterator, class Size, class Generator>
Marshall Clowe9cdc5c2018-01-20 20:14:32 +0000677 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000678 generate_n(OutputIterator first, Size n, Generator gen);
679
680template <class ForwardIterator, class T>
Marshall Clow7c0fbd82018-01-22 21:43:04 +0000681 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000682 remove(ForwardIterator first, ForwardIterator last, const T& value);
683
684template <class ForwardIterator, class Predicate>
Marshall Clow7c0fbd82018-01-22 21:43:04 +0000685 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000686 remove_if(ForwardIterator first, ForwardIterator last, Predicate pred);
687
688template <class InputIterator, class OutputIterator, class T>
Marshall Clow7c0fbd82018-01-22 21:43:04 +0000689 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000690 remove_copy(InputIterator first, InputIterator last, OutputIterator result, const T& value);
691
692template <class InputIterator, class OutputIterator, class Predicate>
Marshall Clow7c0fbd82018-01-22 21:43:04 +0000693 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000694 remove_copy_if(InputIterator first, InputIterator last, OutputIterator result, Predicate pred);
695
696template <class ForwardIterator>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500697 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000698 unique(ForwardIterator first, ForwardIterator last);
699
700template <class ForwardIterator, class BinaryPredicate>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500701 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000702 unique(ForwardIterator first, ForwardIterator last, BinaryPredicate pred);
703
704template <class InputIterator, class OutputIterator>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500705 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000706 unique_copy(InputIterator first, InputIterator last, OutputIterator result);
707
708template <class InputIterator, class OutputIterator, class BinaryPredicate>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500709 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000710 unique_copy(InputIterator first, InputIterator last, OutputIterator result, BinaryPredicate pred);
711
712template <class BidirectionalIterator>
Arthur O'Dwyere50e7472020-12-17 00:01:08 -0500713 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000714 reverse(BidirectionalIterator first, BidirectionalIterator last);
715
716template <class BidirectionalIterator, class OutputIterator>
Marshall Clow7c0fbd82018-01-22 21:43:04 +0000717 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000718 reverse_copy(BidirectionalIterator first, BidirectionalIterator last, OutputIterator result);
719
720template <class ForwardIterator>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500721 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000722 rotate(ForwardIterator first, ForwardIterator middle, ForwardIterator last);
723
724template <class ForwardIterator, class OutputIterator>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500725 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000726 rotate_copy(ForwardIterator first, ForwardIterator middle, ForwardIterator last, OutputIterator result);
727
728template <class RandomAccessIterator>
729 void
Marshall Clowfac06e52017-03-23 13:43:37 +0000730 random_shuffle(RandomAccessIterator first, RandomAccessIterator last); // deprecated in C++14, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000731
732template <class RandomAccessIterator, class RandomNumberGenerator>
733 void
Marshall Clow83f35392014-03-03 06:14:19 +0000734 random_shuffle(RandomAccessIterator first, RandomAccessIterator last,
Marshall Clowfac06e52017-03-23 13:43:37 +0000735 RandomNumberGenerator& rand); // deprecated in C++14, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000736
Eric Fiselier1208fcd2016-08-28 22:14:37 +0000737template<class PopulationIterator, class SampleIterator,
738 class Distance, class UniformRandomBitGenerator>
739 SampleIterator sample(PopulationIterator first, PopulationIterator last,
740 SampleIterator out, Distance n,
741 UniformRandomBitGenerator&& g); // C++17
742
Howard Hinnant578ac0f2010-05-26 17:49:34 +0000743template<class RandomAccessIterator, class UniformRandomNumberGenerator>
744 void shuffle(RandomAccessIterator first, RandomAccessIterator last,
Howard Hinnanta5e71782010-11-18 01:47:02 +0000745 UniformRandomNumberGenerator&& g);
Howard Hinnant578ac0f2010-05-26 17:49:34 +0000746
Arthur O'Dwyercea050d2020-12-26 01:39:03 -0500747template<class ForwardIterator>
748 constexpr ForwardIterator
749 shift_left(ForwardIterator first, ForwardIterator last,
750 typename iterator_traits<ForwardIterator>::difference_type n); // C++20
751
752template<class ForwardIterator>
753 constexpr ForwardIterator
754 shift_right(ForwardIterator first, ForwardIterator last,
755 typename iterator_traits<ForwardIterator>::difference_type n); // C++20
756
Howard Hinnantc51e1022010-05-11 19:42:16 +0000757template <class InputIterator, class Predicate>
Marshall Clow96d050a2018-01-15 16:16:32 +0000758 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000759 is_partitioned(InputIterator first, InputIterator last, Predicate pred);
760
761template <class ForwardIterator, class Predicate>
Arthur O'Dwyere50e7472020-12-17 00:01:08 -0500762 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000763 partition(ForwardIterator first, ForwardIterator last, Predicate pred);
764
765template <class InputIterator, class OutputIterator1,
766 class OutputIterator2, class Predicate>
Marshall Clow5492c8a2018-01-22 20:44:33 +0000767 constexpr pair<OutputIterator1, OutputIterator2> // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000768 partition_copy(InputIterator first, InputIterator last,
769 OutputIterator1 out_true, OutputIterator2 out_false,
770 Predicate pred);
771
772template <class ForwardIterator, class Predicate>
773 ForwardIterator
774 stable_partition(ForwardIterator first, ForwardIterator last, Predicate pred);
775
776template<class ForwardIterator, class Predicate>
Marshall Clowe00916c2018-01-16 02:34:41 +0000777 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000778 partition_point(ForwardIterator first, ForwardIterator last, Predicate pred);
779
780template <class ForwardIterator>
Marshall Clow96d050a2018-01-15 16:16:32 +0000781 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000782 is_sorted(ForwardIterator first, ForwardIterator last);
783
784template <class ForwardIterator, class Compare>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500785 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000786 is_sorted(ForwardIterator first, ForwardIterator last, Compare comp);
787
788template<class ForwardIterator>
Marshall Clow3c0558f2018-01-15 19:40:34 +0000789 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000790 is_sorted_until(ForwardIterator first, ForwardIterator last);
791
792template <class ForwardIterator, class Compare>
Marshall Clow3c0558f2018-01-15 19:40:34 +0000793 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000794 is_sorted_until(ForwardIterator first, ForwardIterator last, Compare comp);
795
796template <class RandomAccessIterator>
Arthur O'Dwyer1bb0f672020-12-20 15:21:42 -0500797 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000798 sort(RandomAccessIterator first, RandomAccessIterator last);
799
800template <class RandomAccessIterator, class Compare>
Arthur O'Dwyer1bb0f672020-12-20 15:21:42 -0500801 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000802 sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
803
804template <class RandomAccessIterator>
805 void
806 stable_sort(RandomAccessIterator first, RandomAccessIterator last);
807
808template <class RandomAccessIterator, class Compare>
809 void
810 stable_sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
811
812template <class RandomAccessIterator>
Arthur O'Dwyer2dfea5d2020-12-17 00:26:18 -0500813 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000814 partial_sort(RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last);
815
816template <class RandomAccessIterator, class Compare>
Arthur O'Dwyer2dfea5d2020-12-17 00:26:18 -0500817 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000818 partial_sort(RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last, Compare comp);
819
820template <class InputIterator, class RandomAccessIterator>
Arthur O'Dwyer2dfea5d2020-12-17 00:26:18 -0500821 constexpr RandomAccessIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000822 partial_sort_copy(InputIterator first, InputIterator last,
823 RandomAccessIterator result_first, RandomAccessIterator result_last);
824
825template <class InputIterator, class RandomAccessIterator, class Compare>
Arthur O'Dwyer2dfea5d2020-12-17 00:26:18 -0500826 constexpr RandomAccessIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000827 partial_sort_copy(InputIterator first, InputIterator last,
828 RandomAccessIterator result_first, RandomAccessIterator result_last, Compare comp);
829
830template <class RandomAccessIterator>
Arthur O'Dwyer4f5717b2021-02-04 18:12:52 -0500831 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000832 nth_element(RandomAccessIterator first, RandomAccessIterator nth, RandomAccessIterator last);
833
834template <class RandomAccessIterator, class Compare>
Arthur O'Dwyer4f5717b2021-02-04 18:12:52 -0500835 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000836 nth_element(RandomAccessIterator first, RandomAccessIterator nth, RandomAccessIterator last, Compare comp);
837
838template <class ForwardIterator, class T>
Marshall Clowe00916c2018-01-16 02:34:41 +0000839 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000840 lower_bound(ForwardIterator first, ForwardIterator last, const T& value);
841
842template <class ForwardIterator, class T, class Compare>
Marshall Clowe00916c2018-01-16 02:34:41 +0000843 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000844 lower_bound(ForwardIterator first, ForwardIterator last, const T& value, Compare comp);
845
846template <class ForwardIterator, class T>
Marshall Clowe00916c2018-01-16 02:34:41 +0000847 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000848 upper_bound(ForwardIterator first, ForwardIterator last, const T& value);
849
850template <class ForwardIterator, class T, class Compare>
Marshall Clowe00916c2018-01-16 02:34:41 +0000851 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000852 upper_bound(ForwardIterator first, ForwardIterator last, const T& value, Compare comp);
853
854template <class ForwardIterator, class T>
Marshall Clowe00916c2018-01-16 02:34:41 +0000855 constexpr pair<ForwardIterator, ForwardIterator> // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000856 equal_range(ForwardIterator first, ForwardIterator last, const T& value);
857
858template <class ForwardIterator, class T, class Compare>
Marshall Clowe00916c2018-01-16 02:34:41 +0000859 constexpr pair<ForwardIterator, ForwardIterator> // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000860 equal_range(ForwardIterator first, ForwardIterator last, const T& value, Compare comp);
861
862template <class ForwardIterator, class T>
Marshall Clowe00916c2018-01-16 02:34:41 +0000863 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000864 binary_search(ForwardIterator first, ForwardIterator last, const T& value);
865
866template <class ForwardIterator, class T, class Compare>
Marshall Clowc0b7f972018-01-22 23:10:40 +0000867 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000868 binary_search(ForwardIterator first, ForwardIterator last, const T& value, Compare comp);
869
870template <class InputIterator1, class InputIterator2, class OutputIterator>
Arthur O'Dwyer5afc5692020-12-04 13:47:12 -0500871 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000872 merge(InputIterator1 first1, InputIterator1 last1,
873 InputIterator2 first2, InputIterator2 last2, OutputIterator result);
874
875template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
Arthur O'Dwyer5afc5692020-12-04 13:47:12 -0500876 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000877 merge(InputIterator1 first1, InputIterator1 last1,
878 InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
879
880template <class BidirectionalIterator>
881 void
882 inplace_merge(BidirectionalIterator first, BidirectionalIterator middle, BidirectionalIterator last);
883
884template <class BidirectionalIterator, class Compare>
885 void
886 inplace_merge(BidirectionalIterator first, BidirectionalIterator middle, BidirectionalIterator last, Compare comp);
887
888template <class InputIterator1, class InputIterator2>
Marshall Clowc0b7f972018-01-22 23:10:40 +0000889 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000890 includes(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2);
891
892template <class InputIterator1, class InputIterator2, class Compare>
Marshall Clowc0b7f972018-01-22 23:10:40 +0000893 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000894 includes(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, Compare comp);
895
896template <class InputIterator1, class InputIterator2, class OutputIterator>
Arthur O'Dwyer5afc5692020-12-04 13:47:12 -0500897 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000898 set_union(InputIterator1 first1, InputIterator1 last1,
899 InputIterator2 first2, InputIterator2 last2, OutputIterator result);
900
901template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
Arthur O'Dwyer5afc5692020-12-04 13:47:12 -0500902 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000903 set_union(InputIterator1 first1, InputIterator1 last1,
904 InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
905
906template <class InputIterator1, class InputIterator2, class OutputIterator>
Marshall Clowc0b7f972018-01-22 23:10:40 +0000907 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000908 set_intersection(InputIterator1 first1, InputIterator1 last1,
909 InputIterator2 first2, InputIterator2 last2, OutputIterator result);
910
911template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
Marshall Clowc0b7f972018-01-22 23:10:40 +0000912 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000913 set_intersection(InputIterator1 first1, InputIterator1 last1,
914 InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
915
916template <class InputIterator1, class InputIterator2, class OutputIterator>
Arthur O'Dwyer5afc5692020-12-04 13:47:12 -0500917 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000918 set_difference(InputIterator1 first1, InputIterator1 last1,
919 InputIterator2 first2, InputIterator2 last2, OutputIterator result);
920
921template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
Arthur O'Dwyer5afc5692020-12-04 13:47:12 -0500922 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000923 set_difference(InputIterator1 first1, InputIterator1 last1,
924 InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
925
926template <class InputIterator1, class InputIterator2, class OutputIterator>
Arthur O'Dwyer5afc5692020-12-04 13:47:12 -0500927 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000928 set_symmetric_difference(InputIterator1 first1, InputIterator1 last1,
929 InputIterator2 first2, InputIterator2 last2, OutputIterator result);
930
931template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
Arthur O'Dwyer5afc5692020-12-04 13:47:12 -0500932 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000933 set_symmetric_difference(InputIterator1 first1, InputIterator1 last1,
934 InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
935
936template <class RandomAccessIterator>
Arthur O'Dwyer2dfea5d2020-12-17 00:26:18 -0500937 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000938 push_heap(RandomAccessIterator first, RandomAccessIterator last);
939
940template <class RandomAccessIterator, class Compare>
Arthur O'Dwyer2dfea5d2020-12-17 00:26:18 -0500941 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000942 push_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
943
944template <class RandomAccessIterator>
Arthur O'Dwyer2dfea5d2020-12-17 00:26:18 -0500945 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000946 pop_heap(RandomAccessIterator first, RandomAccessIterator last);
947
948template <class RandomAccessIterator, class Compare>
Arthur O'Dwyer2dfea5d2020-12-17 00:26:18 -0500949 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000950 pop_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
951
952template <class RandomAccessIterator>
Arthur O'Dwyer2dfea5d2020-12-17 00:26:18 -0500953 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000954 make_heap(RandomAccessIterator first, RandomAccessIterator last);
955
956template <class RandomAccessIterator, class Compare>
Arthur O'Dwyer2dfea5d2020-12-17 00:26:18 -0500957 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000958 make_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
959
960template <class RandomAccessIterator>
Arthur O'Dwyer2dfea5d2020-12-17 00:26:18 -0500961 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000962 sort_heap(RandomAccessIterator first, RandomAccessIterator last);
963
964template <class RandomAccessIterator, class Compare>
Arthur O'Dwyer2dfea5d2020-12-17 00:26:18 -0500965 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000966 sort_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
967
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000968template <class RandomAccessIterator>
Marshall Clow96d050a2018-01-15 16:16:32 +0000969 constexpr bool // constexpr in C++20
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000970 is_heap(RandomAccessIterator first, RandomAccessiterator last);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000971
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000972template <class RandomAccessIterator, class Compare>
Marshall Clow96d050a2018-01-15 16:16:32 +0000973 constexpr bool // constexpr in C++20
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000974 is_heap(RandomAccessIterator first, RandomAccessiterator last, Compare comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000975
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000976template <class RandomAccessIterator>
Marshall Clow96d050a2018-01-15 16:16:32 +0000977 constexpr RandomAccessIterator // constexpr in C++20
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000978 is_heap_until(RandomAccessIterator first, RandomAccessiterator last);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000979
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000980template <class RandomAccessIterator, class Compare>
Marshall Clow96d050a2018-01-15 16:16:32 +0000981 constexpr RandomAccessIterator // constexpr in C++20
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000982 is_heap_until(RandomAccessIterator first, RandomAccessiterator last, Compare comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000983
Howard Hinnantb120e7a2010-08-21 20:10:01 +0000984template <class ForwardIterator>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500985 constexpr ForwardIterator // constexpr in C++14
986 min_element(ForwardIterator first, ForwardIterator last);
Howard Hinnantb120e7a2010-08-21 20:10:01 +0000987
988template <class ForwardIterator, class Compare>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500989 constexpr ForwardIterator // constexpr in C++14
990 min_element(ForwardIterator first, ForwardIterator last, Compare comp);
Howard Hinnantb120e7a2010-08-21 20:10:01 +0000991
Howard Hinnantc51e1022010-05-11 19:42:16 +0000992template <class T>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500993 constexpr const T& // constexpr in C++14
994 min(const T& a, const T& b);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000995
996template <class T, class Compare>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500997 constexpr const T& // constexpr in C++14
998 min(const T& a, const T& b, Compare comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000999
Howard Hinnantb120e7a2010-08-21 20:10:01 +00001000template<class T>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -05001001 constexpr T // constexpr in C++14
1002 min(initializer_list<T> t);
Howard Hinnantb120e7a2010-08-21 20:10:01 +00001003
1004template<class T, class Compare>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -05001005 constexpr T // constexpr in C++14
1006 min(initializer_list<T> t, Compare comp);
Howard Hinnantb120e7a2010-08-21 20:10:01 +00001007
Marshall Clow3e18d0e2016-03-07 22:43:49 +00001008template<class T>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -05001009 constexpr const T& clamp(const T& v, const T& lo, const T& hi); // C++17
Marshall Clow3e18d0e2016-03-07 22:43:49 +00001010
1011template<class T, class Compare>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -05001012 constexpr const T& clamp(const T& v, const T& lo, const T& hi, Compare comp); // C++17
Marshall Clow3e18d0e2016-03-07 22:43:49 +00001013
Howard Hinnantb120e7a2010-08-21 20:10:01 +00001014template <class ForwardIterator>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -05001015 constexpr ForwardIterator // constexpr in C++14
1016 max_element(ForwardIterator first, ForwardIterator last);
Howard Hinnantb120e7a2010-08-21 20:10:01 +00001017
1018template <class ForwardIterator, class Compare>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -05001019 constexpr ForwardIterator // constexpr in C++14
1020 max_element(ForwardIterator first, ForwardIterator last, Compare comp);
Howard Hinnantb120e7a2010-08-21 20:10:01 +00001021
Howard Hinnantc51e1022010-05-11 19:42:16 +00001022template <class T>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -05001023 constexpr const T& // constexpr in C++14
1024 max(const T& a, const T& b);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001025
1026template <class T, class Compare>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -05001027 constexpr const T& // constexpr in C++14
1028 max(const T& a, const T& b, Compare comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001029
Howard Hinnantb120e7a2010-08-21 20:10:01 +00001030template<class T>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -05001031 constexpr T // constexpr in C++14
1032 max(initializer_list<T> t);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001033
Howard Hinnantb120e7a2010-08-21 20:10:01 +00001034template<class T, class Compare>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -05001035 constexpr T // constexpr in C++14
1036 max(initializer_list<T> t, Compare comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001037
Howard Hinnantb120e7a2010-08-21 20:10:01 +00001038template<class ForwardIterator>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -05001039 constexpr pair<ForwardIterator, ForwardIterator> // constexpr in C++14
1040 minmax_element(ForwardIterator first, ForwardIterator last);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001041
Howard Hinnantb120e7a2010-08-21 20:10:01 +00001042template<class ForwardIterator, class Compare>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -05001043 constexpr pair<ForwardIterator, ForwardIterator> // constexpr in C++14
1044 minmax_element(ForwardIterator first, ForwardIterator last, Compare comp);
Howard Hinnantb120e7a2010-08-21 20:10:01 +00001045
1046template<class T>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -05001047 constexpr pair<const T&, const T&> // constexpr in C++14
1048 minmax(const T& a, const T& b);
Howard Hinnantb120e7a2010-08-21 20:10:01 +00001049
1050template<class T, class Compare>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -05001051 constexpr pair<const T&, const T&> // constexpr in C++14
1052 minmax(const T& a, const T& b, Compare comp);
Howard Hinnantb120e7a2010-08-21 20:10:01 +00001053
1054template<class T>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -05001055 constexpr pair<T, T> // constexpr in C++14
1056 minmax(initializer_list<T> t);
Howard Hinnantb120e7a2010-08-21 20:10:01 +00001057
1058template<class T, class Compare>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -05001059 constexpr pair<T, T> // constexpr in C++14
1060 minmax(initializer_list<T> t, Compare comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001061
1062template <class InputIterator1, class InputIterator2>
Marshall Clow5492c8a2018-01-22 20:44:33 +00001063 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +00001064 lexicographical_compare(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2);
1065
1066template <class InputIterator1, class InputIterator2, class Compare>
Marshall Clow5492c8a2018-01-22 20:44:33 +00001067 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +00001068 lexicographical_compare(InputIterator1 first1, InputIterator1 last1,
1069 InputIterator2 first2, InputIterator2 last2, Compare comp);
1070
1071template <class BidirectionalIterator>
Arthur O'Dwyere50e7472020-12-17 00:01:08 -05001072 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +00001073 next_permutation(BidirectionalIterator first, BidirectionalIterator last);
1074
1075template <class BidirectionalIterator, class Compare>
Arthur O'Dwyere50e7472020-12-17 00:01:08 -05001076 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +00001077 next_permutation(BidirectionalIterator first, BidirectionalIterator last, Compare comp);
1078
1079template <class BidirectionalIterator>
Arthur O'Dwyere50e7472020-12-17 00:01:08 -05001080 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +00001081 prev_permutation(BidirectionalIterator first, BidirectionalIterator last);
1082
1083template <class BidirectionalIterator, class Compare>
Arthur O'Dwyere50e7472020-12-17 00:01:08 -05001084 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +00001085 prev_permutation(BidirectionalIterator first, BidirectionalIterator last, Compare comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001086} // std
1087
1088*/
1089
Louis Dionneb4fce352022-03-25 12:55:36 -04001090#include <__assert> // all public C++ headers provide the assertion handler
Arthur O'Dwyer3693d7a2022-02-04 13:09:30 -05001091#include <__bits>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001092#include <__config>
Louis Dionnea60dd872021-06-17 11:30:11 -04001093#include <__debug>
Howard Hinnant60e5cf42012-07-26 17:09:09 +00001094#include <cstddef>
Arthur O'Dwyeref181602021-05-19 11:57:04 -04001095#include <cstring>
Arthur O'Dwyeref181602021-05-19 11:57:04 -04001096#include <initializer_list>
Arthur O'Dwyeref181602021-05-19 11:57:04 -04001097#include <memory>
1098#include <type_traits>
Marshall Clow0a1e7502018-09-12 19:41:40 +00001099#include <version>
Howard Hinnantea382952013-08-14 18:00:20 +00001100
Louis Dionnea60dd872021-06-17 11:30:11 -04001101#include <__algorithm/adjacent_find.h>
1102#include <__algorithm/all_of.h>
1103#include <__algorithm/any_of.h>
1104#include <__algorithm/binary_search.h>
1105#include <__algorithm/clamp.h>
1106#include <__algorithm/comp.h>
1107#include <__algorithm/comp_ref_type.h>
1108#include <__algorithm/copy.h>
1109#include <__algorithm/copy_backward.h>
1110#include <__algorithm/copy_if.h>
1111#include <__algorithm/copy_n.h>
1112#include <__algorithm/count.h>
1113#include <__algorithm/count_if.h>
1114#include <__algorithm/equal.h>
1115#include <__algorithm/equal_range.h>
Louis Dionnea60dd872021-06-17 11:30:11 -04001116#include <__algorithm/fill.h>
Arthur O'Dwyer65077c02022-01-07 09:45:05 -05001117#include <__algorithm/fill_n.h>
Louis Dionnea60dd872021-06-17 11:30:11 -04001118#include <__algorithm/find.h>
1119#include <__algorithm/find_end.h>
1120#include <__algorithm/find_first_of.h>
1121#include <__algorithm/find_if.h>
1122#include <__algorithm/find_if_not.h>
1123#include <__algorithm/for_each.h>
1124#include <__algorithm/for_each_n.h>
Louis Dionnea60dd872021-06-17 11:30:11 -04001125#include <__algorithm/generate.h>
Arthur O'Dwyer65077c02022-01-07 09:45:05 -05001126#include <__algorithm/generate_n.h>
Louis Dionnea60dd872021-06-17 11:30:11 -04001127#include <__algorithm/half_positive.h>
Nikolas Klauserdd5ad212022-02-21 23:07:02 +01001128#include <__algorithm/in_found_result.h>
Nikolas Klauser671b4752022-02-11 17:01:58 +01001129#include <__algorithm/in_fun_result.h>
Nikolas Klauser05e2cd82022-01-25 11:21:47 +01001130#include <__algorithm/in_in_out_result.h>
Nikolas Klauserf74be4e2022-01-14 02:55:51 +01001131#include <__algorithm/in_in_result.h>
Nikolas Klauser61ce8162022-02-03 02:17:03 +01001132#include <__algorithm/in_out_out_result.h>
Konstantin Varlamov74736812022-01-10 22:49:37 -08001133#include <__algorithm/in_out_result.h>
Louis Dionnea60dd872021-06-17 11:30:11 -04001134#include <__algorithm/includes.h>
1135#include <__algorithm/inplace_merge.h>
1136#include <__algorithm/is_heap.h>
1137#include <__algorithm/is_heap_until.h>
1138#include <__algorithm/is_partitioned.h>
1139#include <__algorithm/is_permutation.h>
1140#include <__algorithm/is_sorted.h>
1141#include <__algorithm/is_sorted_until.h>
Christopher Di Bella41f26e82021-06-05 02:47:47 +00001142#include <__algorithm/iter_swap.h>
Louis Dionnea60dd872021-06-17 11:30:11 -04001143#include <__algorithm/lexicographical_compare.h>
1144#include <__algorithm/lower_bound.h>
1145#include <__algorithm/make_heap.h>
1146#include <__algorithm/max.h>
1147#include <__algorithm/max_element.h>
1148#include <__algorithm/merge.h>
1149#include <__algorithm/min.h>
1150#include <__algorithm/min_element.h>
Nikolas Klauser2e263162022-02-21 22:48:36 +01001151#include <__algorithm/min_max_result.h>
Louis Dionnea60dd872021-06-17 11:30:11 -04001152#include <__algorithm/minmax.h>
1153#include <__algorithm/minmax_element.h>
1154#include <__algorithm/mismatch.h>
1155#include <__algorithm/move.h>
1156#include <__algorithm/move_backward.h>
1157#include <__algorithm/next_permutation.h>
1158#include <__algorithm/none_of.h>
1159#include <__algorithm/nth_element.h>
1160#include <__algorithm/partial_sort.h>
1161#include <__algorithm/partial_sort_copy.h>
1162#include <__algorithm/partition.h>
1163#include <__algorithm/partition_copy.h>
1164#include <__algorithm/partition_point.h>
1165#include <__algorithm/pop_heap.h>
1166#include <__algorithm/prev_permutation.h>
1167#include <__algorithm/push_heap.h>
Nikolas Klauser5ae708f2022-06-08 12:14:12 +02001168#include <__algorithm/ranges_adjacent_find.h>
Nikolas Klausered3f0e82022-05-26 16:42:46 +02001169#include <__algorithm/ranges_all_of.h>
1170#include <__algorithm/ranges_any_of.h>
Nikolas Klauser8b381972022-06-05 21:15:16 +02001171#include <__algorithm/ranges_binary_search.h>
Nikolas Klauserd959d842022-04-15 13:43:40 +02001172#include <__algorithm/ranges_copy.h>
1173#include <__algorithm/ranges_copy_backward.h>
1174#include <__algorithm/ranges_copy_if.h>
1175#include <__algorithm/ranges_copy_n.h>
Nikolas Klauserf1373d02022-04-07 13:02:02 +02001176#include <__algorithm/ranges_count.h>
1177#include <__algorithm/ranges_count_if.h>
Nikolas Klauser353f1dd2022-05-25 11:09:43 +02001178#include <__algorithm/ranges_equal.h>
Nikolas Klausereb49c2a2022-05-21 18:26:29 +02001179#include <__algorithm/ranges_fill.h>
1180#include <__algorithm/ranges_fill_n.h>
Nikolas Klauser37d076e2022-03-12 01:45:35 +01001181#include <__algorithm/ranges_find.h>
Nikolas Klauser0a7e46d2022-06-06 13:57:34 +02001182#include <__algorithm/ranges_find_first_of.h>
Nikolas Klauser37d076e2022-03-12 01:45:35 +01001183#include <__algorithm/ranges_find_if.h>
1184#include <__algorithm/ranges_find_if_not.h>
Nikolas Klauser58de98c2022-05-04 20:27:07 +02001185#include <__algorithm/ranges_for_each.h>
1186#include <__algorithm/ranges_for_each_n.h>
Nikolas Klauserbb9049d2022-05-04 14:19:09 +02001187#include <__algorithm/ranges_is_partitioned.h>
Nikolas Klauserab0b7af2022-05-26 16:08:55 +02001188#include <__algorithm/ranges_is_sorted.h>
1189#include <__algorithm/ranges_is_sorted_until.h>
Nikolas Klauser2fd677c2022-06-15 16:24:43 +02001190#include <__algorithm/ranges_lexicographical_compare.h>
Nikolas Klauser8b381972022-06-05 21:15:16 +02001191#include <__algorithm/ranges_lower_bound.h>
Nikolas Klauser573cd6f2022-04-03 09:17:01 +02001192#include <__algorithm/ranges_max.h>
Nikolas Klauserf2a69ea2022-03-07 17:01:52 +01001193#include <__algorithm/ranges_max_element.h>
Nikolas Klauser3559e452022-03-18 02:57:08 +01001194#include <__algorithm/ranges_min.h>
Nikolas Klauser0a62a172022-02-11 13:11:57 +01001195#include <__algorithm/ranges_min_element.h>
Nikolas Klauser0a2f44f2022-04-13 22:59:09 +02001196#include <__algorithm/ranges_minmax.h>
1197#include <__algorithm/ranges_minmax_element.h>
Nikolas Klauser12fc9bf2022-03-08 23:12:35 +01001198#include <__algorithm/ranges_mismatch.h>
Nikolas Klausered3f0e82022-05-26 16:42:46 +02001199#include <__algorithm/ranges_none_of.h>
Nikolas Klauserfadea392022-06-07 09:42:10 +02001200#include <__algorithm/ranges_replace.h>
1201#include <__algorithm/ranges_replace_if.h>
Nikolas Klauser52f20072022-05-24 10:32:50 +02001202#include <__algorithm/ranges_reverse.h>
Konstantin Varlamov55e39a82022-06-16 15:20:53 -07001203#include <__algorithm/ranges_sort.h>
Nikolas Klauser4ceab5f2022-02-10 13:33:03 +01001204#include <__algorithm/ranges_swap_ranges.h>
Nikolas Klauser559a1772022-04-05 11:05:36 +02001205#include <__algorithm/ranges_transform.h>
Nikolas Klauser8b381972022-06-05 21:15:16 +02001206#include <__algorithm/ranges_upper_bound.h>
Louis Dionnea60dd872021-06-17 11:30:11 -04001207#include <__algorithm/remove.h>
1208#include <__algorithm/remove_copy.h>
1209#include <__algorithm/remove_copy_if.h>
1210#include <__algorithm/remove_if.h>
1211#include <__algorithm/replace.h>
1212#include <__algorithm/replace_copy.h>
1213#include <__algorithm/replace_copy_if.h>
1214#include <__algorithm/replace_if.h>
1215#include <__algorithm/reverse.h>
1216#include <__algorithm/reverse_copy.h>
1217#include <__algorithm/rotate.h>
1218#include <__algorithm/rotate_copy.h>
1219#include <__algorithm/sample.h>
1220#include <__algorithm/search.h>
1221#include <__algorithm/search_n.h>
1222#include <__algorithm/set_difference.h>
1223#include <__algorithm/set_intersection.h>
1224#include <__algorithm/set_symmetric_difference.h>
1225#include <__algorithm/set_union.h>
1226#include <__algorithm/shift_left.h>
1227#include <__algorithm/shift_right.h>
1228#include <__algorithm/shuffle.h>
1229#include <__algorithm/sift_down.h>
1230#include <__algorithm/sort.h>
1231#include <__algorithm/sort_heap.h>
1232#include <__algorithm/stable_partition.h>
1233#include <__algorithm/stable_sort.h>
Christopher Di Bella41f26e82021-06-05 02:47:47 +00001234#include <__algorithm/swap_ranges.h>
Louis Dionnea60dd872021-06-17 11:30:11 -04001235#include <__algorithm/transform.h>
Louis Dionnea60dd872021-06-17 11:30:11 -04001236#include <__algorithm/unique.h>
Arthur O'Dwyer65077c02022-01-07 09:45:05 -05001237#include <__algorithm/unique_copy.h>
Louis Dionnea60dd872021-06-17 11:30:11 -04001238#include <__algorithm/unwrap_iter.h>
1239#include <__algorithm/upper_bound.h>
Eric Fiselier14b6de92014-08-10 23:53:08 +00001240
Howard Hinnantaaaa52b2011-10-17 20:05:10 +00001241#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Arthur O'Dwyer6eeaa002022-02-01 20:16:40 -05001242# pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +00001243#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001244
Louis Dionne59d0b3c2019-08-05 18:29:14 +00001245#if defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS) && _LIBCPP_STD_VER >= 17
Louis Dionned53d8c02019-08-06 21:11:24 +00001246# include <__pstl_algorithm>
Louis Dionne59d0b3c2019-08-05 18:29:14 +00001247#endif
1248
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001249#endif // _LIBCPP_ALGORITHM