1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// 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
7//
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
21namespace ranges {
22
23 // [algorithms.results], algorithm result types
24 template <class I, class F>
25 struct in_fun_result; // since C++20
26
27 template <class I1, class I2>
28 struct in_in_result; // since C++20
29
30 template <class I, class O>
31 struct in_out_result; // since C++20
32
33 template <class I1, class I2, class O>
34 struct in_in_out_result; // since C++20
35
36 template <class I, class O1, class O2>
37 struct in_out_out_result; // since C++20
38
39 template <class I1, class I2>
40 struct min_max_result; // since C++20
41
42 template <class I>
43 struct in_found_result; // since C++20
44
45 template <class I, class T>
46 struct in_value_result; // since C++23
47
48 template <class O, class T>
49 struct out_value_result; // since C++23
50
51 template<forward_iterator I, sentinel_for<I> S, class Proj = identity,
52 indirect_strict_weak_order<projected<I, Proj>> Comp = ranges::less> // since C++20
53 constexpr I min_element(I first, S last, Comp comp = {}, Proj proj = {});
54
55 template<forward_range R, class Proj = identity,
56 indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less> // since C++20
57 constexpr borrowed_iterator_t<R> min_element(R&& r, Comp comp = {}, Proj proj = {});
58
59 template<forward_iterator I, sentinel_for<I> S, class Proj = identity,
60 indirect_strict_weak_order<projected<I, Proj>> Comp = ranges::less>
61 constexpr I ranges::max_element(I first, S last, Comp comp = {}, Proj proj = {}); // since C++20
62
63 template<forward_range R, class Proj = identity,
64 indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less>
65 constexpr borrowed_iterator_t<R> ranges::max_element(R&& r, Comp comp = {}, Proj proj = {}); // since C++20
66
67 template<class I1, class I2>
68 using mismatch_result = in_in_result<I1, I2>;
69
70 template <input_iterator I1, sentinel_for<_I1> S1, input_iterator I2, sentinel_for<_I2> S2,
71 class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
72 requires indirectly_comparable<I1, I2, Pred, Proj1, Proj2>
73 constexpr mismatch_result<_I1, _I2> // since C++20
74 mismatch()(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {})
75
76 template <input_range R1, input_range R2,
77 class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
78 requires indirectly_comparable<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
79 constexpr mismatch_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>>
80 mismatch(R1&& r1, R2&& r2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}) // since C++20
81
82 requires indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T*>
83 constexpr I find(I first, S last, const T& value, Proj proj = {}); // since C++20
84
85 template<input_range R, class T, class Proj = identity>
86 requires indirect_binary_predicate<ranges::equal_to, projected<iterator_t<R>, Proj>, const T*>
87 constexpr borrowed_iterator_t<R>
88 find(R&& r, const T& value, Proj proj = {}); // since C++20
89
90 template<input_iterator I, sentinel_for<I> S, class Proj = identity,
91 indirect_unary_predicate<projected<I, Proj>> Pred>
92 constexpr I find_if(I first, S last, Pred pred, Proj proj = {}); // since C++20
93
94 template<input_range R, class Proj = identity,
95 indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
96 constexpr borrowed_iterator_t<R>
97 find_if(R&& r, Pred pred, Proj proj = {}); // since C++20
98
99 template<input_iterator I, sentinel_for<I> S, class Proj = identity,
100 indirect_unary_predicate<projected<I, Proj>> Pred>
101 constexpr I find_if_not(I first, S last, Pred pred, Proj proj = {}); // since C++20
102
103 template<input_range R, class Proj = identity,
104 indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
105 constexpr borrowed_iterator_t<R>
106 find_if_not(R&& r, Pred pred, Proj proj = {}); // since C++20
107
108 template<forward_iterator I, sentinel_for<I> S, class T, class Proj = identity>
109 requires indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T*>
110 constexpr subrange<I> find_last(I first, S last, const T& value, Proj proj = {}); // since C++23
111
112 template<forward_range R, class T, class Proj = identity>
113 requires
114 indirect_binary_predicate<ranges::equal_to, projected<iterator_t<R>, Proj>, const T*>
115 constexpr borrowed_subrange_t<R> find_last(R&& r, const T& value, Proj proj = {}); // since C++23
116
117 template<forward_iterator I, sentinel_for<I> S, class Proj = identity,
118 indirect_unary_predicate<projected<I, Proj>> Pred>
119 constexpr subrange<I> find_last_if(I first, S last, Pred pred, Proj proj = {}); // since C++23
120
121 template<forward_range R, class Proj = identity,
122 indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
123 constexpr borrowed_subrange_t<R> find_last_if(R&& r, Pred pred, Proj proj = {}); // since C++23
124
125 template<forward_iterator I, sentinel_for<I> S, class Proj = identity,
126 indirect_unary_predicate<projected<I, Proj>> Pred>
127 constexpr subrange<I> find_last_if_not(I first, S last, Pred pred, Proj proj = {}); // since C++23
128
129 template<forward_range R, class Proj = identity,
130 indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
131 constexpr borrowed_subrange_t<R> find_last_if_not(R&& r, Pred pred, Proj proj = {}); // since C++23
132
133 template<class T, class Proj = identity,
134 indirect_strict_weak_order<projected<const T*, Proj>> Comp = ranges::less>
135 constexpr const T& min(const T& a, const T& b, Comp comp = {}, Proj proj = {}); // since C++20
136
137 template<copyable T, class Proj = identity,
138 indirect_strict_weak_order<projected<const T*, Proj>> Comp = ranges::less>
139 constexpr T min(initializer_list<T> r, Comp comp = {}, Proj proj = {}); // since C++20
140
141 template<input_range R, class Proj = identity,
142 indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less>
143 requires indirectly_copyable_storable<iterator_t<R>, range_value_t<R>*>
144 constexpr range_value_t<R>
145 min(R&& r, Comp comp = {}, Proj proj = {}); // since C++20
146
147 template<class T, class Proj = identity,
148 indirect_strict_weak_order<projected<const T*, Proj>> Comp = ranges::less>
149 constexpr const T& max(const T& a, const T& b, Comp comp = {}, Proj proj = {}); // since C++20
150
151 template<copyable T, class Proj = identity,
152 indirect_strict_weak_order<projected<const T*, Proj>> Comp = ranges::less>
153 constexpr T max(initializer_list<T> r, Comp comp = {}, Proj proj = {}); // since C++20
154
155 template<input_range R, class Proj = identity,
156 indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less>
157 requires indirectly_copyable_storable<iterator_t<R>, range_value_t<R>*>
158 constexpr range_value_t<R>
159 max(R&& r, Comp comp = {}, Proj proj = {}); // since C++20
160
161 template<class I, class O>
162 using unary_transform_result = in_out_result<I, O>; // since C++20
163
164 template<class I1, class I2, class O>
165 using binary_transform_result = in_in_out_result<I1, I2, O>; // since C++20
166
167 template<input_iterator I, sentinel_for<I> S, weakly_incrementable O,
168 copy_constructible F, class Proj = identity>
169 requires indirectly_writable<O, indirect_result_t<F&, projected<I, Proj>>>
170 constexpr ranges::unary_transform_result<I, O>
171 transform(I first1, S last1, O result, F op, Proj proj = {}); // since C++20
172
173 template<input_range R, weakly_incrementable O, copy_constructible F,
174 class Proj = identity>
175 requires indirectly_writable<O, indirect_result_t<F&, projected<iterator_t<R>, Proj>>>
176 constexpr ranges::unary_transform_result<borrowed_iterator_t<R>, O>
177 transform(R&& r, O result, F op, Proj proj = {}); // since C++20
178
179 template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2,
180 weakly_incrementable O, copy_constructible F, class Proj1 = identity,
181 class Proj2 = identity>
182 requires indirectly_writable<O, indirect_result_t<F&, projected<I1, Proj1>,
183 projected<I2, Proj2>>>
184 constexpr ranges::binary_transform_result<I1, I2, O>
185 transform(I1 first1, S1 last1, I2 first2, S2 last2, O result,
186 F binary_op, Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
187
188 template<input_range R1, input_range R2, weakly_incrementable O,
189 copy_constructible F, class Proj1 = identity, class Proj2 = identity>
190 requires indirectly_writable<O, indirect_result_t<F&, projected<iterator_t<R1>, Proj1>,
191 projected<iterator_t<R2>, Proj2>>>
192 constexpr ranges::binary_transform_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>, O>
193 transform(R1&& r1, R2&& r2, O result,
194 F binary_op, Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
195
196 template<input_iterator I, sentinel_for<I> S, class T, class Proj = identity>
197 requires indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T*>
198 constexpr iter_difference_t<I>
199 count(I first, S last, const T& value, Proj proj = {}); // since C++20
200
201 template<input_range R, class T, class Proj = identity>
202 requires indirect_binary_predicate<ranges::equal_to, projected<iterator_t<R>, Proj>, const T*>
203 constexpr range_difference_t<R>
204 count(R&& r, const T& value, Proj proj = {}); // since C++20
205
206 template<input_iterator I, sentinel_for<I> S, class Proj = identity,
207 indirect_unary_predicate<projected<I, Proj>> Pred>
208 constexpr iter_difference_t<I>
209 count_if(I first, S last, Pred pred, Proj proj = {}); // since C++20
210
211 template<input_range R, class Proj = identity,
212 indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
213 constexpr range_difference_t<R>
214 count_if(R&& r, Pred pred, Proj proj = {}); // since C++20
215
216 template<class T>
217 using minmax_result = min_max_result<T>;
218
219 template<class T, class Proj = identity,
220 indirect_strict_weak_order<projected<const T*, Proj>> Comp = ranges::less>
221 constexpr ranges::minmax_result<const T&>
222 minmax(const T& a, const T& b, Comp comp = {}, Proj proj = {}); // since C++20
223
224 template<copyable T, class Proj = identity,
225 indirect_strict_weak_order<projected<const T*, Proj>> Comp = ranges::less>
226 constexpr ranges::minmax_result<T>
227 minmax(initializer_list<T> r, Comp comp = {}, Proj proj = {}); // since C++20
228
229 template<input_range R, class Proj = identity,
230 indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less>
231 requires indirectly_copyable_storable<iterator_t<R>, range_value_t<R>*>
232 constexpr ranges::minmax_result<range_value_t<R>>
233 minmax(R&& r, Comp comp = {}, Proj proj = {}); // since C++20
234
235 template<class I>
236 using minmax_element_result = min_max_result<I>;
237
238 template<forward_iterator I, sentinel_for<I> S, class Proj = identity,
239 indirect_strict_weak_order<projected<I, Proj>> Comp = ranges::less>
240 constexpr ranges::minmax_element_result<I>
241 minmax_element(I first, S last, Comp comp = {}, Proj proj = {}); // since C++20
242
243 template<forward_range R, class Proj = identity,
244 indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less>
245 constexpr ranges::minmax_element_result<borrowed_iterator_t<R>>
246 minmax_element(R&& r, Comp comp = {}, Proj proj = {}); // since C++20
247
248 template<forward_iterator I1, sentinel_for<I1> S1,
249 forward_iterator I2, sentinel_for<I2> S2,
250 class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
251 requires indirectly_comparable<I1, I2, Pred, Proj1, Proj2>
252 constexpr bool contains_subrange(I1 first1, S1 last1, I2 first2, S2 last2,
253 Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++23
254
255 template<forward_range R1, forward_range R2,
256 class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
257 requires indirectly_comparable<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
258 constexpr bool contains_subrange(R1&& r1, R2&& r2, Pred pred = {},
259 Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++23
260
261 template<class I, class O>
262 using copy_result = in_out_result<I, O>; // since C++20
263
264 template<class I, class O>
265 using copy_n_result = in_out_result<I, O>; // since C++20
266
267 template<class I, class O>
268 using copy_if_result = in_out_result<I, O>; // since C++20
269
270 template<class I1, class I2>
271 using copy_backward_result = in_out_result<I1, I2>; // since C++20
272
273 template<input_iterator I, sentinel_for<I> S, class T, class Proj = identity>
274 requires indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T*>
275 constexpr bool ranges::contains(I first, S last, const T& value, Proj proj = {}); // since C++23
276
277 template<input_range R, class T, class Proj = identity>
278 requires indirect_binary_predicate<ranges::equal_to, projected<iterator_t<R>, Proj>, const T*>
279 constexpr bool ranges::contains(R&& r, const T& value, Proj proj = {}); // since C++23
280
281 template<input_iterator I, sentinel_for<I> S, weakly_incrementable O>
282 requires indirectly_copyable<I, O>
283 constexpr ranges::copy_result<I, O> ranges::copy(I first, S last, O result); // since C++20
284
285 template<input_range R, weakly_incrementable O>
286 requires indirectly_copyable<iterator_t<R>, O>
287 constexpr ranges::copy_result<borrowed_iterator_t<R>, O> ranges::copy(R&& r, O result); // since C++20
288
289 template<input_iterator I, weakly_incrementable O>
290 requires indirectly_copyable<I, O>
291 constexpr ranges::copy_n_result<I, O>
292 ranges::copy_n(I first, iter_difference_t<I> n, O result); // since C++20
293
294 template<input_iterator I, sentinel_for<I> S, weakly_incrementable O, class Proj = identity,
295 indirect_unary_predicate<projected<I, Proj>> Pred>
296 requires indirectly_copyable<I, O>
297 constexpr ranges::copy_if_result<I, O>
298 ranges::copy_if(I first, S last, O result, Pred pred, Proj proj = {}); // since C++20
299
300 template<input_range R, weakly_incrementable O, class Proj = identity,
301 indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
302 requires indirectly_copyable<iterator_t<R>, O>
303 constexpr ranges::copy_if_result<borrowed_iterator_t<R>, O>
304 ranges::copy_if(R&& r, O result, Pred pred, Proj proj = {}); // since C++20
305
306 template<bidirectional_iterator I1, sentinel_for<I1> S1, bidirectional_iterator I2>
307 requires indirectly_copyable<I1, I2>
308 constexpr ranges::copy_backward_result<I1, I2>
309 ranges::copy_backward(I1 first, S1 last, I2 result); // since C++20
310
311 template<bidirectional_range R, bidirectional_iterator I>
312 requires indirectly_copyable<iterator_t<R>, I>
313 constexpr ranges::copy_backward_result<borrowed_iterator_t<R>, I>
314 ranges::copy_backward(R&& r, I result); // since C++20
315
316 template<class I, class F>
317 using for_each_result = in_fun_result<I, F>; // since C++20
318
319 template<class I, class F>
320 using for_each_n_result = in_fun_result<I, F>; // since C++20
321
322 template<input_iterator I, sentinel_for<I> S, class Proj = identity,
323 indirectly_unary_invocable<projected<I, Proj>> Fun>
324 constexpr ranges::for_each_result<I, Fun>
325 ranges::for_each(I first, S last, Fun f, Proj proj = {}); // since C++20
326
327 template<input_range R, class Proj = identity,
328 indirectly_unary_invocable<projected<iterator_t<R>, Proj>> Fun>
329 constexpr ranges::for_each_result<borrowed_iterator_t<R>, Fun>
330 ranges::for_each(R&& r, Fun f, Proj proj = {}); // since C++20
331
332 template<input_iterator I, class Proj = identity,
333 indirectly_unary_invocable<projected<I, Proj>> Fun>
334 constexpr ranges::for_each_n_result<I, Fun>
335 ranges::for_each_n(I first, iter_difference_t<I> n, Fun f, Proj proj = {}); // since C++20
336
337 template<input_iterator I, sentinel_for<I> S, class Proj = identity,
338 indirect_unary_predicate<projected<I, Proj>> Pred>
339 constexpr bool ranges::is_partitioned(I first, S last, Pred pred, Proj proj = {}); // since C++20
340
341 template<input_range R, class Proj = identity,
342 indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
343 constexpr bool ranges::is_partitioned(R&& r, Pred pred, Proj proj = {}); // since C++20
344
345 template<random_access_iterator I, sentinel_for<I> S, class Comp = ranges::less,
346 class Proj = identity>
347 requires sortable<I, Comp, Proj>
348 constexpr I
349 ranges::push_heap(I first, S last, Comp comp = {}, Proj proj = {}); // since C++20
350
351 template<random_access_range R, class Comp = ranges::less, class Proj = identity>
352 requires sortable<iterator_t<R>, Comp, Proj>
353 constexpr borrowed_iterator_t<R>
354 ranges::push_heap(R&& r, Comp comp = {}, Proj proj = {}); // since C++20
355
356 template<random_access_iterator I, sentinel_for<I> S, class Comp = ranges::less,
357 class Proj = identity>
358 requires sortable<I, Comp, Proj>
359 constexpr I
360 ranges::pop_heap(I first, S last, Comp comp = {}, Proj proj = {}); // since C++20
361
362 template<random_access_range R, class Comp = ranges::less, class Proj = identity>
363 requires sortable<iterator_t<R>, Comp, Proj>
364 constexpr borrowed_iterator_t<R>
365 ranges::pop_heap(R&& r, Comp comp = {}, Proj proj = {}); // since C++20
366
367 template<random_access_iterator I, sentinel_for<I> S, class Comp = ranges::less,
368 class Proj = identity>
369 requires sortable<I, Comp, Proj>
370 constexpr I
371 ranges::make_heap(I first, S last, Comp comp = {}, Proj proj = {}); // since C++20
372
373 template<random_access_range R, class Comp = ranges::less, class Proj = identity>
374 requires sortable<iterator_t<R>, Comp, Proj>
375 constexpr borrowed_iterator_t<R>
376 ranges::make_heap(R&& r, Comp comp = {}, Proj proj = {}); // since C++20
377
378 template<random_access_iterator I, sentinel_for<I> S, class Comp = ranges::less,
379 class Proj = identity>
380 requires sortable<I, Comp, Proj>
381 constexpr I
382 ranges::sort_heap(I first, S last, Comp comp = {}, Proj proj = {}); // since C++20
383
384 template<random_access_range R, class Comp = ranges::less, class Proj = identity>
385 requires sortable<iterator_t<R>, Comp, Proj>
386 constexpr borrowed_iterator_t<R>
387 ranges::sort_heap(R&& r, Comp comp = {}, Proj proj = {}); // since C++20
388
389 template<random_access_iterator I, sentinel_for<I> S, class Proj = identity,
390 indirect_strict_weak_order<projected<I, Proj>> Comp = ranges::less>
391 constexpr bool is_heap(I first, S last, Comp comp = {}, Proj proj = {}); // since C++20
392
393 template<random_access_range R, class Proj = identity,
394 indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less>
395 constexpr bool is_heap(R&& r, Comp comp = {}, Proj proj = {}); // since C++20
396
397 template<random_access_iterator I, sentinel_for<I> S, class Proj = identity,
398 indirect_strict_weak_order<projected<I, Proj>> Comp = ranges::less>
399 constexpr I is_heap_until(I first, S last, Comp comp = {}, Proj proj = {}); // since C++20
400
401 template<random_access_range R, class Proj = identity,
402 indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less>
403 constexpr borrowed_iterator_t<R>
404 is_heap_until(R&& r, Comp comp = {}, Proj proj = {}); // since C++20
405
406 template<bidirectional_iterator I, sentinel_for<I> S>
407 requires permutable<I>
408 constexpr I ranges::reverse(I first, S last); // since C++20
409
410 template<bidirectional_range R>
411 requires permutable<iterator_t<R>>
412 constexpr borrowed_iterator_t<R> ranges::reverse(R&& r); // since C++20
413
414 template<random_access_iterator I, sentinel_for<I> S, class Comp = ranges::less,
415 class Proj = identity>
416 requires sortable<I, Comp, Proj>
417 constexpr I
418 ranges::sort(I first, S last, Comp comp = {}, Proj proj = {}); // since C++20
419
420 template<random_access_range R, class Comp = ranges::less, class Proj = identity>
421 requires sortable<iterator_t<R>, Comp, Proj>
422 constexpr borrowed_iterator_t<R>
423 ranges::sort(R&& r, Comp comp = {}, Proj proj = {}); // since C++20
424
425 template<random_access_iterator I, sentinel_for<I> S, class Comp = ranges::less,
426 class Proj = identity>
427 requires sortable<I, Comp, Proj>
428 constexpr I // constexpr since C++26
429 ranges::stable_sort(I first, S last, Comp comp = {}, Proj proj = {}); // since C++20
430
431 template<random_access_range R, class Comp = ranges::less, class Proj = identity>
432 requires sortable<iterator_t<R>, Comp, Proj>
433 constexpr borrowed_iterator_t<R> // constexpr since C++26
434 ranges::stable_sort(R&& r, Comp comp = {}, Proj proj = {}); // since C++20
435
436 template<random_access_iterator I, sentinel_for<I> S, class Comp = ranges::less,
437 class Proj = identity>
438 requires sortable<I, Comp, Proj>
439 constexpr I
440 ranges::partial_sort(I first, I middle, S last, Comp comp = {}, Proj proj = {}); // since C++20
441
442 template<random_access_range R, class Comp = ranges::less, class Proj = identity>
443 requires sortable<iterator_t<R>, Comp, Proj>
444 constexpr borrowed_iterator_t<R>
445 ranges::partial_sort(R&& r, iterator_t<R> middle, Comp comp = {}, Proj proj = {}); // since C++20
446
447 template<class T, output_iterator<const T&> O, sentinel_for<O> S>
448 constexpr O ranges::fill(O first, S last, const T& value); // since C++20
449
450 template<class T, output_range<const T&> R>
451 constexpr borrowed_iterator_t<R> ranges::fill(R&& r, const T& value); // since C++20
452
453 template<class T, output_iterator<const T&> O>
454 constexpr O ranges::fill_n(O first, iter_difference_t<O> n, const T& value); // since C++20
455
456 template<input_or_output_iterator O, sentinel_for<O> S, copy_constructible F>
457 requires invocable<F&> && indirectly_writable<O, invoke_result_t<F&>>
458 constexpr O generate(O first, S last, F gen); // since C++20
459
460 template<class ExecutionPolicy, class ForwardIterator, class Generator>
461 void generate(ExecutionPolicy&& exec,
462 ForwardIterator first, ForwardIterator last,
463 Generator gen); // since C++17
464
465 template<class R, copy_constructible F>
466 requires invocable<F&> && output_range<R, invoke_result_t<F&>>
467 constexpr borrowed_iterator_t<R> generate(R&& r, F gen); // since C++20
468
469 template<input_or_output_iterator O, copy_constructible F>
470 requires invocable<F&> && indirectly_writable<O, invoke_result_t<F&>>
471 constexpr O generate_n(O first, iter_difference_t<O> n, F gen); // since C++20
472
473 template<class ExecutionPolicy, class ForwardIterator, class Size, class Generator>
474 ForwardIterator generate_n(ExecutionPolicy&& exec,
475 ForwardIterator first, Size n, Generator gen); // since C++17
476
477 template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2,
478 class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
479 requires indirectly_comparable<I1, I2, Pred, Proj1, Proj2>
480 constexpr bool ranges::equal(I1 first1, S1 last1, I2 first2, S2 last2,
481 Pred pred = {},
482 Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
483
484 template<input_range R1, input_range R2, class Pred = ranges::equal_to,
485 class Proj1 = identity, class Proj2 = identity>
486 requires indirectly_comparable<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
487 constexpr bool ranges::equal(R1&& r1, R2&& r2, Pred pred = {},
488 Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
489
490 template<input_iterator I, sentinel_for<I> S, class Proj = identity,
491 indirect_unary_predicate<projected<I, Proj>> Pred>
492 constexpr bool ranges::all_of(I first, S last, Pred pred, Proj proj = {}); // since C++20
493
494 template<input_range R, class Proj = identity,
495 indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
496 constexpr bool ranges::all_of(R&& r, Pred pred, Proj proj = {}); // since C++20
497
498 template<input_iterator I, sentinel_for<I> S, class Proj = identity,
499 indirect_unary_predicate<projected<I, Proj>> Pred>
500 constexpr bool ranges::any_of(I first, S last, Pred pred, Proj proj = {}); // since C++20
501
502 template<input_range R, class Proj = identity,
503 indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
504 constexpr bool ranges::any_of(R&& r, Pred pred, Proj proj = {}); // since C++20
505
506 template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2,
507 class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
508 requires (forward_iterator<I1> || sized_sentinel_for<S1, I1>) &&
509 (forward_iterator<I2> || sized_sentinel_for<S2, I2>) &&
510 indirectly_comparable<I1, I2, Pred, Proj1, Proj2>
511 constexpr bool ranges::ends_with(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {},
512 Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++23
513
514 template<input_range R1, input_range R2, class Pred = ranges::equal_to, class Proj1 = identity,
515 class Proj2 = identity>
516 requires (forward_range<R1> || sized_range<R1>) &&
517 (forward_range<R2> || sized_range<R2>) &&
518 indirectly_comparable<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
519 constexpr bool ranges::ends_with(R1&& r1, R2&& r2, Pred pred = {},
520 Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++23
521
522 template<input_iterator I, sentinel_for<I> S, class Proj = identity,
523 indirect_unary_predicate<projected<I, Proj>> Pred>
524 constexpr bool ranges::none_of(I first, S last, Pred pred, Proj proj = {}); // since C++20
525
526 template<input_range R, class Proj = identity,
527 indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
528 constexpr bool ranges::none_of(R&& r, Pred pred, Proj proj = {}); // since C++20
529
530 template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2,
531 class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
532 requires indirectly_comparable<I1, I2, Pred, Proj1, Proj2>
533 constexpr bool ranges::starts_with(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {},
534 Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++23
535
536 template<input_range R1, input_range R2, class Pred = ranges::equal_to, class Proj1 = identity,
537 class Proj2 = identity>
538 requires indirectly_comparable<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
539 constexpr bool ranges::starts_with(R1&& r1, R2&& r2, Pred pred = {},
540 Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++23
541
542 template<input_iterator I1, sentinel_for<I1> S1,
543 random_access_iterator I2, sentinel_for<I2> S2,
544 class Comp = ranges::less, class Proj1 = identity, class Proj2 = identity>
545 requires indirectly_copyable<I1, I2> && sortable<I2, Comp, Proj2> &&
546 indirect_strict_weak_order<Comp, projected<I1, Proj1>, projected<I2, Proj2>>
547 constexpr partial_sort_copy_result<I1, I2>
548 partial_sort_copy(I1 first, S1 last, I2 result_first, S2 result_last,
549 Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
550
551 template<input_range R1, random_access_range R2, class Comp = ranges::less,
552 class Proj1 = identity, class Proj2 = identity>
553 requires indirectly_copyable<iterator_t<R1>, iterator_t<R2>> &&
554 sortable<iterator_t<R2>, Comp, Proj2> &&
555 indirect_strict_weak_order<Comp, projected<iterator_t<R1>, Proj1>,
556 projected<iterator_t<R2>, Proj2>>
557 constexpr partial_sort_copy_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>>
558 partial_sort_copy(R1&& r, R2&& result_r, Comp comp = {},
559 Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
560
561 template<forward_iterator I, sentinel_for<I> S, class Proj = identity,
562 indirect_strict_weak_order<projected<I, Proj>> Comp = ranges::less>
563 constexpr bool ranges::is_sorted(I first, S last, Comp comp = {}, Proj proj = {}); // since C++20
564
565 template<forward_range R, class Proj = identity,
566 indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less>
567 constexpr bool ranges::is_sorted(R&& r, Comp comp = {}, Proj proj = {}); // since C++20
568
569 template<forward_iterator I, sentinel_for<I> S, class Proj = identity,
570 indirect_strict_weak_order<projected<I, Proj>> Comp = ranges::less>
571 constexpr I ranges::is_sorted_until(I first, S last, Comp comp = {}, Proj proj = {}); // since C++20
572
573 template<forward_range R, class Proj = identity,
574 indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less>
575 constexpr borrowed_iterator_t<R>
576 ranges::is_sorted_until(R&& r, Comp comp = {}, Proj proj = {}); // since C++20
577
578 template<random_access_iterator I, sentinel_for<I> S, class Comp = ranges::less,
579 class Proj = identity>
580 requires sortable<I, Comp, Proj>
581 constexpr I
582 ranges::nth_element(I first, I nth, S last, Comp comp = {}, Proj proj = {}); // since C++20
583
584 template<random_access_range R, class Comp = ranges::less, class Proj = identity>
585 requires sortable<iterator_t<R>, Comp, Proj>
586 constexpr borrowed_iterator_t<R>
587 ranges::nth_element(R&& r, iterator_t<R> nth, Comp comp = {}, Proj proj = {}); // since C++20
588
589 template<forward_iterator I, sentinel_for<I> S, class T, class Proj = identity,
590 indirect_strict_weak_order<const T*, projected<I, Proj>> Comp = ranges::less> // since C++20
591 constexpr I upper_bound(I first, S last, const T& value, Comp comp = {}, Proj proj = {});
592
593 template<forward_range R, class T, class Proj = identity,
594 indirect_strict_weak_order<const T*, projected<iterator_t<R>, Proj>> Comp =
595 ranges::less>
596 constexpr borrowed_iterator_t<R>
597 upper_bound(R&& r, const T& value, Comp comp = {}, Proj proj = {}); // since C++20
598
599 template<forward_iterator I, sentinel_for<I> S, class T, class Proj = identity,
600 indirect_strict_weak_order<const T*, projected<I, Proj>> Comp = ranges::less>
601 constexpr I lower_bound(I first, S last, const T& value, Comp comp = {},
602 Proj proj = {}); // since C++20
603 template<forward_range R, class T, class Proj = identity,
604 indirect_strict_weak_order<const T*, projected<iterator_t<R>, Proj>> Comp =
605 ranges::less>
606 constexpr borrowed_iterator_t<R>
607 lower_bound(R&& r, const T& value, Comp comp = {}, Proj proj = {}); // since C++20
608
609 template<forward_iterator I, sentinel_for<I> S, class T, class Proj = identity,
610 indirect_strict_weak_order<const T*, projected<I, Proj>> Comp = ranges::less>
611 constexpr bool binary_search(I first, S last, const T& value, Comp comp = {},
612 Proj proj = {}); // since C++20
613
614 template<forward_range R, class T, class Proj = identity,
615 indirect_strict_weak_order<const T*, projected<iterator_t<R>, Proj>> Comp =
616 ranges::less>
617 constexpr bool binary_search(R&& r, const T& value, Comp comp = {},
618 Proj proj = {}); // since C++20
619
620 template<permutable I, sentinel_for<I> S, class Proj = identity,
621 indirect_unary_predicate<projected<I, Proj>> Pred>
622 constexpr subrange<I>
623 partition(I first, S last, Pred pred, Proj proj = {}); // since C++20
624
625 template<forward_range R, class Proj = identity,
626 indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
627 requires permutable<iterator_t<R>>
628 constexpr borrowed_subrange_t<R>
629 partition(R&& r, Pred pred, Proj proj = {}); // since C++20
630
631 template<bidirectional_iterator I, sentinel_for<I> S, class Proj = identity,
632 indirect_unary_predicate<projected<I, Proj>> Pred>
633 requires permutable<I>
634 constexpr subrange<I> // constexpr since C++26
635 stable_partition(I first, S last, Pred pred, Proj proj = {}); // since C++20
636
637 template<bidirectional_range R, class Proj = identity,
638 indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
639 requires permutable<iterator_t<R>>
640 constexpr borrowed_subrange_t<R> // constexpr since C++26
641 stable_partition(R&& r, Pred pred, Proj proj = {}); // since C++20
642
643 template<input_iterator I1, sentinel_for<I1> S1, forward_iterator I2, sentinel_for<I2> S2,
644 class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
645 requires indirectly_comparable<I1, I2, Pred, Proj1, Proj2>
646 constexpr I1 ranges::find_first_of(I1 first1, S1 last1, I2 first2, S2 last2,
647 Pred pred = {},
648 Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
649
650 template<input_range R1, forward_range R2,
651 class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
652 requires indirectly_comparable<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
653 constexpr borrowed_iterator_t<R1>
654 ranges::find_first_of(R1&& r1, R2&& r2,
655 Pred pred = {},
656 Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
657
658 template<forward_iterator I, sentinel_for<I> S, class Proj = identity,
659 indirect_binary_predicate<projected<I, Proj>,
660 projected<I, Proj>> Pred = ranges::equal_to>
661 constexpr I ranges::adjacent_find(I first, S last, Pred pred = {}, Proj proj = {}); // since C++20
662
663 template<forward_range R, class Proj = identity,
664 indirect_binary_predicate<projected<iterator_t<R>, Proj>,
665 projected<iterator_t<R>, Proj>> Pred = ranges::equal_to>
666 constexpr borrowed_iterator_t<R> ranges::adjacent_find(R&& r, Pred pred = {}, Proj proj = {}); // since C++20
667
668 template<input_iterator I, sentinel_for<I> S, class T1, class T2, class Proj = identity>
669 requires indirectly_writable<I, const T2&> &&
670 indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T1*>
671 constexpr I
672 ranges::replace(I first, S last, const T1& old_value, const T2& new_value, Proj proj = {}); // since C++20
673
674 template<input_range R, class T1, class T2, class Proj = identity>
675 requires indirectly_writable<iterator_t<R>, const T2&> &&
676 indirect_binary_predicate<ranges::equal_to, projected<iterator_t<R>, Proj>, const T1*>
677 constexpr borrowed_iterator_t<R>
678 ranges::replace(R&& r, const T1& old_value, const T2& new_value, Proj proj = {}); // since C++20
679
680 template<input_iterator I, sentinel_for<I> S, class T, class Proj = identity,
681 indirect_unary_predicate<projected<I, Proj>> Pred>
682 requires indirectly_writable<I, const T&>
683 constexpr I ranges::replace_if(I first, S last, Pred pred, const T& new_value, Proj proj = {}); // since C++20
684
685 template<input_range R, class T, class Proj = identity,
686 indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
687 requires indirectly_writable<iterator_t<R>, const T&>
688 constexpr borrowed_iterator_t<R>
689 ranges::replace_if(R&& r, Pred pred, const T& new_value, Proj proj = {}); // since C++20
690
691 template<class T, class Proj = identity,
692 indirect_strict_weak_order<projected<const T*, Proj>> Comp = ranges::less>
693 constexpr const T&
694 ranges::clamp(const T& v, const T& lo, const T& hi, Comp comp = {}, Proj proj = {}); // since C++20
695
696 template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2,
697 class Proj1 = identity, class Proj2 = identity,
698 indirect_strict_weak_order<projected<I1, Proj1>,
699 projected<I2, Proj2>> Comp = ranges::less>
700 constexpr bool
701 ranges::lexicographical_compare(I1 first1, S1 last1, I2 first2, S2 last2,
702 Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
703
704 template<input_range R1, input_range R2, class Proj1 = identity,
705 class Proj2 = identity,
706 indirect_strict_weak_order<projected<iterator_t<R1>, Proj1>,
707 projected<iterator_t<R2>, Proj2>> Comp = ranges::less>
708 constexpr bool
709 ranges::lexicographical_compare(R1&& r1, R2&& r2, Comp comp = {},
710 Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
711
712 template<class I, class O>
713 using move_result = in_out_result<I, O>; // since C++20
714
715 template<class I, class O>
716 using move_backward_result = in_out_result<I, O>; // since C++20
717
718 template<bidirectional_iterator I1, sentinel_for<I1> S1, bidirectional_iterator I2>
719 requires indirectly_movable<I1, I2>
720 constexpr ranges::move_backward_result<I1, I2>
721 ranges::move_backward(I1 first, S1 last, I2 result); // since C++20
722
723 template<bidirectional_range R, bidirectional_iterator I>
724 requires indirectly_movable<iterator_t<R>, I>
725 constexpr ranges::move_backward_result<borrowed_iterator_t<R>, I>
726 ranges::move_backward(R&& r, I result); // since C++20
727
728 template<input_iterator I, sentinel_for<I> S, weakly_incrementable O>
729 requires indirectly_movable<I, O>
730 constexpr ranges::move_result<I, O>
731 ranges::move(I first, S last, O result); // since C++20
732
733 template<input_range R, weakly_incrementable O>
734 requires indirectly_movable<iterator_t<R>, O>
735 constexpr ranges::move_result<borrowed_iterator_t<R>, O>
736 ranges::move(R&& r, O result); // since C++20
737
738 template<class I, class O1, class O2>
739 using partition_copy_result = in_out_out_result<I, O1, O2>; // since C++20
740
741 template<input_iterator I, sentinel_for<I> S,
742 weakly_incrementable O1, weakly_incrementable O2,
743 class Proj = identity, indirect_unary_predicate<projected<I, Proj>> Pred>
744 requires indirectly_copyable<I, O1> && indirectly_copyable<I, O2>
745 constexpr partition_copy_result<I, O1, O2>
746 partition_copy(I first, S last, O1 out_true, O2 out_false, Pred pred,
747 Proj proj = {}); // since C++20
748
749 template<input_range R, weakly_incrementable O1, weakly_incrementable O2,
750 class Proj = identity,
751 indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
752 requires indirectly_copyable<iterator_t<R>, O1> &&
753 indirectly_copyable<iterator_t<R>, O2>
754 constexpr partition_copy_result<borrowed_iterator_t<R>, O1, O2>
755 partition_copy(R&& r, O1 out_true, O2 out_false, Pred pred, Proj proj = {}); // since C++20
756
757 template<forward_iterator I, sentinel_for<I> S, class Proj = identity,
758 indirect_unary_predicate<projected<I, Proj>> Pred>
759 constexpr I partition_point(I first, S last, Pred pred, Proj proj = {}); // since C++20
760
761 template<forward_range R, class Proj = identity,
762 indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
763 constexpr borrowed_iterator_t<R>
764 partition_point(R&& r, Pred pred, Proj proj = {}); // since C++20
765
766 template<class I1, class I2, class O>
767 using merge_result = in_in_out_result<I1, I2, O>; // since C++20
768
769 template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2,
770 weakly_incrementable O, class Comp = ranges::less, class Proj1 = identity,
771 class Proj2 = identity>
772 requires mergeable<I1, I2, O, Comp, Proj1, Proj2>
773 constexpr merge_result<I1, I2, O>
774 merge(I1 first1, S1 last1, I2 first2, S2 last2, O result,
775 Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
776
777 template<input_range R1, input_range R2, weakly_incrementable O, class Comp = ranges::less,
778 class Proj1 = identity, class Proj2 = identity>
779 requires mergeable<iterator_t<R1>, iterator_t<R2>, O, Comp, Proj1, Proj2>
780 constexpr merge_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>, O>
781 merge(R1&& r1, R2&& r2, O result,
782 Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
783
784 template<permutable I, sentinel_for<I> S, class T, class Proj = identity>
785 requires indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T*>
786 constexpr subrange<I> ranges::remove(I first, S last, const T& value, Proj proj = {}); // since C++20
787
788 template<forward_range R, class T, class Proj = identity>
789 requires permutable<iterator_t<R>> &&
790 indirect_binary_predicate<ranges::equal_to, projected<iterator_t<R>, Proj>, const T*>
791 constexpr borrowed_subrange_t<R>
792 ranges::remove(R&& r, const T& value, Proj proj = {}); // since C++20
793
794 template<permutable I, sentinel_for<I> S, class Proj = identity,
795 indirect_unary_predicate<projected<I, Proj>> Pred>
796 constexpr subrange<I> ranges::remove_if(I first, S last, Pred pred, Proj proj = {}); // since C++20
797
798 template<forward_range R, class Proj = identity,
799 indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
800 requires permutable<iterator_t<R>>
801 constexpr borrowed_subrange_t<R>
802 ranges::remove_if(R&& r, Pred pred, Proj proj = {}); // since C++20
803
804 template<class I, class O>
805 using set_difference_result = in_out_result<I, O>; // since C++20
806
807 template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2,
808 weakly_incrementable O, class Comp = ranges::less,
809 class Proj1 = identity, class Proj2 = identity>
810 requires mergeable<I1, I2, O, Comp, Proj1, Proj2>
811 constexpr set_difference_result<I1, O>
812 set_difference(I1 first1, S1 last1, I2 first2, S2 last2, O result,
813 Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
814
815 template<input_range R1, input_range R2, weakly_incrementable O,
816 class Comp = ranges::less, class Proj1 = identity, class Proj2 = identity>
817 requires mergeable<iterator_t<R1>, iterator_t<R2>, O, Comp, Proj1, Proj2>
818 constexpr set_difference_result<borrowed_iterator_t<R1>, O>
819 set_difference(R1&& r1, R2&& r2, O result,
820 Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
821
822 template<class I1, class I2, class O>
823 using set_intersection_result = in_in_out_result<I1, I2, O>; // since C++20
824
825 template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2,
826 weakly_incrementable O, class Comp = ranges::less,
827 class Proj1 = identity, class Proj2 = identity>
828 requires mergeable<I1, I2, O, Comp, Proj1, Proj2>
829 constexpr set_intersection_result<I1, I2, O>
830 set_intersection(I1 first1, S1 last1, I2 first2, S2 last2, O result,
831 Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
832
833 template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2,
834 weakly_incrementable O, class Comp = ranges::less,
835 class Proj1 = identity, class Proj2 = identity>
836 requires mergeable<I1, I2, O, Comp, Proj1, Proj2>
837 constexpr set_intersection_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>, O>
838 set_intersection(R1&& r1, R2&& r2, O result,
839 Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
840
841 template <class _InIter, class _OutIter>
842 using reverse_copy_result = in_out_result<_InIter, _OutIter>; // since C++20
843
844 template<bidirectional_iterator I, sentinel_for<I> S, weakly_incrementable O>
845 requires indirectly_copyable<I, O>
846 constexpr ranges::reverse_copy_result<I, O>
847 ranges::reverse_copy(I first, S last, O result); // since C++20
848
849 template<bidirectional_range R, weakly_incrementable O>
850 requires indirectly_copyable<iterator_t<R>, O>
851 constexpr ranges::reverse_copy_result<borrowed_iterator_t<R>, O>
852 ranges::reverse_copy(R&& r, O result); // since C++20
853
854 template<permutable I, sentinel_for<I> S>
855 constexpr subrange<I> rotate(I first, I middle, S last); // since C++20
856
857 template<forward_range R>
858 requires permutable<iterator_t<R>>
859 constexpr borrowed_subrange_t<R> rotate(R&& r, iterator_t<R> middle); // since C++20
860
861 template <class _InIter, class _OutIter>
862 using rotate_copy_result = in_out_result<_InIter, _OutIter>; // since C++20
863
864 template<forward_iterator I, sentinel_for<I> S, weakly_incrementable O>
865 requires indirectly_copyable<I, O>
866 constexpr ranges::rotate_copy_result<I, O>
867 ranges::rotate_copy(I first, I middle, S last, O result); // since C++20
868
869 template<forward_range R, weakly_incrementable O>
870 requires indirectly_copyable<iterator_t<R>, O>
871 constexpr ranges::rotate_copy_result<borrowed_iterator_t<R>, O>
872 ranges::rotate_copy(R&& r, iterator_t<R> middle, O result); // since C++20
873
874 template<input_iterator I, sentinel_for<I> S, weakly_incrementable O, class Gen>
875 requires (forward_iterator<I> || random_access_iterator<O>) &&
876 indirectly_copyable<I, O> &&
877 uniform_random_bit_generator<remove_reference_t<Gen>>
878 O sample(I first, S last, O out, iter_difference_t<I> n, Gen&& g); // since C++20
879
880 template<input_range R, weakly_incrementable O, class Gen>
881 requires (forward_range<R> || random_access_iterator<O>) &&
882 indirectly_copyable<iterator_t<R>, O> &&
883 uniform_random_bit_generator<remove_reference_t<Gen>>
884 O sample(R&& r, O out, range_difference_t<R> n, Gen&& g); // since C++20
885
886 template<permutable I, sentinel_for<I> S>
887 constexpr subrange<I> ranges::shift_left(I first, S last, iter_difference_t<I> n); // since C++23
888
889 template<forward_range R>
890 requires permutable<iterator_t<R>>
891 constexpr borrowed_subrange_t<R> ranges::shift_left(R&& r, range_difference_t<R> n) // since C++23
892
893 template<random_access_iterator I, sentinel_for<I> S, class Gen>
894 requires permutable<I> &&
895 uniform_random_bit_generator<remove_reference_t<Gen>>
896 I shuffle(I first, S last, Gen&& g); // since C++20
897
898 template<random_access_range R, class Gen>
899 requires permutable<iterator_t<R>> &&
900 uniform_random_bit_generator<remove_reference_t<Gen>>
901 borrowed_iterator_t<R> shuffle(R&& r, Gen&& g); // since C++20
902
903 template<forward_iterator I1, sentinel_for<I1> S1, forward_iterator I2,
904 sentinel_for<I2> S2, class Proj1 = identity, class Proj2 = identity,
905 indirect_equivalence_relation<projected<I1, Proj1>,
906 projected<I2, Proj2>> Pred = ranges::equal_to>
907 constexpr bool ranges::is_permutation(I1 first1, S1 last1, I2 first2, S2 last2,
908 Pred pred = {},
909 Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
910
911 template<forward_range R1, forward_range R2,
912 class Proj1 = identity, class Proj2 = identity,
913 indirect_equivalence_relation<projected<iterator_t<R1>, Proj1>,
914 projected<iterator_t<R2>, Proj2>> Pred = ranges::equal_to>
915 constexpr bool ranges::is_permutation(R1&& r1, R2&& r2, Pred pred = {},
916 Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
917
918 template<forward_iterator I1, sentinel_for<I1> S1, forward_iterator I2,
919 sentinel_for<I2> S2, class Pred = ranges::equal_to,
920 class Proj1 = identity, class Proj2 = identity>
921 requires indirectly_comparable<I1, I2, Pred, Proj1, Proj2>
922 constexpr subrange<I1>
923 ranges::search(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {},
924 Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
925
926 template<forward_range R1, forward_range R2, class Pred = ranges::equal_to,
927 class Proj1 = identity, class Proj2 = identity>
928 requires indirectly_comparable<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
929 constexpr borrowed_subrange_t<R1>
930 ranges::search(R1&& r1, R2&& r2, Pred pred = {},
931 Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
932
933 template<forward_iterator I, sentinel_for<I> S, class T,
934 class Pred = ranges::equal_to, class Proj = identity>
935 requires indirectly_comparable<I, const T*, Pred, Proj>
936 constexpr subrange<I>
937 ranges::search_n(I first, S last, iter_difference_t<I> count,
938 const T& value, Pred pred = {}, Proj proj = {}); // since C++20
939
940 template<forward_range R, class T, class Pred = ranges::equal_to,
941 class Proj = identity>
942 requires indirectly_comparable<iterator_t<R>, const T*, Pred, Proj>
943 constexpr borrowed_subrange_t<R>
944 ranges::search_n(R&& r, range_difference_t<R> count,
945 const T& value, Pred pred = {}, Proj proj = {}); // since C++20
946
947 template<input_iterator I, sentinel_for<I> S, class T,
948 indirectly-binary-left-foldable<T, I> F>
949 constexpr auto ranges::fold_left(I first, S last, T init, F f); // since C++23
950
951 template<input_range R, class T, indirectly-binary-left-foldable<T, iterator_t<R>> F>
952 constexpr auto fold_left(R&& r, T init, F f); // since C++23
953
954 template<input_iterator I, sentinel_for<I> S,
955 indirectly-binary-left-foldable<iter_value_t<I>, I> F>
956 requires constructible_from<iter_value_t<I>, iter_reference_t<I>>
957 constexpr auto ranges::fold_left_first(I first, S last, F f); // since C++23
958
959 template<input_range R, indirectly-binary-left-foldable<range_value_t<R>, iterator_t<R>> F>
960 requires constructible_from<range_value_t<R>, range_reference_t<R>>
961 constexpr auto ranges::fold_left_first(R&& r, F f); // since C++23
962
963 template<bidirectional_iterator I, sentinel_for<I> S, class T = iter_value_t<I>,
964 indirectly-binary-right-foldable<T, I> F>
965 constexpr auto ranges::fold_right(I first, S last, T init, F f); // since C++23
966
967 template<bidirectional_range R, class T = range_value_t<R>,
968 indirectly-binary-right-foldable<T, iterator_t<R>> F>
969 constexpr auto ranges::fold_right(R&& r, T init, F f); // since C++23
970
971 template<bidirectional_iterator I, sentinel_for<I> S,
972 indirectly-binary-right-foldable<iter_value_t<I>, I> F>
973 requires constructible_from<iter_value_t<I>, iter_reference_t<I>>
974 constexpr auto ranges::fold_right_last(I first, S last, F f); // since C++23
975
976 template<bidirectional_range R,
977 indirectly-binary-right-foldable<range_value_t<R>, iterator_t<R>> F>
978 requires constructible_from<range_value_t<R>, range_reference_t<R>>
979 constexpr auto ranges::fold_right_last(R&& r, F f); // since C++23
980
981 template<class I, class T>
982 using fold_left_with_iter_result = in_value_result<I, T>; // since C++23
983
984 template<input_iterator I, sentinel_for<I> S, class T,
985 indirectly-binary-left-foldable<T, I> F>
986 constexpr see below fold_left_with_iter(I first, S last, T init, F f); // since C++23
987
988 template<input_range R, class T, indirectly-binary-left-foldable<T, iterator_t<R>> F>
989 constexpr see below fold_left_with_iter(R&& r, T init, F f); // since C++23
990
991 template<class I, class T>
992 using fold_left_first_with_iter_result = in_value_result<I, T>; // since C++23
993
994 template<input_iterator I, sentinel_for<I> S,
995 indirectly-binary-left-foldable<iter_value_t<I>, I> F>
996 requires constructible_from<iter_value_t<I>, iter_reference_t<I>>
997 constexpr see below ranges::fold_left_first_with_iter(I first, S last, F f); // since C++23
998
999 template<input_range R, indirectly-binary-left-foldable<range_value_t<R>, iterator_t<R>> F>
1000 requires constructible_from<range_value_t<R>, range_reference_t<R>>
1001 constexpr see below ranges::fold_left_first_with_iter(R&& r, F f); // since C++23
1002
1003 template<forward_iterator I1, sentinel_for<I1> S1, forward_iterator I2, sentinel_for<I2> S2,
1004 class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
1005 requires indirectly_comparable<I1, I2, Pred, Proj1, Proj2>
1006 constexpr subrange<I1>
1007 ranges::find_end(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {},
1008 Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
1009
1010 template<forward_range R1, forward_range R2,
1011 class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
1012 requires indirectly_comparable<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
1013 constexpr borrowed_subrange_t<R1>
1014 ranges::find_end(R1&& r1, R2&& r2, Pred pred = {},
1015 Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
1016
1017 template<class I1, class I2, class O>
1018 using set_symmetric_difference_result = in_in_out_result<I1, I2, O>; // since C++20
1019
1020 template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2,
1021 weakly_incrementable O, class Comp = ranges::less,
1022 class Proj1 = identity, class Proj2 = identity>
1023 requires mergeable<I1, I2, O, Comp, Proj1, Proj2>
1024 constexpr set_symmetric_difference_result<I1, I2, O>
1025 set_symmetric_difference(I1 first1, S1 last1, I2 first2, S2 last2, O result,
1026 Comp comp = {}, Proj1 proj1 = {},
1027 Proj2 proj2 = {}); // since C++20
1028
1029 template<input_range R1, input_range R2, weakly_incrementable O,
1030 class Comp = ranges::less, class Proj1 = identity, class Proj2 = identity>
1031 requires mergeable<iterator_t<R1>, iterator_t<R2>, O, Comp, Proj1, Proj2>
1032 constexpr set_symmetric_difference_result<borrowed_iterator_t<R1>,
1033 borrowed_iterator_t<R2>, O>
1034 set_symmetric_difference(R1&& r1, R2&& r2, O result, Comp comp = {},
1035 Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
1036
1037 template<forward_iterator I, sentinel_for<I> S, class T, class Proj = identity,
1038 indirect_strict_weak_order<const T*, projected<I, Proj>> Comp = ranges::less>
1039 constexpr subrange<I>
1040 equal_range(I first, S last, const T& value, Comp comp = {}, Proj proj = {}); // since C++20
1041
1042 template<forward_range R, class T, class Proj = identity,
1043 indirect_strict_weak_order<const T*, projected<iterator_t<R>, Proj>> Comp =
1044 ranges::less>
1045 constexpr borrowed_subrange_t<R>
1046 equal_range(R&& r, const T& value, Comp comp = {}, Proj proj = {}); // since C++20
1047
1048 template<class I1, class I2, class O>
1049 using set_union_result = in_in_out_result<I1, I2, O>; // since C++20
1050
1051 template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2,
1052 weakly_incrementable O, class Comp = ranges::less,
1053 class Proj1 = identity, class Proj2 = identity>
1054 requires mergeable<I1, I2, O, Comp, Proj1, Proj2>
1055 constexpr set_union_result<I1, I2, O>
1056 set_union(I1 first1, S1 last1, I2 first2, S2 last2, O result, Comp comp = {},
1057 Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
1058
1059 template<input_range R1, input_range R2, weakly_incrementable O,
1060 class Comp = ranges::less, class Proj1 = identity, class Proj2 = identity>
1061 requires mergeable<iterator_t<R1>, iterator_t<R2>, O, Comp, Proj1, Proj2>
1062 constexpr set_union_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>, O>
1063 set_union(R1&& r1, R2&& r2, O result, Comp comp = {},
1064 Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
1065
1066 template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2,
1067 class Proj1 = identity, class Proj2 = identity,
1068 indirect_strict_weak_order<projected<I1, Proj1>, projected<I2, Proj2>> Comp =
1069 ranges::less>
1070 constexpr bool includes(I1 first1, S1 last1, I2 first2, S2 last2, Comp comp = {},
1071 Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
1072
1073 template<input_range R1, input_range R2, class Proj1 = identity,
1074 class Proj2 = identity,
1075 indirect_strict_weak_order<projected<iterator_t<R1>, Proj1>,
1076 projected<iterator_t<R2>, Proj2>> Comp = ranges::less>
1077 constexpr bool includes(R1&& r1, R2&& r2, Comp comp = {},
1078 Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
1079
1080 template<bidirectional_iterator I, sentinel_for<I> S, class Comp = ranges::less,
1081 class Proj = identity>
1082 requires sortable<I, Comp, Proj>
1083 constexpr I // constexpr since C++26
1084 inplace_merge(I first, I middle, S last, Comp comp = {}, Proj proj = {}); // since C++20
1085
1086 template<bidirectional_range R, class Comp = ranges::less, class Proj = identity>
1087 requires sortable<iterator_t<R>, Comp, Proj>
1088 constexpr borrowed_iterator_t<R> // constexpr since C++26
1089 inplace_merge(R&& r, iterator_t<R> middle, Comp comp = {},
1090 Proj proj = {}); // since C++20
1091
1092 template<permutable I, sentinel_for<I> S, class Proj = identity,
1093 indirect_equivalence_relation<projected<I, Proj>> C = ranges::equal_to>
1094 constexpr subrange<I> unique(I first, S last, C comp = {}, Proj proj = {}); // since C++20
1095
1096 template<forward_range R, class Proj = identity,
1097 indirect_equivalence_relation<projected<iterator_t<R>, Proj>> C = ranges::equal_to>
1098 requires permutable<iterator_t<R>>
1099 constexpr borrowed_subrange_t<R>
1100 unique(R&& r, C comp = {}, Proj proj = {}); // since C++20
1101
1102 template<input_iterator I, sentinel_for<I> S, weakly_incrementable O, class Proj = identity,
1103 indirect_equivalence_relation<projected<I, Proj>> C = ranges::equal_to>
1104 requires indirectly_copyable<I, O> &&
1105 (forward_iterator<I> ||
1106 (input_iterator<O> && same_as<iter_value_t<I>, iter_value_t<O>>) ||
1107 indirectly_copyable_storable<I, O>)
1108 constexpr unique_copy_result<I, O>
1109 unique_copy(I first, S last, O result, C comp = {}, Proj proj = {}); // since C++20
1110
1111 template<input_range R, weakly_incrementable O, class Proj = identity,
1112 indirect_equivalence_relation<projected<iterator_t<R>, Proj>> C = ranges::equal_to>
1113 requires indirectly_copyable<iterator_t<R>, O> &&
1114 (forward_iterator<iterator_t<R>> ||
1115 (input_iterator<O> && same_as<range_value_t<R>, iter_value_t<O>>) ||
1116 indirectly_copyable_storable<iterator_t<R>, O>)
1117 constexpr unique_copy_result<borrowed_iterator_t<R>, O>
1118 unique_copy(R&& r, O result, C comp = {}, Proj proj = {}); // since C++20
1119
1120 template<class I, class O>
1121 using remove_copy_result = in_out_result<I, O>; // since C++20
1122
1123 template<input_iterator I, sentinel_for<I> S, weakly_incrementable O, class T,
1124 class Proj = identity>
1125 indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T*>
1126 constexpr remove_copy_result<I, O>
1127 remove_copy(I first, S last, O result, const T& value, Proj proj = {}); // since C++20
1128
1129 template<input_range R, weakly_incrementable O, class T, class Proj = identity>
1130 requires indirectly_copyable<iterator_t<R>, O> &&
1131 indirect_binary_predicate<ranges::equal_to,
1132 projected<iterator_t<R>, Proj>, const T*>
1133 constexpr remove_copy_result<borrowed_iterator_t<R>, O>
1134 remove_copy(R&& r, O result, const T& value, Proj proj = {}); // since C++20
1135
1136 template<class I, class O>
1137 using remove_copy_if_result = in_out_result<I, O>; // since C++20
1138
1139 template<input_iterator I, sentinel_for<I> S, weakly_incrementable O,
1140 class Proj = identity, indirect_unary_predicate<projected<I, Proj>> Pred>
1141 requires indirectly_copyable<I, O>
1142 constexpr remove_copy_if_result<I, O>
1143 remove_copy_if(I first, S last, O result, Pred pred, Proj proj = {}); // since C++20
1144
1145 template<input_range R, weakly_incrementable O, class Proj = identity,
1146 indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
1147 requires indirectly_copyable<iterator_t<R>, O>
1148 constexpr remove_copy_if_result<borrowed_iterator_t<R>, O>
1149 remove_copy_if(R&& r, O result, Pred pred, Proj proj = {}); // since C++20
1150
1151 template<class I, class O>
1152 using replace_copy_result = in_out_result<I, O>; // since C++20
1153
1154 template<input_iterator I, sentinel_for<I> S, class T1, class T2,
1155 output_iterator<const T2&> O, class Proj = identity>
1156 requires indirectly_copyable<I, O> &&
1157 indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T1*>
1158 constexpr replace_copy_result<I, O>
1159 replace_copy(I first, S last, O result, const T1& old_value, const T2& new_value,
1160 Proj proj = {}); // since C++20
1161
1162 template<input_range R, class T1, class T2, output_iterator<const T2&> O,
1163 class Proj = identity>
1164 requires indirectly_copyable<iterator_t<R>, O> &&
1165 indirect_binary_predicate<ranges::equal_to,
1166 projected<iterator_t<R>, Proj>, const T1*>
1167 constexpr replace_copy_result<borrowed_iterator_t<R>, O>
1168 replace_copy(R&& r, O result, const T1& old_value, const T2& new_value,
1169 Proj proj = {}); // since C++20
1170
1171 template<class I, class O>
1172 using replace_copy_if_result = in_out_result<I, O>; // since C++20
1173
1174 template<input_iterator I, sentinel_for<I> S, class T, output_iterator<const T&> O,
1175 class Proj = identity, indirect_unary_predicate<projected<I, Proj>> Pred>
1176 requires indirectly_copyable<I, O>
1177 constexpr replace_copy_if_result<I, O>
1178 replace_copy_if(I first, S last, O result, Pred pred, const T& new_value,
1179 Proj proj = {}); // since C++20
1180
1181 template<input_range R, class T, output_iterator<const T&> O, class Proj = identity,
1182 indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
1183 requires indirectly_copyable<iterator_t<R>, O>
1184 constexpr replace_copy_if_result<borrowed_iterator_t<R>, O>
1185 replace_copy_if(R&& r, O result, Pred pred, const T& new_value,
1186 Proj proj = {}); // since C++20
1187
1188 template<class I>
1189 using prev_permutation_result = in_found_result<I>; // since C++20
1190
1191 template<bidirectional_iterator I, sentinel_for<I> S, class Comp = ranges::less,
1192 class Proj = identity>
1193 requires sortable<I, Comp, Proj>
1194 constexpr ranges::prev_permutation_result<I>
1195 ranges::prev_permutation(I first, S last, Comp comp = {}, Proj proj = {}); // since C++20
1196
1197 template<bidirectional_range R, class Comp = ranges::less,
1198 class Proj = identity>
1199 requires sortable<iterator_t<R>, Comp, Proj>
1200 constexpr ranges::prev_permutation_result<borrowed_iterator_t<R>>
1201 ranges::prev_permutation(R&& r, Comp comp = {}, Proj proj = {}); // since C++20
1202
1203 template<class I>
1204 using next_permutation_result = in_found_result<I>; // since C++20
1205
1206 template<bidirectional_iterator I, sentinel_for<I> S, class Comp = ranges::less,
1207 class Proj = identity>
1208 requires sortable<I, Comp, Proj>
1209 constexpr ranges::next_permutation_result<I>
1210 ranges::next_permutation(I first, S last, Comp comp = {}, Proj proj = {}); // since C++20
1211
1212 template<bidirectional_range R, class Comp = ranges::less,
1213 class Proj = identity>
1214 requires sortable<iterator_t<R>, Comp, Proj>
1215 constexpr ranges::next_permutation_result<borrowed_iterator_t<R>>
1216 ranges::next_permutation(R&& r, Comp comp = {}, Proj proj = {}); // since C++20
1217
1218}
1219
1220template <class InputIterator, class Predicate>
1221 constexpr bool // constexpr since C++20
1222 all_of(InputIterator first, InputIterator last, Predicate pred);
1223
1224template <class InputIterator, class Predicate>
1225 constexpr bool // constexpr since C++20
1226 any_of(InputIterator first, InputIterator last, Predicate pred);
1227
1228template <class InputIterator, class Predicate>
1229 constexpr bool // constexpr since C++20
1230 none_of(InputIterator first, InputIterator last, Predicate pred);
1231
1232template <class InputIterator, class Function>
1233 constexpr Function // constexpr since C++20
1234 for_each(InputIterator first, InputIterator last, Function f);
1235
1236template<class InputIterator, class Size, class Function>
1237 constexpr InputIterator // constexpr since C++20
1238 for_each_n(InputIterator first, Size n, Function f); // C++17
1239
1240template <class InputIterator, class T>
1241 constexpr InputIterator // constexpr since C++20
1242 find(InputIterator first, InputIterator last, const T& value);
1243
1244template <class InputIterator, class Predicate>
1245 constexpr InputIterator // constexpr since C++20
1246 find_if(InputIterator first, InputIterator last, Predicate pred);
1247
1248template<class InputIterator, class Predicate>
1249 constexpr InputIterator // constexpr since C++20
1250 find_if_not(InputIterator first, InputIterator last, Predicate pred);
1251
1252template <class ForwardIterator1, class ForwardIterator2>
1253 constexpr ForwardIterator1 // constexpr since C++20
1254 find_end(ForwardIterator1 first1, ForwardIterator1 last1,
1255 ForwardIterator2 first2, ForwardIterator2 last2);
1256
1257template <class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
1258 constexpr ForwardIterator1 // constexpr since C++20
1259 find_end(ForwardIterator1 first1, ForwardIterator1 last1,
1260 ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred);
1261
1262template <class ForwardIterator1, class ForwardIterator2>
1263 constexpr ForwardIterator1 // constexpr since C++20
1264 find_first_of(ForwardIterator1 first1, ForwardIterator1 last1,
1265 ForwardIterator2 first2, ForwardIterator2 last2);
1266
1267template <class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
1268 constexpr ForwardIterator1 // constexpr since C++20
1269 find_first_of(ForwardIterator1 first1, ForwardIterator1 last1,
1270 ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred);
1271
1272template <class ForwardIterator>
1273 constexpr ForwardIterator // constexpr since C++20
1274 adjacent_find(ForwardIterator first, ForwardIterator last);
1275
1276template <class ForwardIterator, class BinaryPredicate>
1277 constexpr ForwardIterator // constexpr since C++20
1278 adjacent_find(ForwardIterator first, ForwardIterator last, BinaryPredicate pred);
1279
1280template <class InputIterator, class T>
1281 constexpr typename iterator_traits<InputIterator>::difference_type // constexpr since C++20
1282 count(InputIterator first, InputIterator last, const T& value);
1283
1284template <class InputIterator, class Predicate>
1285 constexpr typename iterator_traits<InputIterator>::difference_type // constexpr since C++20
1286 count_if(InputIterator first, InputIterator last, Predicate pred);
1287
1288template <class InputIterator1, class InputIterator2>
1289 constexpr pair<InputIterator1, InputIterator2> // constexpr since C++20
1290 mismatch(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2);
1291
1292template <class InputIterator1, class InputIterator2>
1293 constexpr pair<InputIterator1, InputIterator2>
1294 mismatch(InputIterator1 first1, InputIterator1 last1,
1295 InputIterator2 first2, InputIterator2 last2); // since C++14, constexpr since C++20
1296
1297template <class InputIterator1, class InputIterator2, class BinaryPredicate>
1298 constexpr pair<InputIterator1, InputIterator2> // constexpr since C++20
1299 mismatch(InputIterator1 first1, InputIterator1 last1,
1300 InputIterator2 first2, BinaryPredicate pred);
1301
1302template <class InputIterator1, class InputIterator2, class BinaryPredicate>
1303 constexpr pair<InputIterator1, InputIterator2>
1304 mismatch(InputIterator1 first1, InputIterator1 last1,
1305 InputIterator2 first2, InputIterator2 last2,
1306 BinaryPredicate pred); // since C++14, constexpr since C++20
1307
1308template <class InputIterator1, class InputIterator2>
1309 constexpr bool // constexpr since C++20
1310 equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2);
1311
1312template <class InputIterator1, class InputIterator2>
1313 constexpr bool
1314 equal(InputIterator1 first1, InputIterator1 last1,
1315 InputIterator2 first2, InputIterator2 last2); // since C++14, constexpr since C++20
1316
1317template <class InputIterator1, class InputIterator2, class BinaryPredicate>
1318 constexpr bool // constexpr since C++20
1319 equal(InputIterator1 first1, InputIterator1 last1,
1320 InputIterator2 first2, BinaryPredicate pred);
1321
1322template <class InputIterator1, class InputIterator2, class BinaryPredicate>
1323 constexpr bool
1324 equal(InputIterator1 first1, InputIterator1 last1,
1325 InputIterator2 first2, InputIterator2 last2,
1326 BinaryPredicate pred); // since C++14, constexpr since C++20
1327
1328template<class ForwardIterator1, class ForwardIterator2>
1329 constexpr bool // constexpr since C++20
1330 is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
1331 ForwardIterator2 first2);
1332
1333template<class ForwardIterator1, class ForwardIterator2>
1334 constexpr bool
1335 is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
1336 ForwardIterator2 first2, ForwardIterator2 last2); // since C++14, constexpr since C++20
1337
1338template<class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
1339 constexpr bool // constexpr since C++20
1340 is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
1341 ForwardIterator2 first2, BinaryPredicate pred);
1342
1343template<class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
1344 constexpr bool
1345 is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
1346 ForwardIterator2 first2, ForwardIterator2 last2,
1347 BinaryPredicate pred); // since C++14, constexpr since C++20
1348
1349template <class ForwardIterator1, class ForwardIterator2>
1350 constexpr ForwardIterator1 // constexpr since C++20
1351 search(ForwardIterator1 first1, ForwardIterator1 last1,
1352 ForwardIterator2 first2, ForwardIterator2 last2);
1353
1354template <class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
1355 constexpr ForwardIterator1 // constexpr since C++20
1356 search(ForwardIterator1 first1, ForwardIterator1 last1,
1357 ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred);
1358
1359template <class ForwardIterator, class Size, class T>
1360 constexpr ForwardIterator // constexpr since C++20
1361 search_n(ForwardIterator first, ForwardIterator last, Size count, const T& value);
1362
1363template <class ForwardIterator, class Size, class T, class BinaryPredicate>
1364 constexpr ForwardIterator // constexpr since C++20
1365 search_n(ForwardIterator first, ForwardIterator last,
1366 Size count, const T& value, BinaryPredicate pred);
1367
1368template <class InputIterator, class OutputIterator>
1369 constexpr OutputIterator // constexpr since C++20
1370 copy(InputIterator first, InputIterator last, OutputIterator result);
1371
1372template<class InputIterator, class OutputIterator, class Predicate>
1373 constexpr OutputIterator // constexpr since C++20
1374 copy_if(InputIterator first, InputIterator last,
1375 OutputIterator result, Predicate pred);
1376
1377template<class InputIterator, class Size, class OutputIterator>
1378 constexpr OutputIterator // constexpr since C++20
1379 copy_n(InputIterator first, Size n, OutputIterator result);
1380
1381template <class BidirectionalIterator1, class BidirectionalIterator2>
1382 constexpr BidirectionalIterator2 // constexpr since C++20
1383 copy_backward(BidirectionalIterator1 first, BidirectionalIterator1 last,
1384 BidirectionalIterator2 result);
1385
1386// [alg.move], move
1387template<class InputIterator, class OutputIterator>
1388 constexpr OutputIterator move(InputIterator first, InputIterator last,
1389 OutputIterator result);
1390
1391template<class BidirectionalIterator1, class BidirectionalIterator2>
1392 constexpr BidirectionalIterator2
1393 move_backward(BidirectionalIterator1 first, BidirectionalIterator1 last,
1394 BidirectionalIterator2 result);
1395
1396template <class ForwardIterator1, class ForwardIterator2>
1397 constexpr ForwardIterator2 // constexpr since C++20
1398 swap_ranges(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2);
1399
1400namespace ranges {
1401 template<class I1, class I2>
1402 using swap_ranges_result = in_in_result<I1, I2>;
1403
1404template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2>
1405 requires indirectly_swappable<I1, I2>
1406 constexpr ranges::swap_ranges_result<I1, I2>
1407 swap_ranges(I1 first1, S1 last1, I2 first2, S2 last2);
1408
1409template<input_range R1, input_range R2>
1410 requires indirectly_swappable<iterator_t<R1>, iterator_t<R2>>
1411 constexpr ranges::swap_ranges_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>>
1412 swap_ranges(R1&& r1, R2&& r2);
1413}
1414
1415template <class ForwardIterator1, class ForwardIterator2>
1416 constexpr void // constexpr since C++20
1417 iter_swap(ForwardIterator1 a, ForwardIterator2 b);
1418
1419template <class InputIterator, class OutputIterator, class UnaryOperation>
1420 constexpr OutputIterator // constexpr since C++20
1421 transform(InputIterator first, InputIterator last, OutputIterator result, UnaryOperation op);
1422
1423template <class InputIterator1, class InputIterator2, class OutputIterator, class BinaryOperation>
1424 constexpr OutputIterator // constexpr since C++20
1425 transform(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2,
1426 OutputIterator result, BinaryOperation binary_op);
1427
1428template <class ForwardIterator, class T>
1429 constexpr void // constexpr since C++20
1430 replace(ForwardIterator first, ForwardIterator last, const T& old_value, const T& new_value);
1431
1432template <class ForwardIterator, class Predicate, class T>
1433 constexpr void // constexpr since C++20
1434 replace_if(ForwardIterator first, ForwardIterator last, Predicate pred, const T& new_value);
1435
1436template <class InputIterator, class OutputIterator, class T>
1437 constexpr OutputIterator // constexpr since C++20
1438 replace_copy(InputIterator first, InputIterator last, OutputIterator result,
1439 const T& old_value, const T& new_value);
1440
1441template <class InputIterator, class OutputIterator, class Predicate, class T>
1442 constexpr OutputIterator // constexpr since C++20
1443 replace_copy_if(InputIterator first, InputIterator last, OutputIterator result, Predicate pred, const T& new_value);
1444
1445template <class ForwardIterator, class T>
1446 constexpr void // constexpr since C++20
1447 fill(ForwardIterator first, ForwardIterator last, const T& value);
1448
1449template <class OutputIterator, class Size, class T>
1450 constexpr OutputIterator // constexpr since C++20
1451 fill_n(OutputIterator first, Size n, const T& value);
1452
1453template <class ForwardIterator, class Generator>
1454 constexpr void // constexpr since C++20
1455 generate(ForwardIterator first, ForwardIterator last, Generator gen);
1456
1457template <class OutputIterator, class Size, class Generator>
1458 constexpr OutputIterator // constexpr since C++20
1459 generate_n(OutputIterator first, Size n, Generator gen);
1460
1461template <class ForwardIterator, class T>
1462 constexpr ForwardIterator // constexpr since C++20
1463 remove(ForwardIterator first, ForwardIterator last, const T& value);
1464
1465template <class ForwardIterator, class Predicate>
1466 constexpr ForwardIterator // constexpr since C++20
1467 remove_if(ForwardIterator first, ForwardIterator last, Predicate pred);
1468
1469template <class InputIterator, class OutputIterator, class T>
1470 constexpr OutputIterator // constexpr since C++20
1471 remove_copy(InputIterator first, InputIterator last, OutputIterator result, const T& value);
1472
1473template <class InputIterator, class OutputIterator, class Predicate>
1474 constexpr OutputIterator // constexpr since C++20
1475 remove_copy_if(InputIterator first, InputIterator last, OutputIterator result, Predicate pred);
1476
1477template <class ForwardIterator>
1478 constexpr ForwardIterator // constexpr since C++20
1479 unique(ForwardIterator first, ForwardIterator last);
1480
1481template <class ForwardIterator, class BinaryPredicate>
1482 constexpr ForwardIterator // constexpr since C++20
1483 unique(ForwardIterator first, ForwardIterator last, BinaryPredicate pred);
1484
1485template <class InputIterator, class OutputIterator>
1486 constexpr OutputIterator // constexpr since C++20
1487 unique_copy(InputIterator first, InputIterator last, OutputIterator result);
1488
1489template <class InputIterator, class OutputIterator, class BinaryPredicate>
1490 constexpr OutputIterator // constexpr since C++20
1491 unique_copy(InputIterator first, InputIterator last, OutputIterator result, BinaryPredicate pred);
1492
1493template <class BidirectionalIterator>
1494 constexpr void // constexpr since C++20
1495 reverse(BidirectionalIterator first, BidirectionalIterator last);
1496
1497template <class BidirectionalIterator, class OutputIterator>
1498 constexpr OutputIterator // constexpr since C++20
1499 reverse_copy(BidirectionalIterator first, BidirectionalIterator last, OutputIterator result);
1500
1501template <class ForwardIterator>
1502 constexpr ForwardIterator // constexpr since C++20
1503 rotate(ForwardIterator first, ForwardIterator middle, ForwardIterator last);
1504
1505template <class ForwardIterator, class OutputIterator>
1506 constexpr OutputIterator // constexpr since C++20
1507 rotate_copy(ForwardIterator first, ForwardIterator middle, ForwardIterator last, OutputIterator result);
1508
1509template <class RandomAccessIterator>
1510 void
1511 random_shuffle(RandomAccessIterator first, RandomAccessIterator last); // deprecated in C++14, removed in C++17
1512
1513template <class RandomAccessIterator, class RandomNumberGenerator>
1514 void
1515 random_shuffle(RandomAccessIterator first, RandomAccessIterator last,
1516 RandomNumberGenerator& rand); // deprecated in C++14, removed in C++17
1517
1518template<class PopulationIterator, class SampleIterator,
1519 class Distance, class UniformRandomBitGenerator>
1520 SampleIterator sample(PopulationIterator first, PopulationIterator last,
1521 SampleIterator out, Distance n,
1522 UniformRandomBitGenerator&& g); // C++17
1523
1524template<class RandomAccessIterator, class UniformRandomNumberGenerator>
1525 void shuffle(RandomAccessIterator first, RandomAccessIterator last,
1526 UniformRandomNumberGenerator&& g);
1527
1528template<class ForwardIterator>
1529 constexpr ForwardIterator
1530 shift_left(ForwardIterator first, ForwardIterator last,
1531 typename iterator_traits<ForwardIterator>::difference_type n); // C++20
1532
1533template<class ForwardIterator>
1534 constexpr ForwardIterator
1535 shift_right(ForwardIterator first, ForwardIterator last,
1536 typename iterator_traits<ForwardIterator>::difference_type n); // C++20
1537
1538 template<permutable I, sentinel_for<I> S>
1539 constexpr subrange<I> ranges::shift_right(I first, S last, iter_difference_t<I> n); // since C++23
1540
1541 template<forward_range R>
1542 requires permutable<iterator_t<R>>
1543 constexpr borrowed_subrange_t<R> ranges::shift_right(R&& r, range_difference_t<R> n) // since C++23
1544
1545template <class InputIterator, class Predicate>
1546 constexpr bool // constexpr since C++20
1547 is_partitioned(InputIterator first, InputIterator last, Predicate pred);
1548
1549template <class ForwardIterator, class Predicate>
1550 constexpr ForwardIterator // constexpr since C++20
1551 partition(ForwardIterator first, ForwardIterator last, Predicate pred);
1552
1553template <class InputIterator, class OutputIterator1,
1554 class OutputIterator2, class Predicate>
1555 constexpr pair<OutputIterator1, OutputIterator2> // constexpr since C++20
1556 partition_copy(InputIterator first, InputIterator last,
1557 OutputIterator1 out_true, OutputIterator2 out_false,
1558 Predicate pred);
1559
1560template <class ForwardIterator, class Predicate>
1561 constexpr ForwardIterator // constexpr since C++26
1562 stable_partition(ForwardIterator first, ForwardIterator last, Predicate pred);
1563
1564template<class ForwardIterator, class Predicate>
1565 constexpr ForwardIterator // constexpr since C++20
1566 partition_point(ForwardIterator first, ForwardIterator last, Predicate pred);
1567
1568template <class ForwardIterator>
1569 constexpr bool // constexpr since C++20
1570 is_sorted(ForwardIterator first, ForwardIterator last);
1571
1572template <class ForwardIterator, class Compare>
1573 constexpr bool // constexpr since C++20
1574 is_sorted(ForwardIterator first, ForwardIterator last, Compare comp);
1575
1576template<class ForwardIterator>
1577 constexpr ForwardIterator // constexpr since C++20
1578 is_sorted_until(ForwardIterator first, ForwardIterator last);
1579
1580template <class ForwardIterator, class Compare>
1581 constexpr ForwardIterator // constexpr since C++20
1582 is_sorted_until(ForwardIterator first, ForwardIterator last, Compare comp);
1583
1584template <class RandomAccessIterator>
1585 constexpr void // constexpr since C++20
1586 sort(RandomAccessIterator first, RandomAccessIterator last);
1587
1588template <class RandomAccessIterator, class Compare>
1589 constexpr void // constexpr since C++20
1590 sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
1591
1592template <class RandomAccessIterator>
1593 constexpr void // constexpr since C++26
1594 stable_sort(RandomAccessIterator first, RandomAccessIterator last);
1595
1596template <class RandomAccessIterator, class Compare>
1597 constexpr void // constexpr since C++26
1598 stable_sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
1599
1600template <class RandomAccessIterator>
1601 constexpr void // constexpr since C++20
1602 partial_sort(RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last);
1603
1604template <class RandomAccessIterator, class Compare>
1605 constexpr void // constexpr since C++20
1606 partial_sort(RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last, Compare comp);
1607
1608template <class InputIterator, class RandomAccessIterator>
1609 constexpr RandomAccessIterator // constexpr since C++20
1610 partial_sort_copy(InputIterator first, InputIterator last,
1611 RandomAccessIterator result_first, RandomAccessIterator result_last);
1612
1613template <class InputIterator, class RandomAccessIterator, class Compare>
1614 constexpr RandomAccessIterator // constexpr since C++20
1615 partial_sort_copy(InputIterator first, InputIterator last,
1616 RandomAccessIterator result_first, RandomAccessIterator result_last, Compare comp);
1617
1618template <class RandomAccessIterator>
1619 constexpr void // constexpr since C++20
1620 nth_element(RandomAccessIterator first, RandomAccessIterator nth, RandomAccessIterator last);
1621
1622template <class RandomAccessIterator, class Compare>
1623 constexpr void // constexpr since C++20
1624 nth_element(RandomAccessIterator first, RandomAccessIterator nth, RandomAccessIterator last, Compare comp);
1625
1626template <class ForwardIterator, class T>
1627 constexpr ForwardIterator // constexpr since C++20
1628 lower_bound(ForwardIterator first, ForwardIterator last, const T& value);
1629
1630template <class ForwardIterator, class T, class Compare>
1631 constexpr ForwardIterator // constexpr since C++20
1632 lower_bound(ForwardIterator first, ForwardIterator last, const T& value, Compare comp);
1633
1634template <class ForwardIterator, class T>
1635 constexpr ForwardIterator // constexpr since C++20
1636 upper_bound(ForwardIterator first, ForwardIterator last, const T& value);
1637
1638template <class ForwardIterator, class T, class Compare>
1639 constexpr ForwardIterator // constexpr since C++20
1640 upper_bound(ForwardIterator first, ForwardIterator last, const T& value, Compare comp);
1641
1642template <class ForwardIterator, class T>
1643 constexpr pair<ForwardIterator, ForwardIterator> // constexpr since C++20
1644 equal_range(ForwardIterator first, ForwardIterator last, const T& value);
1645
1646template <class ForwardIterator, class T, class Compare>
1647 constexpr pair<ForwardIterator, ForwardIterator> // constexpr since C++20
1648 equal_range(ForwardIterator first, ForwardIterator last, const T& value, Compare comp);
1649
1650template <class ForwardIterator, class T>
1651 constexpr bool // constexpr since C++20
1652 binary_search(ForwardIterator first, ForwardIterator last, const T& value);
1653
1654template <class ForwardIterator, class T, class Compare>
1655 constexpr bool // constexpr since C++20
1656 binary_search(ForwardIterator first, ForwardIterator last, const T& value, Compare comp);
1657
1658template <class InputIterator1, class InputIterator2, class OutputIterator>
1659 constexpr OutputIterator // constexpr since C++20
1660 merge(InputIterator1 first1, InputIterator1 last1,
1661 InputIterator2 first2, InputIterator2 last2, OutputIterator result);
1662
1663template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
1664 constexpr OutputIterator // constexpr since C++20
1665 merge(InputIterator1 first1, InputIterator1 last1,
1666 InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
1667
1668template <class BidirectionalIterator>
1669 constexpr void // constexpr since C++26
1670 inplace_merge(BidirectionalIterator first, BidirectionalIterator middle, BidirectionalIterator last);
1671
1672template <class BidirectionalIterator, class Compare>
1673 constexpr void // constexpr since C++26
1674 inplace_merge(BidirectionalIterator first, BidirectionalIterator middle, BidirectionalIterator last, Compare comp);
1675
1676template <class InputIterator1, class InputIterator2>
1677 constexpr bool // constexpr since C++20
1678 includes(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2);
1679
1680template <class InputIterator1, class InputIterator2, class Compare>
1681 constexpr bool // constexpr since C++20
1682 includes(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, Compare comp);
1683
1684template <class InputIterator1, class InputIterator2, class OutputIterator>
1685 constexpr OutputIterator // constexpr since C++20
1686 set_union(InputIterator1 first1, InputIterator1 last1,
1687 InputIterator2 first2, InputIterator2 last2, OutputIterator result);
1688
1689template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
1690 constexpr OutputIterator // constexpr since C++20
1691 set_union(InputIterator1 first1, InputIterator1 last1,
1692 InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
1693
1694template <class InputIterator1, class InputIterator2, class OutputIterator>
1695 constexpr OutputIterator // constexpr since C++20
1696 set_intersection(InputIterator1 first1, InputIterator1 last1,
1697 InputIterator2 first2, InputIterator2 last2, OutputIterator result);
1698
1699template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
1700 constexpr OutputIterator // constexpr since C++20
1701 set_intersection(InputIterator1 first1, InputIterator1 last1,
1702 InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
1703
1704template <class InputIterator1, class InputIterator2, class OutputIterator>
1705 constexpr OutputIterator // constexpr since C++20
1706 set_difference(InputIterator1 first1, InputIterator1 last1,
1707 InputIterator2 first2, InputIterator2 last2, OutputIterator result);
1708
1709template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
1710 constexpr OutputIterator // constexpr since C++20
1711 set_difference(InputIterator1 first1, InputIterator1 last1,
1712 InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
1713
1714template <class InputIterator1, class InputIterator2, class OutputIterator>
1715 constexpr OutputIterator // constexpr since C++20
1716 set_symmetric_difference(InputIterator1 first1, InputIterator1 last1,
1717 InputIterator2 first2, InputIterator2 last2, OutputIterator result);
1718
1719template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
1720 constexpr OutputIterator // constexpr since C++20
1721 set_symmetric_difference(InputIterator1 first1, InputIterator1 last1,
1722 InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
1723
1724template <class RandomAccessIterator>
1725 constexpr void // constexpr since C++20
1726 push_heap(RandomAccessIterator first, RandomAccessIterator last);
1727
1728template <class RandomAccessIterator, class Compare>
1729 constexpr void // constexpr since C++20
1730 push_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
1731
1732template <class RandomAccessIterator>
1733 constexpr void // constexpr since C++20
1734 pop_heap(RandomAccessIterator first, RandomAccessIterator last);
1735
1736template <class RandomAccessIterator, class Compare>
1737 constexpr void // constexpr since C++20
1738 pop_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
1739
1740template <class RandomAccessIterator>
1741 constexpr void // constexpr since C++20
1742 make_heap(RandomAccessIterator first, RandomAccessIterator last);
1743
1744template <class RandomAccessIterator, class Compare>
1745 constexpr void // constexpr since C++20
1746 make_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
1747
1748template <class RandomAccessIterator>
1749 constexpr void // constexpr since C++20
1750 sort_heap(RandomAccessIterator first, RandomAccessIterator last);
1751
1752template <class RandomAccessIterator, class Compare>
1753 constexpr void // constexpr since C++20
1754 sort_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
1755
1756template <class RandomAccessIterator>
1757 constexpr bool // constexpr since C++20
1758 is_heap(RandomAccessIterator first, RandomAccessiterator last);
1759
1760template <class RandomAccessIterator, class Compare>
1761 constexpr bool // constexpr since C++20
1762 is_heap(RandomAccessIterator first, RandomAccessiterator last, Compare comp);
1763
1764template <class RandomAccessIterator>
1765 constexpr RandomAccessIterator // constexpr since C++20
1766 is_heap_until(RandomAccessIterator first, RandomAccessiterator last);
1767
1768template <class RandomAccessIterator, class Compare>
1769 constexpr RandomAccessIterator // constexpr since C++20
1770 is_heap_until(RandomAccessIterator first, RandomAccessiterator last, Compare comp);
1771
1772template <class ForwardIterator>
1773 constexpr ForwardIterator // constexpr since C++14
1774 min_element(ForwardIterator first, ForwardIterator last);
1775
1776template <class ForwardIterator, class Compare>
1777 constexpr ForwardIterator // constexpr since C++14
1778 min_element(ForwardIterator first, ForwardIterator last, Compare comp);
1779
1780template <class T>
1781 constexpr const T& // constexpr since C++14
1782 min(const T& a, const T& b);
1783
1784template <class T, class Compare>
1785 constexpr const T& // constexpr since C++14
1786 min(const T& a, const T& b, Compare comp);
1787
1788template<class T>
1789 constexpr T // constexpr since C++14
1790 min(initializer_list<T> t);
1791
1792template<class T, class Compare>
1793 constexpr T // constexpr since C++14
1794 min(initializer_list<T> t, Compare comp);
1795
1796template<class T>
1797 constexpr const T& clamp(const T& v, const T& lo, const T& hi); // C++17
1798
1799template<class T, class Compare>
1800 constexpr const T& clamp(const T& v, const T& lo, const T& hi, Compare comp); // C++17
1801
1802template <class ForwardIterator>
1803 constexpr ForwardIterator // constexpr since C++14
1804 max_element(ForwardIterator first, ForwardIterator last);
1805
1806template <class ForwardIterator, class Compare>
1807 constexpr ForwardIterator // constexpr since C++14
1808 max_element(ForwardIterator first, ForwardIterator last, Compare comp);
1809
1810template <class T>
1811 constexpr const T& // constexpr since C++14
1812 max(const T& a, const T& b);
1813
1814template <class T, class Compare>
1815 constexpr const T& // constexpr since C++14
1816 max(const T& a, const T& b, Compare comp);
1817
1818template<class T>
1819 constexpr T // constexpr since C++14
1820 max(initializer_list<T> t);
1821
1822template<class T, class Compare>
1823 constexpr T // constexpr since C++14
1824 max(initializer_list<T> t, Compare comp);
1825
1826template<class ForwardIterator>
1827 constexpr pair<ForwardIterator, ForwardIterator> // constexpr since C++14
1828 minmax_element(ForwardIterator first, ForwardIterator last);
1829
1830template<class ForwardIterator, class Compare>
1831 constexpr pair<ForwardIterator, ForwardIterator> // constexpr since C++14
1832 minmax_element(ForwardIterator first, ForwardIterator last, Compare comp);
1833
1834template<class T>
1835 constexpr pair<const T&, const T&> // constexpr since C++14
1836 minmax(const T& a, const T& b);
1837
1838template<class T, class Compare>
1839 constexpr pair<const T&, const T&> // constexpr since C++14
1840 minmax(const T& a, const T& b, Compare comp);
1841
1842template<class T>
1843 constexpr pair<T, T> // constexpr since C++14
1844 minmax(initializer_list<T> t);
1845
1846template<class T, class Compare>
1847 constexpr pair<T, T> // constexpr since C++14
1848 minmax(initializer_list<T> t, Compare comp);
1849
1850template <class InputIterator1, class InputIterator2>
1851 constexpr bool // constexpr since C++20
1852 lexicographical_compare(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2);
1853
1854template <class InputIterator1, class InputIterator2, class Compare>
1855 constexpr bool // constexpr since C++20
1856 lexicographical_compare(InputIterator1 first1, InputIterator1 last1,
1857 InputIterator2 first2, InputIterator2 last2, Compare comp);
1858
1859template<class InputIterator1, class InputIterator2, class Cmp>
1860 constexpr auto
1861 lexicographical_compare_three_way(InputIterator1 first1, InputIterator1 last1,
1862 InputIterator2 first2, InputIterator2 last2,
1863 Cmp comp)
1864 -> decltype(comp(*b1, *b2)); // since C++20
1865
1866template<class InputIterator1, class InputIterator2>
1867 constexpr auto
1868 lexicographical_compare_three_way(InputIterator1 first1, InputIterator1 last1,
1869 InputIterator2 first2, InputIterator2 last2); // since C++20
1870
1871template <class BidirectionalIterator>
1872 constexpr bool // constexpr since C++20
1873 next_permutation(BidirectionalIterator first, BidirectionalIterator last);
1874
1875template <class BidirectionalIterator, class Compare>
1876 constexpr bool // constexpr since C++20
1877 next_permutation(BidirectionalIterator first, BidirectionalIterator last, Compare comp);
1878
1879template <class BidirectionalIterator>
1880 constexpr bool // constexpr since C++20
1881 prev_permutation(BidirectionalIterator first, BidirectionalIterator last);
1882
1883template <class BidirectionalIterator, class Compare>
1884 constexpr bool // constexpr since C++20
1885 prev_permutation(BidirectionalIterator first, BidirectionalIterator last, Compare comp);
1886} // std
1887
1888*/
1889
1890#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
1891# include <__cxx03/algorithm>
1892#else
1893# include <__config>
1894
1895# include <__algorithm/adjacent_find.h>
1896# include <__algorithm/all_of.h>
1897# include <__algorithm/any_of.h>
1898# include <__algorithm/binary_search.h>
1899# include <__algorithm/copy.h>
1900# include <__algorithm/copy_backward.h>
1901# include <__algorithm/copy_if.h>
1902# include <__algorithm/copy_n.h>
1903# include <__algorithm/count.h>
1904# include <__algorithm/count_if.h>
1905# include <__algorithm/equal.h>
1906# include <__algorithm/equal_range.h>
1907# include <__algorithm/fill.h>
1908# include <__algorithm/fill_n.h>
1909# include <__algorithm/find.h>
1910# include <__algorithm/find_end.h>
1911# include <__algorithm/find_first_of.h>
1912# include <__algorithm/find_if.h>
1913# include <__algorithm/find_if_not.h>
1914# include <__algorithm/for_each.h>
1915# include <__algorithm/generate.h>
1916# include <__algorithm/generate_n.h>
1917# include <__algorithm/includes.h>
1918# include <__algorithm/inplace_merge.h>
1919# include <__algorithm/is_heap.h>
1920# include <__algorithm/is_heap_until.h>
1921# include <__algorithm/is_partitioned.h>
1922# include <__algorithm/is_permutation.h>
1923# include <__algorithm/is_sorted.h>
1924# include <__algorithm/is_sorted_until.h>
1925# include <__algorithm/iter_swap.h>
1926# include <__algorithm/lexicographical_compare.h>
1927# include <__algorithm/lower_bound.h>
1928# include <__algorithm/make_heap.h>
1929# include <__algorithm/max.h>
1930# include <__algorithm/max_element.h>
1931# include <__algorithm/merge.h>
1932# include <__algorithm/min.h>
1933# include <__algorithm/min_element.h>
1934# include <__algorithm/minmax.h>
1935# include <__algorithm/minmax_element.h>
1936# include <__algorithm/mismatch.h>
1937# include <__algorithm/move.h>
1938# include <__algorithm/move_backward.h>
1939# include <__algorithm/next_permutation.h>
1940# include <__algorithm/none_of.h>
1941# include <__algorithm/nth_element.h>
1942# include <__algorithm/partial_sort.h>
1943# include <__algorithm/partial_sort_copy.h>
1944# include <__algorithm/partition.h>
1945# include <__algorithm/partition_copy.h>
1946# include <__algorithm/partition_point.h>
1947# include <__algorithm/pop_heap.h>
1948# include <__algorithm/prev_permutation.h>
1949# include <__algorithm/push_heap.h>
1950# include <__algorithm/remove.h>
1951# include <__algorithm/remove_copy.h>
1952# include <__algorithm/remove_copy_if.h>
1953# include <__algorithm/remove_if.h>
1954# include <__algorithm/replace.h>
1955# include <__algorithm/replace_copy.h>
1956# include <__algorithm/replace_copy_if.h>
1957# include <__algorithm/replace_if.h>
1958# include <__algorithm/reverse.h>
1959# include <__algorithm/reverse_copy.h>
1960# include <__algorithm/rotate.h>
1961# include <__algorithm/rotate_copy.h>
1962# include <__algorithm/search.h>
1963# include <__algorithm/search_n.h>
1964# include <__algorithm/set_difference.h>
1965# include <__algorithm/set_intersection.h>
1966# include <__algorithm/set_symmetric_difference.h>
1967# include <__algorithm/set_union.h>
1968# include <__algorithm/shuffle.h>
1969# include <__algorithm/sort.h>
1970# include <__algorithm/sort_heap.h>
1971# include <__algorithm/stable_partition.h>
1972# include <__algorithm/stable_sort.h>
1973# include <__algorithm/swap_ranges.h>
1974# include <__algorithm/transform.h>
1975# include <__algorithm/unique.h>
1976# include <__algorithm/unique_copy.h>
1977# include <__algorithm/upper_bound.h>
1978
1979# if _LIBCPP_STD_VER >= 17
1980# include <__algorithm/clamp.h>
1981# include <__algorithm/for_each_n.h>
1982# include <__algorithm/pstl.h>
1983# include <__algorithm/sample.h>
1984# endif // _LIBCPP_STD_VER >= 17
1985
1986# if _LIBCPP_STD_VER >= 20
1987# include <__algorithm/in_found_result.h>
1988# include <__algorithm/in_fun_result.h>
1989# include <__algorithm/in_in_out_result.h>
1990# include <__algorithm/in_in_result.h>
1991# include <__algorithm/in_out_out_result.h>
1992# include <__algorithm/in_out_result.h>
1993# include <__algorithm/lexicographical_compare_three_way.h>
1994# include <__algorithm/min_max_result.h>
1995# include <__algorithm/out_value_result.h>
1996# include <__algorithm/ranges_adjacent_find.h>
1997# include <__algorithm/ranges_all_of.h>
1998# include <__algorithm/ranges_any_of.h>
1999# include <__algorithm/ranges_binary_search.h>
2000# include <__algorithm/ranges_clamp.h>
2001# include <__algorithm/ranges_contains.h>
2002# include <__algorithm/ranges_copy.h>
2003# include <__algorithm/ranges_copy_backward.h>
2004# include <__algorithm/ranges_copy_if.h>
2005# include <__algorithm/ranges_copy_n.h>
2006# include <__algorithm/ranges_count.h>
2007# include <__algorithm/ranges_count_if.h>
2008# include <__algorithm/ranges_equal.h>
2009# include <__algorithm/ranges_equal_range.h>
2010# include <__algorithm/ranges_fill.h>
2011# include <__algorithm/ranges_fill_n.h>
2012# include <__algorithm/ranges_find.h>
2013# include <__algorithm/ranges_find_end.h>
2014# include <__algorithm/ranges_find_first_of.h>
2015# include <__algorithm/ranges_find_if.h>
2016# include <__algorithm/ranges_find_if_not.h>
2017# include <__algorithm/ranges_for_each.h>
2018# include <__algorithm/ranges_for_each_n.h>
2019# include <__algorithm/ranges_generate.h>
2020# include <__algorithm/ranges_generate_n.h>
2021# include <__algorithm/ranges_includes.h>
2022# include <__algorithm/ranges_inplace_merge.h>
2023# include <__algorithm/ranges_is_heap.h>
2024# include <__algorithm/ranges_is_heap_until.h>
2025# include <__algorithm/ranges_is_partitioned.h>
2026# include <__algorithm/ranges_is_permutation.h>
2027# include <__algorithm/ranges_is_sorted.h>
2028# include <__algorithm/ranges_is_sorted_until.h>
2029# include <__algorithm/ranges_lexicographical_compare.h>
2030# include <__algorithm/ranges_lower_bound.h>
2031# include <__algorithm/ranges_make_heap.h>
2032# include <__algorithm/ranges_max.h>
2033# include <__algorithm/ranges_max_element.h>
2034# include <__algorithm/ranges_merge.h>
2035# include <__algorithm/ranges_min.h>
2036# include <__algorithm/ranges_min_element.h>
2037# include <__algorithm/ranges_minmax.h>
2038# include <__algorithm/ranges_minmax_element.h>
2039# include <__algorithm/ranges_mismatch.h>
2040# include <__algorithm/ranges_move.h>
2041# include <__algorithm/ranges_move_backward.h>
2042# include <__algorithm/ranges_next_permutation.h>
2043# include <__algorithm/ranges_none_of.h>
2044# include <__algorithm/ranges_nth_element.h>
2045# include <__algorithm/ranges_partial_sort.h>
2046# include <__algorithm/ranges_partial_sort_copy.h>
2047# include <__algorithm/ranges_partition.h>
2048# include <__algorithm/ranges_partition_copy.h>
2049# include <__algorithm/ranges_partition_point.h>
2050# include <__algorithm/ranges_pop_heap.h>
2051# include <__algorithm/ranges_prev_permutation.h>
2052# include <__algorithm/ranges_push_heap.h>
2053# include <__algorithm/ranges_remove.h>
2054# include <__algorithm/ranges_remove_copy.h>
2055# include <__algorithm/ranges_remove_copy_if.h>
2056# include <__algorithm/ranges_remove_if.h>
2057# include <__algorithm/ranges_replace.h>
2058# include <__algorithm/ranges_replace_copy.h>
2059# include <__algorithm/ranges_replace_copy_if.h>
2060# include <__algorithm/ranges_replace_if.h>
2061# include <__algorithm/ranges_reverse.h>
2062# include <__algorithm/ranges_reverse_copy.h>
2063# include <__algorithm/ranges_rotate.h>
2064# include <__algorithm/ranges_rotate_copy.h>
2065# include <__algorithm/ranges_sample.h>
2066# include <__algorithm/ranges_search.h>
2067# include <__algorithm/ranges_search_n.h>
2068# include <__algorithm/ranges_set_difference.h>
2069# include <__algorithm/ranges_set_intersection.h>
2070# include <__algorithm/ranges_set_symmetric_difference.h>
2071# include <__algorithm/ranges_set_union.h>
2072# include <__algorithm/ranges_shuffle.h>
2073# include <__algorithm/ranges_sort.h>
2074# include <__algorithm/ranges_sort_heap.h>
2075# include <__algorithm/ranges_stable_partition.h>
2076# include <__algorithm/ranges_stable_sort.h>
2077# include <__algorithm/ranges_swap_ranges.h>
2078# include <__algorithm/ranges_transform.h>
2079# include <__algorithm/ranges_unique.h>
2080# include <__algorithm/ranges_unique_copy.h>
2081# include <__algorithm/ranges_upper_bound.h>
2082# include <__algorithm/shift_left.h>
2083# include <__algorithm/shift_right.h>
2084# endif
2085
2086# if _LIBCPP_STD_VER >= 23
2087# include <__algorithm/ranges_contains_subrange.h>
2088# include <__algorithm/ranges_ends_with.h>
2089# include <__algorithm/ranges_find_last.h>
2090# include <__algorithm/ranges_fold.h>
2091# include <__algorithm/ranges_shift_left.h>
2092# include <__algorithm/ranges_shift_right.h>
2093# include <__algorithm/ranges_starts_with.h>
2094# endif // _LIBCPP_STD_VER >= 23
2095
2096# include <version>
2097
2098// standard-mandated includes
2099
2100// [algorithm.syn]
2101# include <initializer_list>
2102
2103# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2104# pragma GCC system_header
2105# endif
2106
2107# if defined(_LIBCPP_KEEP_TRANSITIVE_INCLUDES_LLVM23) && _LIBCPP_STD_VER == 14
2108# include <execution>
2109# endif
2110
2111# if defined(_LIBCPP_KEEP_TRANSITIVE_INCLUDES_LLVM23) && _LIBCPP_STD_VER <= 20
2112# include <atomic>
2113# include <bit>
2114# include <concepts>
2115# include <cstdlib>
2116# include <cstring>
2117# include <iterator>
2118# include <memory>
2119# include <optional>
2120# include <stdexcept>
2121# include <type_traits>
2122# include <utility>
2123# endif
2124#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
2125
2126#endif // _LIBCPP_ALGORITHM
2127