xref: /llvm-project/libcxx/include/algorithm (revision 1e77b396ffe46b165bcdafdf79077a9d1da6c255)
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  template <class I, class F>
23    struct in_fun_result; // since C++20
24
25  template <class I1, class I2>
26    struct in_in_result;     // since C++20
27
28  template <class I1, class I2, class O>
29    struct in_in_out_result; // since C++20
30
31  template <class I, class O1, class O2>
32    struct in_out_out_result; // since C++20
33
34  template<class I, class O>
35    struct in_out_result; // since C++20
36}
37
38template <class InputIterator, class Predicate>
39    constexpr bool     // constexpr in C++20
40    all_of(InputIterator first, InputIterator last, Predicate pred);
41
42template <class InputIterator, class Predicate>
43    constexpr bool     // constexpr in C++20
44    any_of(InputIterator first, InputIterator last, Predicate pred);
45
46template <class InputIterator, class Predicate>
47    constexpr bool     // constexpr in C++20
48    none_of(InputIterator first, InputIterator last, Predicate pred);
49
50template <class InputIterator, class Function>
51    constexpr Function          // constexpr in C++20
52    for_each(InputIterator first, InputIterator last, Function f);
53
54template<class InputIterator, class Size, class Function>
55    constexpr InputIterator     // constexpr in C++20
56    for_each_n(InputIterator first, Size n, Function f); // C++17
57
58template <class InputIterator, class T>
59    constexpr InputIterator     // constexpr in C++20
60    find(InputIterator first, InputIterator last, const T& value);
61
62template <class InputIterator, class Predicate>
63    constexpr InputIterator     // constexpr in C++20
64    find_if(InputIterator first, InputIterator last, Predicate pred);
65
66template<class InputIterator, class Predicate>
67    constexpr InputIterator     // constexpr in C++20
68    find_if_not(InputIterator first, InputIterator last, Predicate pred);
69
70template <class ForwardIterator1, class ForwardIterator2>
71    constexpr ForwardIterator1  // constexpr in C++20
72    find_end(ForwardIterator1 first1, ForwardIterator1 last1,
73             ForwardIterator2 first2, ForwardIterator2 last2);
74
75template <class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
76    constexpr ForwardIterator1  // constexpr in C++20
77    find_end(ForwardIterator1 first1, ForwardIterator1 last1,
78             ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred);
79
80template <class ForwardIterator1, class ForwardIterator2>
81    constexpr ForwardIterator1  // constexpr in C++20
82    find_first_of(ForwardIterator1 first1, ForwardIterator1 last1,
83                  ForwardIterator2 first2, ForwardIterator2 last2);
84
85template <class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
86    constexpr ForwardIterator1  // constexpr in C++20
87    find_first_of(ForwardIterator1 first1, ForwardIterator1 last1,
88                  ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred);
89
90template <class ForwardIterator>
91    constexpr ForwardIterator   // constexpr in C++20
92    adjacent_find(ForwardIterator first, ForwardIterator last);
93
94template <class ForwardIterator, class BinaryPredicate>
95    constexpr ForwardIterator   // constexpr in C++20
96    adjacent_find(ForwardIterator first, ForwardIterator last, BinaryPredicate pred);
97
98template <class InputIterator, class T>
99    constexpr typename iterator_traits<InputIterator>::difference_type  // constexpr in C++20
100    count(InputIterator first, InputIterator last, const T& value);
101
102template <class InputIterator, class Predicate>
103    constexpr typename iterator_traits<InputIterator>::difference_type // constexpr in C++20
104    count_if(InputIterator first, InputIterator last, Predicate pred);
105
106template <class InputIterator1, class InputIterator2>
107    constexpr pair<InputIterator1, InputIterator2>   // constexpr in C++20
108    mismatch(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2);
109
110template <class InputIterator1, class InputIterator2>
111    constexpr pair<InputIterator1, InputIterator2>   // constexpr in C++20
112    mismatch(InputIterator1 first1, InputIterator1 last1,
113             InputIterator2 first2, InputIterator2 last2); // **C++14**
114
115template <class InputIterator1, class InputIterator2, class BinaryPredicate>
116    constexpr pair<InputIterator1, InputIterator2>   // constexpr in C++20
117    mismatch(InputIterator1 first1, InputIterator1 last1,
118             InputIterator2 first2, BinaryPredicate pred);
119
120template <class InputIterator1, class InputIterator2, class BinaryPredicate>
121    constexpr pair<InputIterator1, InputIterator2>   // constexpr in C++20
122    mismatch(InputIterator1 first1, InputIterator1 last1,
123             InputIterator2 first2, InputIterator2 last2,
124             BinaryPredicate pred); // **C++14**
125
126template <class InputIterator1, class InputIterator2>
127    constexpr bool      // constexpr in C++20
128    equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2);
129
130template <class InputIterator1, class InputIterator2>
131    constexpr bool      // constexpr in C++20
132    equal(InputIterator1 first1, InputIterator1 last1,
133          InputIterator2 first2, InputIterator2 last2); // **C++14**
134
135template <class InputIterator1, class InputIterator2, class BinaryPredicate>
136    constexpr bool      // constexpr in C++20
137    equal(InputIterator1 first1, InputIterator1 last1,
138          InputIterator2 first2, BinaryPredicate pred);
139
140template <class InputIterator1, class InputIterator2, class BinaryPredicate>
141    constexpr bool      // constexpr in C++20
142    equal(InputIterator1 first1, InputIterator1 last1,
143          InputIterator2 first2, InputIterator2 last2,
144          BinaryPredicate pred); // **C++14**
145
146template<class ForwardIterator1, class ForwardIterator2>
147    constexpr bool      // constexpr in C++20
148    is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
149                   ForwardIterator2 first2);
150
151template<class ForwardIterator1, class ForwardIterator2>
152    constexpr bool      // constexpr in C++20
153    is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
154                   ForwardIterator2 first2, ForwardIterator2 last2); // **C++14**
155
156template<class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
157    constexpr bool      // constexpr in C++20
158    is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
159                   ForwardIterator2 first2, BinaryPredicate pred);
160
161template<class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
162    constexpr bool      // constexpr in C++20
163    is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
164                   ForwardIterator2 first2, ForwardIterator2 last2,
165                   BinaryPredicate pred);  // **C++14**
166
167template <class ForwardIterator1, class ForwardIterator2>
168    constexpr ForwardIterator1      // constexpr in C++20
169    search(ForwardIterator1 first1, ForwardIterator1 last1,
170           ForwardIterator2 first2, ForwardIterator2 last2);
171
172template <class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
173    constexpr ForwardIterator1      // constexpr in C++20
174    search(ForwardIterator1 first1, ForwardIterator1 last1,
175           ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred);
176
177template <class ForwardIterator, class Size, class T>
178    constexpr ForwardIterator       // constexpr in C++20
179    search_n(ForwardIterator first, ForwardIterator last, Size count, const T& value);
180
181template <class ForwardIterator, class Size, class T, class BinaryPredicate>
182    constexpr ForwardIterator       // constexpr in C++20
183    search_n(ForwardIterator first, ForwardIterator last,
184             Size count, const T& value, BinaryPredicate pred);
185
186template <class InputIterator, class OutputIterator>
187    constexpr OutputIterator      // constexpr in C++20
188    copy(InputIterator first, InputIterator last, OutputIterator result);
189
190template<class InputIterator, class OutputIterator, class Predicate>
191    constexpr OutputIterator      // constexpr in C++20
192    copy_if(InputIterator first, InputIterator last,
193            OutputIterator result, Predicate pred);
194
195template<class InputIterator, class Size, class OutputIterator>
196    constexpr OutputIterator      // constexpr in C++20
197    copy_n(InputIterator first, Size n, OutputIterator result);
198
199template <class BidirectionalIterator1, class BidirectionalIterator2>
200    constexpr BidirectionalIterator2      // constexpr in C++20
201    copy_backward(BidirectionalIterator1 first, BidirectionalIterator1 last,
202                  BidirectionalIterator2 result);
203
204template <class ForwardIterator1, class ForwardIterator2>
205    constexpr ForwardIterator2    // constexpr in C++20
206    swap_ranges(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2);
207
208template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2>
209        requires indirectly_swappable<I1, I2>
210    constexpr ranges::swap_ranges_result<I1, I2>
211        ranges::swap_ranges(I1 first1, S1 last1, I2 first2, S2 last2);
212
213template<input_range R1, input_range R2>
214        requires indirectly_swappable<iterator_t<R1>, iterator_t<R2>>
215    constexpr ranges::swap_ranges_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>>
216        ranges::swap_ranges(R1&& r1, R2&& r2);
217
218template <class ForwardIterator1, class ForwardIterator2>
219    constexpr void                // constexpr in C++20
220    iter_swap(ForwardIterator1 a, ForwardIterator2 b);
221
222template <class InputIterator, class OutputIterator, class UnaryOperation>
223    constexpr OutputIterator      // constexpr in C++20
224    transform(InputIterator first, InputIterator last, OutputIterator result, UnaryOperation op);
225
226template <class InputIterator1, class InputIterator2, class OutputIterator, class BinaryOperation>
227    constexpr OutputIterator      // constexpr in C++20
228    transform(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2,
229              OutputIterator result, BinaryOperation binary_op);
230
231template <class ForwardIterator, class T>
232    constexpr void      // constexpr in C++20
233    replace(ForwardIterator first, ForwardIterator last, const T& old_value, const T& new_value);
234
235template <class ForwardIterator, class Predicate, class T>
236    constexpr void      // constexpr in C++20
237    replace_if(ForwardIterator first, ForwardIterator last, Predicate pred, const T& new_value);
238
239template <class InputIterator, class OutputIterator, class T>
240    constexpr OutputIterator      // constexpr in C++20
241    replace_copy(InputIterator first, InputIterator last, OutputIterator result,
242                 const T& old_value, const T& new_value);
243
244template <class InputIterator, class OutputIterator, class Predicate, class T>
245    constexpr OutputIterator      // constexpr in C++20
246    replace_copy_if(InputIterator first, InputIterator last, OutputIterator result, Predicate pred, const T& new_value);
247
248template <class ForwardIterator, class T>
249    constexpr void      // constexpr in C++20
250    fill(ForwardIterator first, ForwardIterator last, const T& value);
251
252template <class OutputIterator, class Size, class T>
253    constexpr OutputIterator      // constexpr in C++20
254    fill_n(OutputIterator first, Size n, const T& value);
255
256template <class ForwardIterator, class Generator>
257    constexpr void      // constexpr in C++20
258    generate(ForwardIterator first, ForwardIterator last, Generator gen);
259
260template <class OutputIterator, class Size, class Generator>
261    constexpr OutputIterator      // constexpr in C++20
262    generate_n(OutputIterator first, Size n, Generator gen);
263
264template <class ForwardIterator, class T>
265    constexpr ForwardIterator     // constexpr in C++20
266    remove(ForwardIterator first, ForwardIterator last, const T& value);
267
268template <class ForwardIterator, class Predicate>
269    constexpr ForwardIterator     // constexpr in C++20
270    remove_if(ForwardIterator first, ForwardIterator last, Predicate pred);
271
272template <class InputIterator, class OutputIterator, class T>
273    constexpr OutputIterator     // constexpr in C++20
274    remove_copy(InputIterator first, InputIterator last, OutputIterator result, const T& value);
275
276template <class InputIterator, class OutputIterator, class Predicate>
277    constexpr OutputIterator     // constexpr in C++20
278    remove_copy_if(InputIterator first, InputIterator last, OutputIterator result, Predicate pred);
279
280template <class ForwardIterator>
281    constexpr ForwardIterator    // constexpr in C++20
282    unique(ForwardIterator first, ForwardIterator last);
283
284template <class ForwardIterator, class BinaryPredicate>
285    constexpr ForwardIterator    // constexpr in C++20
286    unique(ForwardIterator first, ForwardIterator last, BinaryPredicate pred);
287
288template <class InputIterator, class OutputIterator>
289    constexpr OutputIterator     // constexpr in C++20
290    unique_copy(InputIterator first, InputIterator last, OutputIterator result);
291
292template <class InputIterator, class OutputIterator, class BinaryPredicate>
293    constexpr OutputIterator     // constexpr in C++20
294    unique_copy(InputIterator first, InputIterator last, OutputIterator result, BinaryPredicate pred);
295
296template <class BidirectionalIterator>
297    constexpr void               // constexpr in C++20
298    reverse(BidirectionalIterator first, BidirectionalIterator last);
299
300template <class BidirectionalIterator, class OutputIterator>
301    constexpr OutputIterator       // constexpr in C++20
302    reverse_copy(BidirectionalIterator first, BidirectionalIterator last, OutputIterator result);
303
304template <class ForwardIterator>
305    constexpr ForwardIterator      // constexpr in C++20
306    rotate(ForwardIterator first, ForwardIterator middle, ForwardIterator last);
307
308template <class ForwardIterator, class OutputIterator>
309    constexpr OutputIterator       // constexpr in C++20
310    rotate_copy(ForwardIterator first, ForwardIterator middle, ForwardIterator last, OutputIterator result);
311
312template <class RandomAccessIterator>
313    void
314    random_shuffle(RandomAccessIterator first, RandomAccessIterator last); // deprecated in C++14, removed in C++17
315
316template <class RandomAccessIterator, class RandomNumberGenerator>
317    void
318    random_shuffle(RandomAccessIterator first, RandomAccessIterator last,
319                   RandomNumberGenerator& rand);  // deprecated in C++14, removed in C++17
320
321template<class PopulationIterator, class SampleIterator,
322         class Distance, class UniformRandomBitGenerator>
323    SampleIterator sample(PopulationIterator first, PopulationIterator last,
324                          SampleIterator out, Distance n,
325                          UniformRandomBitGenerator&& g); // C++17
326
327template<class RandomAccessIterator, class UniformRandomNumberGenerator>
328    void shuffle(RandomAccessIterator first, RandomAccessIterator last,
329                 UniformRandomNumberGenerator&& g);
330
331template<class ForwardIterator>
332  constexpr ForwardIterator
333    shift_left(ForwardIterator first, ForwardIterator last,
334               typename iterator_traits<ForwardIterator>::difference_type n); // C++20
335
336template<class ForwardIterator>
337  constexpr ForwardIterator
338    shift_right(ForwardIterator first, ForwardIterator last,
339                typename iterator_traits<ForwardIterator>::difference_type n); // C++20
340
341template <class InputIterator, class Predicate>
342    constexpr bool  // constexpr in C++20
343    is_partitioned(InputIterator first, InputIterator last, Predicate pred);
344
345template <class ForwardIterator, class Predicate>
346    constexpr ForwardIterator  // constexpr in C++20
347    partition(ForwardIterator first, ForwardIterator last, Predicate pred);
348
349template <class InputIterator, class OutputIterator1,
350          class OutputIterator2, class Predicate>
351    constexpr pair<OutputIterator1, OutputIterator2>   // constexpr in C++20
352    partition_copy(InputIterator first, InputIterator last,
353                   OutputIterator1 out_true, OutputIterator2 out_false,
354                   Predicate pred);
355
356template <class ForwardIterator, class Predicate>
357    ForwardIterator
358    stable_partition(ForwardIterator first, ForwardIterator last, Predicate pred);
359
360template<class ForwardIterator, class Predicate>
361    constexpr ForwardIterator  // constexpr in C++20
362    partition_point(ForwardIterator first, ForwardIterator last, Predicate pred);
363
364template <class ForwardIterator>
365    constexpr bool  // constexpr in C++20
366    is_sorted(ForwardIterator first, ForwardIterator last);
367
368template <class ForwardIterator, class Compare>
369    constexpr bool  // constexpr in C++20
370    is_sorted(ForwardIterator first, ForwardIterator last, Compare comp);
371
372template<class ForwardIterator>
373    constexpr ForwardIterator    // constexpr in C++20
374    is_sorted_until(ForwardIterator first, ForwardIterator last);
375
376template <class ForwardIterator, class Compare>
377    constexpr ForwardIterator    // constexpr in C++20
378    is_sorted_until(ForwardIterator first, ForwardIterator last, Compare comp);
379
380template <class RandomAccessIterator>
381    constexpr void               // constexpr in C++20
382    sort(RandomAccessIterator first, RandomAccessIterator last);
383
384template <class RandomAccessIterator, class Compare>
385    constexpr void               // constexpr in C++20
386    sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
387
388template <class RandomAccessIterator>
389    void
390    stable_sort(RandomAccessIterator first, RandomAccessIterator last);
391
392template <class RandomAccessIterator, class Compare>
393    void
394    stable_sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
395
396template <class RandomAccessIterator>
397    constexpr void                    // constexpr in C++20
398    partial_sort(RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last);
399
400template <class RandomAccessIterator, class Compare>
401    constexpr void                    // constexpr in C++20
402    partial_sort(RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last, Compare comp);
403
404template <class InputIterator, class RandomAccessIterator>
405    constexpr RandomAccessIterator    // constexpr in C++20
406    partial_sort_copy(InputIterator first, InputIterator last,
407                      RandomAccessIterator result_first, RandomAccessIterator result_last);
408
409template <class InputIterator, class RandomAccessIterator, class Compare>
410    constexpr RandomAccessIterator    // constexpr in C++20
411    partial_sort_copy(InputIterator first, InputIterator last,
412                      RandomAccessIterator result_first, RandomAccessIterator result_last, Compare comp);
413
414template <class RandomAccessIterator>
415    constexpr void                    // constexpr in C++20
416    nth_element(RandomAccessIterator first, RandomAccessIterator nth, RandomAccessIterator last);
417
418template <class RandomAccessIterator, class Compare>
419    constexpr void                    // constexpr in C++20
420    nth_element(RandomAccessIterator first, RandomAccessIterator nth, RandomAccessIterator last, Compare comp);
421
422template <class ForwardIterator, class T>
423    constexpr ForwardIterator                         // constexpr in C++20
424    lower_bound(ForwardIterator first, ForwardIterator last, const T& value);
425
426template <class ForwardIterator, class T, class Compare>
427    constexpr ForwardIterator                         // constexpr in C++20
428    lower_bound(ForwardIterator first, ForwardIterator last, const T& value, Compare comp);
429
430template <class ForwardIterator, class T>
431    constexpr ForwardIterator                         // constexpr in C++20
432    upper_bound(ForwardIterator first, ForwardIterator last, const T& value);
433
434template <class ForwardIterator, class T, class Compare>
435    constexpr ForwardIterator                         // constexpr in C++20
436    upper_bound(ForwardIterator first, ForwardIterator last, const T& value, Compare comp);
437
438template <class ForwardIterator, class T>
439    constexpr pair<ForwardIterator, ForwardIterator>  // constexpr in C++20
440    equal_range(ForwardIterator first, ForwardIterator last, const T& value);
441
442template <class ForwardIterator, class T, class Compare>
443    constexpr pair<ForwardIterator, ForwardIterator>  // constexpr in C++20
444    equal_range(ForwardIterator first, ForwardIterator last, const T& value, Compare comp);
445
446template <class ForwardIterator, class T>
447    constexpr bool                                    // constexpr in C++20
448    binary_search(ForwardIterator first, ForwardIterator last, const T& value);
449
450template <class ForwardIterator, class T, class Compare>
451    constexpr bool                                    // constexpr in C++20
452    binary_search(ForwardIterator first, ForwardIterator last, const T& value, Compare comp);
453
454template <class InputIterator1, class InputIterator2, class OutputIterator>
455    constexpr OutputIterator                          // constexpr in C++20
456    merge(InputIterator1 first1, InputIterator1 last1,
457          InputIterator2 first2, InputIterator2 last2, OutputIterator result);
458
459template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
460    constexpr OutputIterator                          // constexpr in C++20
461    merge(InputIterator1 first1, InputIterator1 last1,
462          InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
463
464template <class BidirectionalIterator>
465    void
466    inplace_merge(BidirectionalIterator first, BidirectionalIterator middle, BidirectionalIterator last);
467
468template <class BidirectionalIterator, class Compare>
469    void
470    inplace_merge(BidirectionalIterator first, BidirectionalIterator middle, BidirectionalIterator last, Compare comp);
471
472template <class InputIterator1, class InputIterator2>
473    constexpr bool                                    // constexpr in C++20
474    includes(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2);
475
476template <class InputIterator1, class InputIterator2, class Compare>
477    constexpr bool                                    // constexpr in C++20
478    includes(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, Compare comp);
479
480template <class InputIterator1, class InputIterator2, class OutputIterator>
481    constexpr OutputIterator                          // constexpr in C++20
482    set_union(InputIterator1 first1, InputIterator1 last1,
483              InputIterator2 first2, InputIterator2 last2, OutputIterator result);
484
485template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
486    constexpr OutputIterator                          // constexpr in C++20
487    set_union(InputIterator1 first1, InputIterator1 last1,
488              InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
489
490template <class InputIterator1, class InputIterator2, class OutputIterator>
491    constexpr OutputIterator                         // constexpr in C++20
492    set_intersection(InputIterator1 first1, InputIterator1 last1,
493                     InputIterator2 first2, InputIterator2 last2, OutputIterator result);
494
495template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
496    constexpr OutputIterator                         // constexpr in C++20
497    set_intersection(InputIterator1 first1, InputIterator1 last1,
498                     InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
499
500template <class InputIterator1, class InputIterator2, class OutputIterator>
501    constexpr OutputIterator                         // constexpr in C++20
502    set_difference(InputIterator1 first1, InputIterator1 last1,
503                   InputIterator2 first2, InputIterator2 last2, OutputIterator result);
504
505template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
506    constexpr OutputIterator                         // constexpr in C++20
507    set_difference(InputIterator1 first1, InputIterator1 last1,
508                   InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
509
510template <class InputIterator1, class InputIterator2, class OutputIterator>
511    constexpr OutputIterator                         // constexpr in C++20
512    set_symmetric_difference(InputIterator1 first1, InputIterator1 last1,
513                             InputIterator2 first2, InputIterator2 last2, OutputIterator result);
514
515template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
516    constexpr OutputIterator                         // constexpr in C++20
517    set_symmetric_difference(InputIterator1 first1, InputIterator1 last1,
518                             InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
519
520template <class RandomAccessIterator>
521    constexpr void                                   // constexpr in C++20
522    push_heap(RandomAccessIterator first, RandomAccessIterator last);
523
524template <class RandomAccessIterator, class Compare>
525    constexpr void                                   // constexpr in C++20
526    push_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
527
528template <class RandomAccessIterator>
529    constexpr void                                   // constexpr in C++20
530    pop_heap(RandomAccessIterator first, RandomAccessIterator last);
531
532template <class RandomAccessIterator, class Compare>
533    constexpr void                                   // constexpr in C++20
534    pop_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
535
536template <class RandomAccessIterator>
537    constexpr void                                   // constexpr in C++20
538    make_heap(RandomAccessIterator first, RandomAccessIterator last);
539
540template <class RandomAccessIterator, class Compare>
541    constexpr void                                   // constexpr in C++20
542    make_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
543
544template <class RandomAccessIterator>
545    constexpr void                                   // constexpr in C++20
546    sort_heap(RandomAccessIterator first, RandomAccessIterator last);
547
548template <class RandomAccessIterator, class Compare>
549    constexpr void                                   // constexpr in C++20
550    sort_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
551
552template <class RandomAccessIterator>
553    constexpr bool   // constexpr in C++20
554    is_heap(RandomAccessIterator first, RandomAccessiterator last);
555
556template <class RandomAccessIterator, class Compare>
557    constexpr bool   // constexpr in C++20
558    is_heap(RandomAccessIterator first, RandomAccessiterator last, Compare comp);
559
560template <class RandomAccessIterator>
561    constexpr RandomAccessIterator   // constexpr in C++20
562    is_heap_until(RandomAccessIterator first, RandomAccessiterator last);
563
564template <class RandomAccessIterator, class Compare>
565    constexpr RandomAccessIterator   // constexpr in C++20
566    is_heap_until(RandomAccessIterator first, RandomAccessiterator last, Compare comp);
567
568template <class ForwardIterator>
569    constexpr ForwardIterator        // constexpr in C++14
570    min_element(ForwardIterator first, ForwardIterator last);
571
572template <class ForwardIterator, class Compare>
573    constexpr ForwardIterator        // constexpr in C++14
574    min_element(ForwardIterator first, ForwardIterator last, Compare comp);
575
576template <class T>
577    constexpr const T&               // constexpr in C++14
578    min(const T& a, const T& b);
579
580template <class T, class Compare>
581    constexpr const T&               // constexpr in C++14
582    min(const T& a, const T& b, Compare comp);
583
584template<class T>
585    constexpr T                      // constexpr in C++14
586    min(initializer_list<T> t);
587
588template<class T, class Compare>
589    constexpr T                      // constexpr in C++14
590    min(initializer_list<T> t, Compare comp);
591
592template<class T>
593    constexpr const T& clamp(const T& v, const T& lo, const T& hi);               // C++17
594
595template<class T, class Compare>
596    constexpr const T& clamp(const T& v, const T& lo, const T& hi, Compare comp); // C++17
597
598template <class ForwardIterator>
599    constexpr ForwardIterator        // constexpr in C++14
600    max_element(ForwardIterator first, ForwardIterator last);
601
602template <class ForwardIterator, class Compare>
603    constexpr ForwardIterator        // constexpr in C++14
604    max_element(ForwardIterator first, ForwardIterator last, Compare comp);
605
606template <class T>
607    constexpr const T&               // constexpr in C++14
608    max(const T& a, const T& b);
609
610template <class T, class Compare>
611    constexpr const T&               // constexpr in C++14
612    max(const T& a, const T& b, Compare comp);
613
614template<class T>
615    constexpr T                      // constexpr in C++14
616    max(initializer_list<T> t);
617
618template<class T, class Compare>
619    constexpr T                      // constexpr in C++14
620    max(initializer_list<T> t, Compare comp);
621
622template<class ForwardIterator>
623    constexpr pair<ForwardIterator, ForwardIterator>  // constexpr in C++14
624    minmax_element(ForwardIterator first, ForwardIterator last);
625
626template<class ForwardIterator, class Compare>
627    constexpr pair<ForwardIterator, ForwardIterator>  // constexpr in C++14
628    minmax_element(ForwardIterator first, ForwardIterator last, Compare comp);
629
630template<class T>
631    constexpr pair<const T&, const T&>  // constexpr in C++14
632    minmax(const T& a, const T& b);
633
634template<class T, class Compare>
635    constexpr pair<const T&, const T&>  // constexpr in C++14
636    minmax(const T& a, const T& b, Compare comp);
637
638template<class T>
639    constexpr pair<T, T>                // constexpr in C++14
640    minmax(initializer_list<T> t);
641
642template<class T, class Compare>
643    constexpr pair<T, T>                // constexpr in C++14
644    minmax(initializer_list<T> t, Compare comp);
645
646template <class InputIterator1, class InputIterator2>
647    constexpr bool     // constexpr in C++20
648    lexicographical_compare(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2);
649
650template <class InputIterator1, class InputIterator2, class Compare>
651    constexpr bool     // constexpr in C++20
652    lexicographical_compare(InputIterator1 first1, InputIterator1 last1,
653                            InputIterator2 first2, InputIterator2 last2, Compare comp);
654
655template <class BidirectionalIterator>
656    constexpr bool     // constexpr in C++20
657    next_permutation(BidirectionalIterator first, BidirectionalIterator last);
658
659template <class BidirectionalIterator, class Compare>
660    constexpr bool     // constexpr in C++20
661    next_permutation(BidirectionalIterator first, BidirectionalIterator last, Compare comp);
662
663template <class BidirectionalIterator>
664    constexpr bool     // constexpr in C++20
665    prev_permutation(BidirectionalIterator first, BidirectionalIterator last);
666
667template <class BidirectionalIterator, class Compare>
668    constexpr bool     // constexpr in C++20
669    prev_permutation(BidirectionalIterator first, BidirectionalIterator last, Compare comp);
670}  // std
671
672*/
673
674#include <__bits>
675#include <__config>
676#include <__debug>
677#include <cstddef>
678#include <cstring>
679#include <functional>
680#include <initializer_list>
681#include <iterator>
682#include <memory>
683#include <type_traits>
684#include <utility>
685#include <version>
686
687#include <__algorithm/adjacent_find.h>
688#include <__algorithm/all_of.h>
689#include <__algorithm/any_of.h>
690#include <__algorithm/binary_search.h>
691#include <__algorithm/clamp.h>
692#include <__algorithm/comp.h>
693#include <__algorithm/comp_ref_type.h>
694#include <__algorithm/copy.h>
695#include <__algorithm/copy_backward.h>
696#include <__algorithm/copy_if.h>
697#include <__algorithm/copy_n.h>
698#include <__algorithm/count.h>
699#include <__algorithm/count_if.h>
700#include <__algorithm/equal.h>
701#include <__algorithm/equal_range.h>
702#include <__algorithm/fill.h>
703#include <__algorithm/fill_n.h>
704#include <__algorithm/find.h>
705#include <__algorithm/find_end.h>
706#include <__algorithm/find_first_of.h>
707#include <__algorithm/find_if.h>
708#include <__algorithm/find_if_not.h>
709#include <__algorithm/for_each.h>
710#include <__algorithm/for_each_n.h>
711#include <__algorithm/generate.h>
712#include <__algorithm/generate_n.h>
713#include <__algorithm/half_positive.h>
714#include <__algorithm/in_fun_result.h>
715#include <__algorithm/in_in_out_result.h>
716#include <__algorithm/in_in_result.h>
717#include <__algorithm/in_out_out_result.h>
718#include <__algorithm/in_out_result.h>
719#include <__algorithm/includes.h>
720#include <__algorithm/inplace_merge.h>
721#include <__algorithm/is_heap.h>
722#include <__algorithm/is_heap_until.h>
723#include <__algorithm/is_partitioned.h>
724#include <__algorithm/is_permutation.h>
725#include <__algorithm/is_sorted.h>
726#include <__algorithm/is_sorted_until.h>
727#include <__algorithm/iter_swap.h>
728#include <__algorithm/lexicographical_compare.h>
729#include <__algorithm/lower_bound.h>
730#include <__algorithm/make_heap.h>
731#include <__algorithm/max.h>
732#include <__algorithm/max_element.h>
733#include <__algorithm/merge.h>
734#include <__algorithm/min.h>
735#include <__algorithm/min_element.h>
736#include <__algorithm/minmax.h>
737#include <__algorithm/minmax_element.h>
738#include <__algorithm/mismatch.h>
739#include <__algorithm/move.h>
740#include <__algorithm/move_backward.h>
741#include <__algorithm/next_permutation.h>
742#include <__algorithm/none_of.h>
743#include <__algorithm/nth_element.h>
744#include <__algorithm/partial_sort.h>
745#include <__algorithm/partial_sort_copy.h>
746#include <__algorithm/partition.h>
747#include <__algorithm/partition_copy.h>
748#include <__algorithm/partition_point.h>
749#include <__algorithm/pop_heap.h>
750#include <__algorithm/prev_permutation.h>
751#include <__algorithm/push_heap.h>
752#include <__algorithm/ranges_swap_ranges.h>
753#include <__algorithm/remove.h>
754#include <__algorithm/remove_copy.h>
755#include <__algorithm/remove_copy_if.h>
756#include <__algorithm/remove_if.h>
757#include <__algorithm/replace.h>
758#include <__algorithm/replace_copy.h>
759#include <__algorithm/replace_copy_if.h>
760#include <__algorithm/replace_if.h>
761#include <__algorithm/reverse.h>
762#include <__algorithm/reverse_copy.h>
763#include <__algorithm/rotate.h>
764#include <__algorithm/rotate_copy.h>
765#include <__algorithm/sample.h>
766#include <__algorithm/search.h>
767#include <__algorithm/search_n.h>
768#include <__algorithm/set_difference.h>
769#include <__algorithm/set_intersection.h>
770#include <__algorithm/set_symmetric_difference.h>
771#include <__algorithm/set_union.h>
772#include <__algorithm/shift_left.h>
773#include <__algorithm/shift_right.h>
774#include <__algorithm/shuffle.h>
775#include <__algorithm/sift_down.h>
776#include <__algorithm/sort.h>
777#include <__algorithm/sort_heap.h>
778#include <__algorithm/stable_partition.h>
779#include <__algorithm/stable_sort.h>
780#include <__algorithm/swap_ranges.h>
781#include <__algorithm/transform.h>
782#include <__algorithm/unique.h>
783#include <__algorithm/unique_copy.h>
784#include <__algorithm/unwrap_iter.h>
785#include <__algorithm/upper_bound.h>
786
787#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
788#  pragma GCC system_header
789#endif
790
791#if defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS) && _LIBCPP_STD_VER >= 17
792#   include <__pstl_algorithm>
793#endif
794
795#endif // _LIBCPP_ALGORITHM
796