blob: 51a1781450fe2b5900caf791dde2961cc0d51712 [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
Louis Dionne9bd93882021-11-17 16:25:01 -05002//===----------------------------------------------------------------------===//
Howard Hinnantc51e1022010-05-11 19:42:16 +00003//
Chandler Carruthd2012102019-01-19 10:56:40 +00004// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Howard Hinnantc51e1022010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_ALGORITHM
11#define _LIBCPP_ALGORITHM
12
13/*
14 algorithm synopsis
15
16#include <initializer_list>
17
18namespace std
19{
20
Nikolas Klauserf74be4e2022-01-14 02:55:51 +010021namespace ranges {
Nikolas Klauser671b4752022-02-11 17:01:58 +010022 template <class I, class F>
Nikolas Klauser2e263162022-02-21 22:48:36 +010023 struct in_fun_result; // since C++20
Nikolas Klauser671b4752022-02-11 17:01:58 +010024
Nikolas Klauserf74be4e2022-01-14 02:55:51 +010025 template <class I1, class I2>
Nikolas Klauser2e263162022-02-21 22:48:36 +010026 struct in_in_result; // since C++20
Nikolas Klauser05e2cd82022-01-25 11:21:47 +010027
28 template <class I1, class I2, class O>
Nikolas Klauser2e263162022-02-21 22:48:36 +010029 struct in_in_out_result; // since C++20
Nikolas Klauser61ce8162022-02-03 02:17:03 +010030
31 template <class I, class O1, class O2>
32 struct in_out_out_result; // since C++20
Nikolas Klauser671b4752022-02-11 17:01:58 +010033
Nikolas Klauser2e263162022-02-21 22:48:36 +010034 template <class I1, class I2>
35 struct min_max_result; // since C++20
36
Nikolas Klauserdd5ad212022-02-21 23:07:02 +010037 template <class I>
38 struct in_found_result; // since C++20
39
Nikolas Klauser0a62a172022-02-11 13:11:57 +010040 template<forward_iterator I, sentinel_for<I> S, class Proj = identity,
41 indirect_strict_weak_order<projected<I, Proj>> Comp = ranges::less> // since C++20
42 constexpr I min_element(I first, S last, Comp comp = {}, Proj proj = {});
43
44 template<forward_range R, class Proj = identity,
45 indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less> // since C++20
46 constexpr borrowed_iterator_t<R> min_element(R&& r, Comp comp = {}, Proj proj = {});
Nikolas Klauser12fc9bf2022-03-08 23:12:35 +010047
48 template <input_iterator I1, sentinel_for<_I1> S1, input_iterator I2, sentinel_for<_I2> S2,
49 class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
50 requires indirectly_comparable<I1, I2, Pred, Proj1, Proj2>
51 constexpr mismatch_result<_I1, _I2>
52 mismatch()(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}) // since C++20
53
54 template <input_range R1, input_range R2,
55 class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
56 requires indirectly_comparable<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
57 constexpr mismatch_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>>
58 mismatch(R1&& r1, R2&& r2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}) // since C++20
Nikolas Klauser37d076e2022-03-12 01:45:35 +010059
Nikolas Klauser37d076e2022-03-12 01:45:35 +010060 requires indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T*>
61 constexpr I find(I first, S last, const T& value, Proj proj = {}); // since C++20
62
63 template<input_range R, class T, class Proj = identity>
64 requires indirect_binary_predicate<ranges::equal_to, projected<iterator_t<R>, Proj>, const T*>
65 constexpr borrowed_iterator_t<R>
66 find(R&& r, const T& value, Proj proj = {}); // since C++20
67
68 template<input_iterator I, sentinel_for<I> S, class Proj = identity,
69 indirect_unary_predicate<projected<I, Proj>> Pred>
70 constexpr I find_if(I first, S last, Pred pred, Proj proj = {}); // since C++20
71
72 template<input_range R, class Proj = identity,
73 indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
74 constexpr borrowed_iterator_t<R>
75 find_if(R&& r, Pred pred, Proj proj = {}); // since C++20
76
77 template<input_iterator I, sentinel_for<I> S, class Proj = identity,
78 indirect_unary_predicate<projected<I, Proj>> Pred>
79 constexpr I find_if_not(I first, S last, Pred pred, Proj proj = {}); // since C++20
80
81 template<input_range R, class Proj = identity,
82 indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
83 constexpr borrowed_iterator_t<R>
84 find_if_not(R&& r, Pred pred, Proj proj = {}); // since C++20
Nikolas Klauser3559e452022-03-18 02:57:08 +010085
86 template<class T, class Proj = identity,
87 indirect_strict_weak_order<projected<const T*, Proj>> Comp = ranges::less>
88 constexpr const T& min(const T& a, const T& b, Comp comp = {}, Proj proj = {}); // since C++20
89
90 template<copyable T, class Proj = identity,
91 indirect_strict_weak_order<projected<const T*, Proj>> Comp = ranges::less>
92 constexpr T min(initializer_list<T> r, Comp comp = {}, Proj proj = {}); // since C++20
93
94 template<input_range R, class Proj = identity,
95 indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less>
96 requires indirectly_copyable_storable<iterator_t<R>, range_value_t<R>*>
97 constexpr range_value_t<R>
98 min(R&& r, Comp comp = {}, Proj proj = {}); // since C++20
Nikolas Klauserf74be4e2022-01-14 02:55:51 +010099}
100
Marshall Clowd607fdb2018-01-15 17:20:36 +0000101 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000102 all_of(InputIterator first, InputIterator last, Predicate pred);
103
104template <class InputIterator, class Predicate>
Marshall Clowd607fdb2018-01-15 17:20:36 +0000105 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000106 any_of(InputIterator first, InputIterator last, Predicate pred);
107
108template <class InputIterator, class Predicate>
Marshall Clowd607fdb2018-01-15 17:20:36 +0000109 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000110 none_of(InputIterator first, InputIterator last, Predicate pred);
111
112template <class InputIterator, class Function>
Marshall Clow5492c8a2018-01-22 20:44:33 +0000113 constexpr Function // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000114 for_each(InputIterator first, InputIterator last, Function f);
115
Marshall Clowde0169c2017-05-25 02:29:54 +0000116template<class InputIterator, class Size, class Function>
Marshall Clow5492c8a2018-01-22 20:44:33 +0000117 constexpr InputIterator // constexpr in C++20
118 for_each_n(InputIterator first, Size n, Function f); // C++17
Marshall Clowde0169c2017-05-25 02:29:54 +0000119
Howard Hinnantc51e1022010-05-11 19:42:16 +0000120template <class InputIterator, class T>
Marshall Clowee0161e2018-01-15 19:26:05 +0000121 constexpr InputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000122 find(InputIterator first, InputIterator last, const T& value);
123
124template <class InputIterator, class Predicate>
Marshall Clowee0161e2018-01-15 19:26:05 +0000125 constexpr InputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000126 find_if(InputIterator first, InputIterator last, Predicate pred);
127
128template<class InputIterator, class Predicate>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500129 constexpr InputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000130 find_if_not(InputIterator first, InputIterator last, Predicate pred);
131
132template <class ForwardIterator1, class ForwardIterator2>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500133 constexpr ForwardIterator1 // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000134 find_end(ForwardIterator1 first1, ForwardIterator1 last1,
135 ForwardIterator2 first2, ForwardIterator2 last2);
136
137template <class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500138 constexpr ForwardIterator1 // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000139 find_end(ForwardIterator1 first1, ForwardIterator1 last1,
140 ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred);
141
142template <class ForwardIterator1, class ForwardIterator2>
Marshall Clowee0161e2018-01-15 19:26:05 +0000143 constexpr ForwardIterator1 // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000144 find_first_of(ForwardIterator1 first1, ForwardIterator1 last1,
145 ForwardIterator2 first2, ForwardIterator2 last2);
146
147template <class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
Marshall Clowee0161e2018-01-15 19:26:05 +0000148 constexpr ForwardIterator1 // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000149 find_first_of(ForwardIterator1 first1, ForwardIterator1 last1,
150 ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred);
151
152template <class ForwardIterator>
Marshall Clowee0161e2018-01-15 19:26:05 +0000153 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000154 adjacent_find(ForwardIterator first, ForwardIterator last);
155
156template <class ForwardIterator, class BinaryPredicate>
Marshall Clowee0161e2018-01-15 19:26:05 +0000157 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000158 adjacent_find(ForwardIterator first, ForwardIterator last, BinaryPredicate pred);
159
160template <class InputIterator, class T>
Marshall Clow3c0558f2018-01-15 19:40:34 +0000161 constexpr typename iterator_traits<InputIterator>::difference_type // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000162 count(InputIterator first, InputIterator last, const T& value);
163
164template <class InputIterator, class Predicate>
Marshall Clow3c0558f2018-01-15 19:40:34 +0000165 constexpr typename iterator_traits<InputIterator>::difference_type // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000166 count_if(InputIterator first, InputIterator last, Predicate pred);
167
168template <class InputIterator1, class InputIterator2>
Marshall Clow30bf3022018-01-16 02:04:10 +0000169 constexpr pair<InputIterator1, InputIterator2> // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000170 mismatch(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2);
171
Marshall Clow96b42b22013-05-09 21:14:23 +0000172template <class InputIterator1, class InputIterator2>
Marshall Clow30bf3022018-01-16 02:04:10 +0000173 constexpr pair<InputIterator1, InputIterator2> // constexpr in C++20
Aditya Kumar3a0179a2016-08-25 11:52:38 +0000174 mismatch(InputIterator1 first1, InputIterator1 last1,
Marshall Clow96b42b22013-05-09 21:14:23 +0000175 InputIterator2 first2, InputIterator2 last2); // **C++14**
176
Howard Hinnantc51e1022010-05-11 19:42:16 +0000177template <class InputIterator1, class InputIterator2, class BinaryPredicate>
Marshall Clow30bf3022018-01-16 02:04:10 +0000178 constexpr pair<InputIterator1, InputIterator2> // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000179 mismatch(InputIterator1 first1, InputIterator1 last1,
180 InputIterator2 first2, BinaryPredicate pred);
181
Marshall Clow96b42b22013-05-09 21:14:23 +0000182template <class InputIterator1, class InputIterator2, class BinaryPredicate>
Marshall Clow30bf3022018-01-16 02:04:10 +0000183 constexpr pair<InputIterator1, InputIterator2> // constexpr in C++20
Marshall Clow96b42b22013-05-09 21:14:23 +0000184 mismatch(InputIterator1 first1, InputIterator1 last1,
185 InputIterator2 first2, InputIterator2 last2,
186 BinaryPredicate pred); // **C++14**
187
Howard Hinnantc51e1022010-05-11 19:42:16 +0000188template <class InputIterator1, class InputIterator2>
Marshall Clow30bf3022018-01-16 02:04:10 +0000189 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000190 equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2);
191
Marshall Clow96b42b22013-05-09 21:14:23 +0000192template <class InputIterator1, class InputIterator2>
Marshall Clow30bf3022018-01-16 02:04:10 +0000193 constexpr bool // constexpr in C++20
Aditya Kumar3a0179a2016-08-25 11:52:38 +0000194 equal(InputIterator1 first1, InputIterator1 last1,
Marshall Clow96b42b22013-05-09 21:14:23 +0000195 InputIterator2 first2, InputIterator2 last2); // **C++14**
196
Howard Hinnantc51e1022010-05-11 19:42:16 +0000197template <class InputIterator1, class InputIterator2, class BinaryPredicate>
Marshall Clow30bf3022018-01-16 02:04:10 +0000198 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000199 equal(InputIterator1 first1, InputIterator1 last1,
200 InputIterator2 first2, BinaryPredicate pred);
201
Marshall Clow96b42b22013-05-09 21:14:23 +0000202template <class InputIterator1, class InputIterator2, class BinaryPredicate>
Marshall Clow30bf3022018-01-16 02:04:10 +0000203 constexpr bool // constexpr in C++20
Marshall Clow96b42b22013-05-09 21:14:23 +0000204 equal(InputIterator1 first1, InputIterator1 last1,
205 InputIterator2 first2, InputIterator2 last2,
206 BinaryPredicate pred); // **C++14**
207
Howard Hinnantc51e1022010-05-11 19:42:16 +0000208template<class ForwardIterator1, class ForwardIterator2>
Marshall Clow96d050a2018-01-15 16:16:32 +0000209 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000210 is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
211 ForwardIterator2 first2);
212
Marshall Clow96b42b22013-05-09 21:14:23 +0000213template<class ForwardIterator1, class ForwardIterator2>
Marshall Clow96d050a2018-01-15 16:16:32 +0000214 constexpr bool // constexpr in C++20
Marshall Clow96b42b22013-05-09 21:14:23 +0000215 is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
216 ForwardIterator2 first2, ForwardIterator2 last2); // **C++14**
217
Howard Hinnantc51e1022010-05-11 19:42:16 +0000218template<class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
Marshall Clow96d050a2018-01-15 16:16:32 +0000219 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000220 is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
221 ForwardIterator2 first2, BinaryPredicate pred);
222
Marshall Clow96b42b22013-05-09 21:14:23 +0000223template<class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
Marshall Clow96d050a2018-01-15 16:16:32 +0000224 constexpr bool // constexpr in C++20
Marshall Clow96b42b22013-05-09 21:14:23 +0000225 is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
226 ForwardIterator2 first2, ForwardIterator2 last2,
227 BinaryPredicate pred); // **C++14**
228
Howard Hinnantc51e1022010-05-11 19:42:16 +0000229template <class ForwardIterator1, class ForwardIterator2>
Marshall Clow323fc5b2018-01-16 15:48:27 +0000230 constexpr ForwardIterator1 // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000231 search(ForwardIterator1 first1, ForwardIterator1 last1,
232 ForwardIterator2 first2, ForwardIterator2 last2);
233
234template <class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
Marshall Clow323fc5b2018-01-16 15:48:27 +0000235 constexpr ForwardIterator1 // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000236 search(ForwardIterator1 first1, ForwardIterator1 last1,
237 ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred);
238
239template <class ForwardIterator, class Size, class T>
Marshall Clow323fc5b2018-01-16 15:48:27 +0000240 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000241 search_n(ForwardIterator first, ForwardIterator last, Size count, const T& value);
242
243template <class ForwardIterator, class Size, class T, class BinaryPredicate>
Marshall Clow323fc5b2018-01-16 15:48:27 +0000244 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000245 search_n(ForwardIterator first, ForwardIterator last,
246 Size count, const T& value, BinaryPredicate pred);
247
248template <class InputIterator, class OutputIterator>
Louis Dionne65b433b2019-11-06 12:02:41 +0000249 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000250 copy(InputIterator first, InputIterator last, OutputIterator result);
251
252template<class InputIterator, class OutputIterator, class Predicate>
Louis Dionne65b433b2019-11-06 12:02:41 +0000253 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000254 copy_if(InputIterator first, InputIterator last,
255 OutputIterator result, Predicate pred);
256
257template<class InputIterator, class Size, class OutputIterator>
Louis Dionne65b433b2019-11-06 12:02:41 +0000258 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000259 copy_n(InputIterator first, Size n, OutputIterator result);
260
261template <class BidirectionalIterator1, class BidirectionalIterator2>
Louis Dionne65b433b2019-11-06 12:02:41 +0000262 constexpr BidirectionalIterator2 // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000263 copy_backward(BidirectionalIterator1 first, BidirectionalIterator1 last,
264 BidirectionalIterator2 result);
265
266template <class ForwardIterator1, class ForwardIterator2>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500267 constexpr ForwardIterator2 // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000268 swap_ranges(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2);
269
Nikolas Klauser4ceab5f2022-02-10 13:33:03 +0100270template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2>
271 requires indirectly_swappable<I1, I2>
272 constexpr ranges::swap_ranges_result<I1, I2>
273 ranges::swap_ranges(I1 first1, S1 last1, I2 first2, S2 last2);
274
275template<input_range R1, input_range R2>
276 requires indirectly_swappable<iterator_t<R1>, iterator_t<R2>>
277 constexpr ranges::swap_ranges_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>>
278 ranges::swap_ranges(R1&& r1, R2&& r2);
279
Howard Hinnantc51e1022010-05-11 19:42:16 +0000280template <class ForwardIterator1, class ForwardIterator2>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500281 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000282 iter_swap(ForwardIterator1 a, ForwardIterator2 b);
283
284template <class InputIterator, class OutputIterator, class UnaryOperation>
Marshall Clow31427c62018-01-19 17:45:39 +0000285 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000286 transform(InputIterator first, InputIterator last, OutputIterator result, UnaryOperation op);
287
288template <class InputIterator1, class InputIterator2, class OutputIterator, class BinaryOperation>
Marshall Clow31427c62018-01-19 17:45:39 +0000289 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000290 transform(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2,
291 OutputIterator result, BinaryOperation binary_op);
292
293template <class ForwardIterator, class T>
Marshall Clow01bbbd22018-01-19 18:07:29 +0000294 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000295 replace(ForwardIterator first, ForwardIterator last, const T& old_value, const T& new_value);
296
297template <class ForwardIterator, class Predicate, class T>
Marshall Clow01bbbd22018-01-19 18:07:29 +0000298 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000299 replace_if(ForwardIterator first, ForwardIterator last, Predicate pred, const T& new_value);
300
301template <class InputIterator, class OutputIterator, class T>
Marshall Clow01bbbd22018-01-19 18:07:29 +0000302 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000303 replace_copy(InputIterator first, InputIterator last, OutputIterator result,
304 const T& old_value, const T& new_value);
305
306template <class InputIterator, class OutputIterator, class Predicate, class T>
Marshall Clow01bbbd22018-01-19 18:07:29 +0000307 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000308 replace_copy_if(InputIterator first, InputIterator last, OutputIterator result, Predicate pred, const T& new_value);
309
310template <class ForwardIterator, class T>
Marshall Clowe9cdc5c2018-01-20 20:14:32 +0000311 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000312 fill(ForwardIterator first, ForwardIterator last, const T& value);
313
314template <class OutputIterator, class Size, class T>
Marshall Clowe9cdc5c2018-01-20 20:14:32 +0000315 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000316 fill_n(OutputIterator first, Size n, const T& value);
317
318template <class ForwardIterator, class Generator>
Marshall Clowe9cdc5c2018-01-20 20:14:32 +0000319 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000320 generate(ForwardIterator first, ForwardIterator last, Generator gen);
321
322template <class OutputIterator, class Size, class Generator>
Marshall Clowe9cdc5c2018-01-20 20:14:32 +0000323 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000324 generate_n(OutputIterator first, Size n, Generator gen);
325
326template <class ForwardIterator, class T>
Marshall Clow7c0fbd82018-01-22 21:43:04 +0000327 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000328 remove(ForwardIterator first, ForwardIterator last, const T& value);
329
330template <class ForwardIterator, class Predicate>
Marshall Clow7c0fbd82018-01-22 21:43:04 +0000331 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000332 remove_if(ForwardIterator first, ForwardIterator last, Predicate pred);
333
334template <class InputIterator, class OutputIterator, class T>
Marshall Clow7c0fbd82018-01-22 21:43:04 +0000335 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000336 remove_copy(InputIterator first, InputIterator last, OutputIterator result, const T& value);
337
338template <class InputIterator, class OutputIterator, class Predicate>
Marshall Clow7c0fbd82018-01-22 21:43:04 +0000339 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000340 remove_copy_if(InputIterator first, InputIterator last, OutputIterator result, Predicate pred);
341
342template <class ForwardIterator>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500343 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000344 unique(ForwardIterator first, ForwardIterator last);
345
346template <class ForwardIterator, class BinaryPredicate>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500347 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000348 unique(ForwardIterator first, ForwardIterator last, BinaryPredicate pred);
349
350template <class InputIterator, class OutputIterator>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500351 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000352 unique_copy(InputIterator first, InputIterator last, OutputIterator result);
353
354template <class InputIterator, class OutputIterator, class BinaryPredicate>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500355 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000356 unique_copy(InputIterator first, InputIterator last, OutputIterator result, BinaryPredicate pred);
357
358template <class BidirectionalIterator>
Arthur O'Dwyere50e7472020-12-17 00:01:08 -0500359 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000360 reverse(BidirectionalIterator first, BidirectionalIterator last);
361
362template <class BidirectionalIterator, class OutputIterator>
Marshall Clow7c0fbd82018-01-22 21:43:04 +0000363 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000364 reverse_copy(BidirectionalIterator first, BidirectionalIterator last, OutputIterator result);
365
366template <class ForwardIterator>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500367 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000368 rotate(ForwardIterator first, ForwardIterator middle, ForwardIterator last);
369
370template <class ForwardIterator, class OutputIterator>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500371 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000372 rotate_copy(ForwardIterator first, ForwardIterator middle, ForwardIterator last, OutputIterator result);
373
374template <class RandomAccessIterator>
375 void
Marshall Clowfac06e52017-03-23 13:43:37 +0000376 random_shuffle(RandomAccessIterator first, RandomAccessIterator last); // deprecated in C++14, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000377
378template <class RandomAccessIterator, class RandomNumberGenerator>
379 void
Marshall Clow83f35392014-03-03 06:14:19 +0000380 random_shuffle(RandomAccessIterator first, RandomAccessIterator last,
Marshall Clowfac06e52017-03-23 13:43:37 +0000381 RandomNumberGenerator& rand); // deprecated in C++14, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000382
Eric Fiselier1208fcd2016-08-28 22:14:37 +0000383template<class PopulationIterator, class SampleIterator,
384 class Distance, class UniformRandomBitGenerator>
385 SampleIterator sample(PopulationIterator first, PopulationIterator last,
386 SampleIterator out, Distance n,
387 UniformRandomBitGenerator&& g); // C++17
388
Howard Hinnant578ac0f2010-05-26 17:49:34 +0000389template<class RandomAccessIterator, class UniformRandomNumberGenerator>
390 void shuffle(RandomAccessIterator first, RandomAccessIterator last,
Howard Hinnanta5e71782010-11-18 01:47:02 +0000391 UniformRandomNumberGenerator&& g);
Howard Hinnant578ac0f2010-05-26 17:49:34 +0000392
Arthur O'Dwyercea050d2020-12-26 01:39:03 -0500393template<class ForwardIterator>
394 constexpr ForwardIterator
395 shift_left(ForwardIterator first, ForwardIterator last,
396 typename iterator_traits<ForwardIterator>::difference_type n); // C++20
397
398template<class ForwardIterator>
399 constexpr ForwardIterator
400 shift_right(ForwardIterator first, ForwardIterator last,
401 typename iterator_traits<ForwardIterator>::difference_type n); // C++20
402
Howard Hinnantc51e1022010-05-11 19:42:16 +0000403template <class InputIterator, class Predicate>
Marshall Clow96d050a2018-01-15 16:16:32 +0000404 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000405 is_partitioned(InputIterator first, InputIterator last, Predicate pred);
406
407template <class ForwardIterator, class Predicate>
Arthur O'Dwyere50e7472020-12-17 00:01:08 -0500408 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000409 partition(ForwardIterator first, ForwardIterator last, Predicate pred);
410
411template <class InputIterator, class OutputIterator1,
412 class OutputIterator2, class Predicate>
Marshall Clow5492c8a2018-01-22 20:44:33 +0000413 constexpr pair<OutputIterator1, OutputIterator2> // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000414 partition_copy(InputIterator first, InputIterator last,
415 OutputIterator1 out_true, OutputIterator2 out_false,
416 Predicate pred);
417
418template <class ForwardIterator, class Predicate>
419 ForwardIterator
420 stable_partition(ForwardIterator first, ForwardIterator last, Predicate pred);
421
422template<class ForwardIterator, class Predicate>
Marshall Clowe00916c2018-01-16 02:34:41 +0000423 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000424 partition_point(ForwardIterator first, ForwardIterator last, Predicate pred);
425
426template <class ForwardIterator>
Marshall Clow96d050a2018-01-15 16:16:32 +0000427 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000428 is_sorted(ForwardIterator first, ForwardIterator last);
429
430template <class ForwardIterator, class Compare>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500431 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000432 is_sorted(ForwardIterator first, ForwardIterator last, Compare comp);
433
434template<class ForwardIterator>
Marshall Clow3c0558f2018-01-15 19:40:34 +0000435 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000436 is_sorted_until(ForwardIterator first, ForwardIterator last);
437
438template <class ForwardIterator, class Compare>
Marshall Clow3c0558f2018-01-15 19:40:34 +0000439 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000440 is_sorted_until(ForwardIterator first, ForwardIterator last, Compare comp);
441
442template <class RandomAccessIterator>
Arthur O'Dwyer1bb0f672020-12-20 15:21:42 -0500443 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000444 sort(RandomAccessIterator first, RandomAccessIterator last);
445
446template <class RandomAccessIterator, class Compare>
Arthur O'Dwyer1bb0f672020-12-20 15:21:42 -0500447 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000448 sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
449
450template <class RandomAccessIterator>
451 void
452 stable_sort(RandomAccessIterator first, RandomAccessIterator last);
453
454template <class RandomAccessIterator, class Compare>
455 void
456 stable_sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
457
458template <class RandomAccessIterator>
Arthur O'Dwyer2dfea5d2020-12-17 00:26:18 -0500459 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000460 partial_sort(RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last);
461
462template <class RandomAccessIterator, class Compare>
Arthur O'Dwyer2dfea5d2020-12-17 00:26:18 -0500463 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000464 partial_sort(RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last, Compare comp);
465
466template <class InputIterator, class RandomAccessIterator>
Arthur O'Dwyer2dfea5d2020-12-17 00:26:18 -0500467 constexpr RandomAccessIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000468 partial_sort_copy(InputIterator first, InputIterator last,
469 RandomAccessIterator result_first, RandomAccessIterator result_last);
470
471template <class InputIterator, class RandomAccessIterator, class Compare>
Arthur O'Dwyer2dfea5d2020-12-17 00:26:18 -0500472 constexpr RandomAccessIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000473 partial_sort_copy(InputIterator first, InputIterator last,
474 RandomAccessIterator result_first, RandomAccessIterator result_last, Compare comp);
475
476template <class RandomAccessIterator>
Arthur O'Dwyer4f5717b2021-02-04 18:12:52 -0500477 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000478 nth_element(RandomAccessIterator first, RandomAccessIterator nth, RandomAccessIterator last);
479
480template <class RandomAccessIterator, class Compare>
Arthur O'Dwyer4f5717b2021-02-04 18:12:52 -0500481 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000482 nth_element(RandomAccessIterator first, RandomAccessIterator nth, RandomAccessIterator last, Compare comp);
483
484template <class ForwardIterator, class T>
Marshall Clowe00916c2018-01-16 02:34:41 +0000485 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000486 lower_bound(ForwardIterator first, ForwardIterator last, const T& value);
487
488template <class ForwardIterator, class T, class Compare>
Marshall Clowe00916c2018-01-16 02:34:41 +0000489 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000490 lower_bound(ForwardIterator first, ForwardIterator last, const T& value, Compare comp);
491
492template <class ForwardIterator, class T>
Marshall Clowe00916c2018-01-16 02:34:41 +0000493 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000494 upper_bound(ForwardIterator first, ForwardIterator last, const T& value);
495
496template <class ForwardIterator, class T, class Compare>
Marshall Clowe00916c2018-01-16 02:34:41 +0000497 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000498 upper_bound(ForwardIterator first, ForwardIterator last, const T& value, Compare comp);
499
500template <class ForwardIterator, class T>
Marshall Clowe00916c2018-01-16 02:34:41 +0000501 constexpr pair<ForwardIterator, ForwardIterator> // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000502 equal_range(ForwardIterator first, ForwardIterator last, const T& value);
503
504template <class ForwardIterator, class T, class Compare>
Marshall Clowe00916c2018-01-16 02:34:41 +0000505 constexpr pair<ForwardIterator, ForwardIterator> // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000506 equal_range(ForwardIterator first, ForwardIterator last, const T& value, Compare comp);
507
508template <class ForwardIterator, class T>
Marshall Clowe00916c2018-01-16 02:34:41 +0000509 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000510 binary_search(ForwardIterator first, ForwardIterator last, const T& value);
511
512template <class ForwardIterator, class T, class Compare>
Marshall Clowc0b7f972018-01-22 23:10:40 +0000513 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000514 binary_search(ForwardIterator first, ForwardIterator last, const T& value, Compare comp);
515
516template <class InputIterator1, class InputIterator2, class OutputIterator>
Arthur O'Dwyer5afc5692020-12-04 13:47:12 -0500517 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000518 merge(InputIterator1 first1, InputIterator1 last1,
519 InputIterator2 first2, InputIterator2 last2, OutputIterator result);
520
521template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
Arthur O'Dwyer5afc5692020-12-04 13:47:12 -0500522 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000523 merge(InputIterator1 first1, InputIterator1 last1,
524 InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
525
526template <class BidirectionalIterator>
527 void
528 inplace_merge(BidirectionalIterator first, BidirectionalIterator middle, BidirectionalIterator last);
529
530template <class BidirectionalIterator, class Compare>
531 void
532 inplace_merge(BidirectionalIterator first, BidirectionalIterator middle, BidirectionalIterator last, Compare comp);
533
534template <class InputIterator1, class InputIterator2>
Marshall Clowc0b7f972018-01-22 23:10:40 +0000535 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000536 includes(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2);
537
538template <class InputIterator1, class InputIterator2, class Compare>
Marshall Clowc0b7f972018-01-22 23:10:40 +0000539 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000540 includes(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, Compare comp);
541
542template <class InputIterator1, class InputIterator2, class OutputIterator>
Arthur O'Dwyer5afc5692020-12-04 13:47:12 -0500543 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000544 set_union(InputIterator1 first1, InputIterator1 last1,
545 InputIterator2 first2, InputIterator2 last2, OutputIterator result);
546
547template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
Arthur O'Dwyer5afc5692020-12-04 13:47:12 -0500548 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000549 set_union(InputIterator1 first1, InputIterator1 last1,
550 InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
551
552template <class InputIterator1, class InputIterator2, class OutputIterator>
Marshall Clowc0b7f972018-01-22 23:10:40 +0000553 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000554 set_intersection(InputIterator1 first1, InputIterator1 last1,
555 InputIterator2 first2, InputIterator2 last2, OutputIterator result);
556
557template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
Marshall Clowc0b7f972018-01-22 23:10:40 +0000558 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000559 set_intersection(InputIterator1 first1, InputIterator1 last1,
560 InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
561
562template <class InputIterator1, class InputIterator2, class OutputIterator>
Arthur O'Dwyer5afc5692020-12-04 13:47:12 -0500563 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000564 set_difference(InputIterator1 first1, InputIterator1 last1,
565 InputIterator2 first2, InputIterator2 last2, OutputIterator result);
566
567template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
Arthur O'Dwyer5afc5692020-12-04 13:47:12 -0500568 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000569 set_difference(InputIterator1 first1, InputIterator1 last1,
570 InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
571
572template <class InputIterator1, class InputIterator2, class OutputIterator>
Arthur O'Dwyer5afc5692020-12-04 13:47:12 -0500573 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000574 set_symmetric_difference(InputIterator1 first1, InputIterator1 last1,
575 InputIterator2 first2, InputIterator2 last2, OutputIterator result);
576
577template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
Arthur O'Dwyer5afc5692020-12-04 13:47:12 -0500578 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000579 set_symmetric_difference(InputIterator1 first1, InputIterator1 last1,
580 InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
581
582template <class RandomAccessIterator>
Arthur O'Dwyer2dfea5d2020-12-17 00:26:18 -0500583 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000584 push_heap(RandomAccessIterator first, RandomAccessIterator last);
585
586template <class RandomAccessIterator, class Compare>
Arthur O'Dwyer2dfea5d2020-12-17 00:26:18 -0500587 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000588 push_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
589
590template <class RandomAccessIterator>
Arthur O'Dwyer2dfea5d2020-12-17 00:26:18 -0500591 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000592 pop_heap(RandomAccessIterator first, RandomAccessIterator last);
593
594template <class RandomAccessIterator, class Compare>
Arthur O'Dwyer2dfea5d2020-12-17 00:26:18 -0500595 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000596 pop_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
597
598template <class RandomAccessIterator>
Arthur O'Dwyer2dfea5d2020-12-17 00:26:18 -0500599 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000600 make_heap(RandomAccessIterator first, RandomAccessIterator last);
601
602template <class RandomAccessIterator, class Compare>
Arthur O'Dwyer2dfea5d2020-12-17 00:26:18 -0500603 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000604 make_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
605
606template <class RandomAccessIterator>
Arthur O'Dwyer2dfea5d2020-12-17 00:26:18 -0500607 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000608 sort_heap(RandomAccessIterator first, RandomAccessIterator last);
609
610template <class RandomAccessIterator, class Compare>
Arthur O'Dwyer2dfea5d2020-12-17 00:26:18 -0500611 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000612 sort_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
613
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000614template <class RandomAccessIterator>
Marshall Clow96d050a2018-01-15 16:16:32 +0000615 constexpr bool // constexpr in C++20
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000616 is_heap(RandomAccessIterator first, RandomAccessiterator last);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000617
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000618template <class RandomAccessIterator, class Compare>
Marshall Clow96d050a2018-01-15 16:16:32 +0000619 constexpr bool // constexpr in C++20
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000620 is_heap(RandomAccessIterator first, RandomAccessiterator last, Compare comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000621
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000622template <class RandomAccessIterator>
Marshall Clow96d050a2018-01-15 16:16:32 +0000623 constexpr RandomAccessIterator // constexpr in C++20
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000624 is_heap_until(RandomAccessIterator first, RandomAccessiterator last);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000625
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000626template <class RandomAccessIterator, class Compare>
Marshall Clow96d050a2018-01-15 16:16:32 +0000627 constexpr RandomAccessIterator // constexpr in C++20
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000628 is_heap_until(RandomAccessIterator first, RandomAccessiterator last, Compare comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000629
Howard Hinnantb120e7a2010-08-21 20:10:01 +0000630template <class ForwardIterator>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500631 constexpr ForwardIterator // constexpr in C++14
632 min_element(ForwardIterator first, ForwardIterator last);
Howard Hinnantb120e7a2010-08-21 20:10:01 +0000633
634template <class ForwardIterator, class Compare>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500635 constexpr ForwardIterator // constexpr in C++14
636 min_element(ForwardIterator first, ForwardIterator last, Compare comp);
Howard Hinnantb120e7a2010-08-21 20:10:01 +0000637
Howard Hinnantc51e1022010-05-11 19:42:16 +0000638template <class T>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500639 constexpr const T& // constexpr in C++14
640 min(const T& a, const T& b);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000641
642template <class T, class Compare>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500643 constexpr const T& // constexpr in C++14
644 min(const T& a, const T& b, Compare comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000645
Howard Hinnantb120e7a2010-08-21 20:10:01 +0000646template<class T>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500647 constexpr T // constexpr in C++14
648 min(initializer_list<T> t);
Howard Hinnantb120e7a2010-08-21 20:10:01 +0000649
650template<class T, class Compare>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500651 constexpr T // constexpr in C++14
652 min(initializer_list<T> t, Compare comp);
Howard Hinnantb120e7a2010-08-21 20:10:01 +0000653
Marshall Clow3e18d0e2016-03-07 22:43:49 +0000654template<class T>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500655 constexpr const T& clamp(const T& v, const T& lo, const T& hi); // C++17
Marshall Clow3e18d0e2016-03-07 22:43:49 +0000656
657template<class T, class Compare>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500658 constexpr const T& clamp(const T& v, const T& lo, const T& hi, Compare comp); // C++17
Marshall Clow3e18d0e2016-03-07 22:43:49 +0000659
Howard Hinnantb120e7a2010-08-21 20:10:01 +0000660template <class ForwardIterator>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500661 constexpr ForwardIterator // constexpr in C++14
662 max_element(ForwardIterator first, ForwardIterator last);
Howard Hinnantb120e7a2010-08-21 20:10:01 +0000663
664template <class ForwardIterator, class Compare>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500665 constexpr ForwardIterator // constexpr in C++14
666 max_element(ForwardIterator first, ForwardIterator last, Compare comp);
Howard Hinnantb120e7a2010-08-21 20:10:01 +0000667
Howard Hinnantc51e1022010-05-11 19:42:16 +0000668template <class T>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500669 constexpr const T& // constexpr in C++14
670 max(const T& a, const T& b);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000671
672template <class T, class Compare>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500673 constexpr const T& // constexpr in C++14
674 max(const T& a, const T& b, Compare comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000675
Howard Hinnantb120e7a2010-08-21 20:10:01 +0000676template<class T>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500677 constexpr T // constexpr in C++14
678 max(initializer_list<T> t);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000679
Howard Hinnantb120e7a2010-08-21 20:10:01 +0000680template<class T, class Compare>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500681 constexpr T // constexpr in C++14
682 max(initializer_list<T> t, Compare comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000683
Howard Hinnantb120e7a2010-08-21 20:10:01 +0000684template<class ForwardIterator>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500685 constexpr pair<ForwardIterator, ForwardIterator> // constexpr in C++14
686 minmax_element(ForwardIterator first, ForwardIterator last);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000687
Howard Hinnantb120e7a2010-08-21 20:10:01 +0000688template<class ForwardIterator, class Compare>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500689 constexpr pair<ForwardIterator, ForwardIterator> // constexpr in C++14
690 minmax_element(ForwardIterator first, ForwardIterator last, Compare comp);
Howard Hinnantb120e7a2010-08-21 20:10:01 +0000691
692template<class T>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500693 constexpr pair<const T&, const T&> // constexpr in C++14
694 minmax(const T& a, const T& b);
Howard Hinnantb120e7a2010-08-21 20:10:01 +0000695
696template<class T, class Compare>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500697 constexpr pair<const T&, const T&> // constexpr in C++14
698 minmax(const T& a, const T& b, Compare comp);
Howard Hinnantb120e7a2010-08-21 20:10:01 +0000699
700template<class T>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500701 constexpr pair<T, T> // constexpr in C++14
702 minmax(initializer_list<T> t);
Howard Hinnantb120e7a2010-08-21 20:10:01 +0000703
704template<class T, class Compare>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500705 constexpr pair<T, T> // constexpr in C++14
706 minmax(initializer_list<T> t, Compare comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000707
708template <class InputIterator1, class InputIterator2>
Marshall Clow5492c8a2018-01-22 20:44:33 +0000709 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000710 lexicographical_compare(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2);
711
712template <class InputIterator1, class InputIterator2, class Compare>
Marshall Clow5492c8a2018-01-22 20:44:33 +0000713 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000714 lexicographical_compare(InputIterator1 first1, InputIterator1 last1,
715 InputIterator2 first2, InputIterator2 last2, Compare comp);
716
717template <class BidirectionalIterator>
Arthur O'Dwyere50e7472020-12-17 00:01:08 -0500718 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000719 next_permutation(BidirectionalIterator first, BidirectionalIterator last);
720
721template <class BidirectionalIterator, class Compare>
Arthur O'Dwyere50e7472020-12-17 00:01:08 -0500722 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000723 next_permutation(BidirectionalIterator first, BidirectionalIterator last, Compare comp);
724
725template <class BidirectionalIterator>
Arthur O'Dwyere50e7472020-12-17 00:01:08 -0500726 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000727 prev_permutation(BidirectionalIterator first, BidirectionalIterator last);
728
729template <class BidirectionalIterator, class Compare>
Arthur O'Dwyere50e7472020-12-17 00:01:08 -0500730 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000731 prev_permutation(BidirectionalIterator first, BidirectionalIterator last, Compare comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000732} // std
733
734*/
735
Arthur O'Dwyer3693d7a2022-02-04 13:09:30 -0500736#include <__bits>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000737#include <__config>
Louis Dionnea60dd872021-06-17 11:30:11 -0400738#include <__debug>
Howard Hinnant60e5cf42012-07-26 17:09:09 +0000739#include <cstddef>
Arthur O'Dwyeref181602021-05-19 11:57:04 -0400740#include <cstring>
741#include <functional>
742#include <initializer_list>
743#include <iterator>
744#include <memory>
745#include <type_traits>
Marshall Clow0a1e7502018-09-12 19:41:40 +0000746#include <version>
Howard Hinnantea382952013-08-14 18:00:20 +0000747
Louis Dionnea60dd872021-06-17 11:30:11 -0400748#include <__algorithm/adjacent_find.h>
749#include <__algorithm/all_of.h>
750#include <__algorithm/any_of.h>
751#include <__algorithm/binary_search.h>
752#include <__algorithm/clamp.h>
753#include <__algorithm/comp.h>
754#include <__algorithm/comp_ref_type.h>
755#include <__algorithm/copy.h>
756#include <__algorithm/copy_backward.h>
757#include <__algorithm/copy_if.h>
758#include <__algorithm/copy_n.h>
759#include <__algorithm/count.h>
760#include <__algorithm/count_if.h>
761#include <__algorithm/equal.h>
762#include <__algorithm/equal_range.h>
Louis Dionnea60dd872021-06-17 11:30:11 -0400763#include <__algorithm/fill.h>
Arthur O'Dwyer65077c02022-01-07 09:45:05 -0500764#include <__algorithm/fill_n.h>
Louis Dionnea60dd872021-06-17 11:30:11 -0400765#include <__algorithm/find.h>
766#include <__algorithm/find_end.h>
767#include <__algorithm/find_first_of.h>
768#include <__algorithm/find_if.h>
769#include <__algorithm/find_if_not.h>
770#include <__algorithm/for_each.h>
771#include <__algorithm/for_each_n.h>
Louis Dionnea60dd872021-06-17 11:30:11 -0400772#include <__algorithm/generate.h>
Arthur O'Dwyer65077c02022-01-07 09:45:05 -0500773#include <__algorithm/generate_n.h>
Louis Dionnea60dd872021-06-17 11:30:11 -0400774#include <__algorithm/half_positive.h>
Nikolas Klauserdd5ad212022-02-21 23:07:02 +0100775#include <__algorithm/in_found_result.h>
Nikolas Klauser671b4752022-02-11 17:01:58 +0100776#include <__algorithm/in_fun_result.h>
Nikolas Klauser05e2cd82022-01-25 11:21:47 +0100777#include <__algorithm/in_in_out_result.h>
Nikolas Klauserf74be4e2022-01-14 02:55:51 +0100778#include <__algorithm/in_in_result.h>
Nikolas Klauser61ce8162022-02-03 02:17:03 +0100779#include <__algorithm/in_out_out_result.h>
Konstantin Varlamov74736812022-01-10 22:49:37 -0800780#include <__algorithm/in_out_result.h>
Louis Dionnea60dd872021-06-17 11:30:11 -0400781#include <__algorithm/includes.h>
782#include <__algorithm/inplace_merge.h>
783#include <__algorithm/is_heap.h>
784#include <__algorithm/is_heap_until.h>
785#include <__algorithm/is_partitioned.h>
786#include <__algorithm/is_permutation.h>
787#include <__algorithm/is_sorted.h>
788#include <__algorithm/is_sorted_until.h>
Christopher Di Bella41f26e82021-06-05 02:47:47 +0000789#include <__algorithm/iter_swap.h>
Louis Dionnea60dd872021-06-17 11:30:11 -0400790#include <__algorithm/lexicographical_compare.h>
791#include <__algorithm/lower_bound.h>
792#include <__algorithm/make_heap.h>
793#include <__algorithm/max.h>
794#include <__algorithm/max_element.h>
795#include <__algorithm/merge.h>
796#include <__algorithm/min.h>
797#include <__algorithm/min_element.h>
Nikolas Klauser2e263162022-02-21 22:48:36 +0100798#include <__algorithm/min_max_result.h>
Louis Dionnea60dd872021-06-17 11:30:11 -0400799#include <__algorithm/minmax.h>
800#include <__algorithm/minmax_element.h>
801#include <__algorithm/mismatch.h>
802#include <__algorithm/move.h>
803#include <__algorithm/move_backward.h>
804#include <__algorithm/next_permutation.h>
805#include <__algorithm/none_of.h>
806#include <__algorithm/nth_element.h>
807#include <__algorithm/partial_sort.h>
808#include <__algorithm/partial_sort_copy.h>
809#include <__algorithm/partition.h>
810#include <__algorithm/partition_copy.h>
811#include <__algorithm/partition_point.h>
812#include <__algorithm/pop_heap.h>
813#include <__algorithm/prev_permutation.h>
814#include <__algorithm/push_heap.h>
Nikolas Klauser37d076e2022-03-12 01:45:35 +0100815#include <__algorithm/ranges_find.h>
816#include <__algorithm/ranges_find_if.h>
817#include <__algorithm/ranges_find_if_not.h>
Nikolas Klauserf2a69ea2022-03-07 17:01:52 +0100818#include <__algorithm/ranges_max_element.h>
Nikolas Klauser3559e452022-03-18 02:57:08 +0100819#include <__algorithm/ranges_min.h>
Nikolas Klauser0a62a172022-02-11 13:11:57 +0100820#include <__algorithm/ranges_min_element.h>
Nikolas Klauser12fc9bf2022-03-08 23:12:35 +0100821#include <__algorithm/ranges_mismatch.h>
Nikolas Klauser4ceab5f2022-02-10 13:33:03 +0100822#include <__algorithm/ranges_swap_ranges.h>
Louis Dionnea60dd872021-06-17 11:30:11 -0400823#include <__algorithm/remove.h>
824#include <__algorithm/remove_copy.h>
825#include <__algorithm/remove_copy_if.h>
826#include <__algorithm/remove_if.h>
827#include <__algorithm/replace.h>
828#include <__algorithm/replace_copy.h>
829#include <__algorithm/replace_copy_if.h>
830#include <__algorithm/replace_if.h>
831#include <__algorithm/reverse.h>
832#include <__algorithm/reverse_copy.h>
833#include <__algorithm/rotate.h>
834#include <__algorithm/rotate_copy.h>
835#include <__algorithm/sample.h>
836#include <__algorithm/search.h>
837#include <__algorithm/search_n.h>
838#include <__algorithm/set_difference.h>
839#include <__algorithm/set_intersection.h>
840#include <__algorithm/set_symmetric_difference.h>
841#include <__algorithm/set_union.h>
842#include <__algorithm/shift_left.h>
843#include <__algorithm/shift_right.h>
844#include <__algorithm/shuffle.h>
845#include <__algorithm/sift_down.h>
846#include <__algorithm/sort.h>
847#include <__algorithm/sort_heap.h>
848#include <__algorithm/stable_partition.h>
849#include <__algorithm/stable_sort.h>
Christopher Di Bella41f26e82021-06-05 02:47:47 +0000850#include <__algorithm/swap_ranges.h>
Louis Dionnea60dd872021-06-17 11:30:11 -0400851#include <__algorithm/transform.h>
Louis Dionnea60dd872021-06-17 11:30:11 -0400852#include <__algorithm/unique.h>
Arthur O'Dwyer65077c02022-01-07 09:45:05 -0500853#include <__algorithm/unique_copy.h>
Louis Dionnea60dd872021-06-17 11:30:11 -0400854#include <__algorithm/unwrap_iter.h>
855#include <__algorithm/upper_bound.h>
Eric Fiselier14b6de92014-08-10 23:53:08 +0000856
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000857#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Arthur O'Dwyer6eeaa002022-02-01 20:16:40 -0500858# pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000859#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000860
Louis Dionne59d0b3c2019-08-05 18:29:14 +0000861#if defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS) && _LIBCPP_STD_VER >= 17
Louis Dionned53d8c02019-08-06 21:11:24 +0000862# include <__pstl_algorithm>
Louis Dionne59d0b3c2019-08-05 18:29:14 +0000863#endif
864
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400865#endif // _LIBCPP_ALGORITHM