blob: 9feb59b3a1a7e9a701a60a95ccf6062262be8719 [file] [log] [blame]
Howard Hinnant3e519522010-05-11 19:42:161// -*- C++ -*-
Louis Dionneeb8650a2021-11-17 21:25:012//===----------------------------------------------------------------------===//
Howard Hinnant3e519522010-05-11 19:42:163//
Chandler Carruth57b08b02019-01-19 10:56:404// 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 Hinnant3e519522010-05-11 19:42:167//
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 Klauserd3729bb2022-01-14 01:55:5121namespace ranges {
Nikolas Klauser1e77b392022-02-11 16:01:5822 template <class I, class F>
Nikolas Klauser807766b2022-02-21 21:48:3623 struct in_fun_result; // since C++20
Nikolas Klauser1e77b392022-02-11 16:01:5824
Nikolas Klauserd3729bb2022-01-14 01:55:5125 template <class I1, class I2>
Nikolas Klauser807766b2022-02-21 21:48:3626 struct in_in_result; // since C++20
Nikolas Klauserf3514af2022-01-25 10:21:4727
28 template <class I1, class I2, class O>
Nikolas Klauser807766b2022-02-21 21:48:3629 struct in_in_out_result; // since C++20
Nikolas Klauser610979b2022-02-03 01:17:0330
31 template <class I, class O1, class O2>
32 struct in_out_out_result; // since C++20
Nikolas Klauser1e77b392022-02-11 16:01:5833
Nikolas Klauser807766b2022-02-21 21:48:3634 template <class I1, class I2>
35 struct min_max_result; // since C++20
36
Nikolas Klauser68f41312022-02-21 22:07:0237 template <class I>
38 struct in_found_result; // since C++20
39
Nikolas Klauser3b470d12022-02-11 12:11:5740 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 Klauserc2cd15a2022-03-08 22:12:3547
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 Klauseree0f8c42022-03-12 00:45:3559
Nikolas Klauseree0f8c42022-03-12 00:45:3560 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 Klauserf83d8332022-03-18 01:57:0885
Nikolas Klausere476df52022-04-03 07:17:0186 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
Nikolas Klauserf83d8332022-03-18 01:57:0889
Nikolas Klausere476df52022-04-03 07:17:0190 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
Nikolas Klauserf83d8332022-03-18 01:57:0893
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 Klausere476df52022-04-03 07:17:0199
100 template<class T, class Proj = identity,
101 indirect_strict_weak_order<projected<const T*, Proj>> Comp = ranges::less>
102 constexpr const T& max(const T& a, const T& b, Comp comp = {}, Proj proj = {}); // since C++20
103
104 template<copyable T, class Proj = identity,
105 indirect_strict_weak_order<projected<const T*, Proj>> Comp = ranges::less>
106 constexpr T max(initializer_list<T> r, Comp comp = {}, Proj proj = {}); // since C++20
107
108 template<input_range R, class Proj = identity,
109 indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less>
110 requires indirectly_copyable_storable<iterator_t<R>, range_value_t<R>*>
111 constexpr range_value_t<R>
112 max(R&& r, Comp comp = {}, Proj proj = {}); // since C++20
Nikolas Klauser3ba85482022-04-05 09:05:36113
114 template<class I, class O>
115 using unary_transform_result = in_out_result<I, O>; // since C++20
116
117 template<class I1, class I2, class O>
118 using binary_transform_result = in_in_out_result<I1, I2, O>; // since C++20
119
120 template<input_iterator I, sentinel_for<I> S, weakly_incrementable O,
121 copy_constructible F, class Proj = identity>
122 requires indirectly_writable<O, indirect_result_t<F&, projected<I, Proj>>>
123 constexpr ranges::unary_transform_result<I, O>
124 transform(I first1, S last1, O result, F op, Proj proj = {}); // since C++20
125
126 template<input_range R, weakly_incrementable O, copy_constructible F,
127 class Proj = identity>
128 requires indirectly_writable<O, indirect_result_t<F&, projected<iterator_t<R>, Proj>>>
129 constexpr ranges::unary_transform_result<borrowed_iterator_t<R>, O>
130 transform(R&& r, O result, F op, Proj proj = {}); // since C++20
131
132 template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2,
133 weakly_incrementable O, copy_constructible F, class Proj1 = identity,
134 class Proj2 = identity>
135 requires indirectly_writable<O, indirect_result_t<F&, projected<I1, Proj1>,
136 projected<I2, Proj2>>>
137 constexpr ranges::binary_transform_result<I1, I2, O>
138 transform(I1 first1, S1 last1, I2 first2, S2 last2, O result,
139 F binary_op, Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
140
141 template<input_range R1, input_range R2, weakly_incrementable O,
142 copy_constructible F, class Proj1 = identity, class Proj2 = identity>
143 requires indirectly_writable<O, indirect_result_t<F&, projected<iterator_t<R1>, Proj1>,
144 projected<iterator_t<R2>, Proj2>>>
145 constexpr ranges::binary_transform_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>, O>
146 transform(R1&& r1, R2&& r2, O result,
147 F binary_op, Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
Nikolas Klauser1306b102022-04-07 11:02:02148
149 template<input_iterator I, sentinel_for<I> S, class T, class Proj = identity>
150 requires indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T*>
151 constexpr iter_difference_t<I>
152 count(I first, S last, const T& value, Proj proj = {}); // since C++20
153
154 template<input_range R, class T, class Proj = identity>
155 requires indirect_binary_predicate<ranges::equal_to, projected<iterator_t<R>, Proj>, const T*>
156 constexpr range_difference_t<R>
157 count(R&& r, const T& value, Proj proj = {}); // since C++20
158
159 template<input_iterator I, sentinel_for<I> S, class Proj = identity,
160 indirect_unary_predicate<projected<I, Proj>> Pred>
161 constexpr iter_difference_t<I>
162 count_if(I first, S last, Pred pred, Proj proj = {}); // since C++20
163
164 template<input_range R, class Proj = identity,
165 indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
166 constexpr range_difference_t<R>
167 count_if(R&& r, Pred pred, Proj proj = {}); // since C++20
Nikolas Klauser58d9ab72022-04-13 20:59:09168
169 template<class T, class Proj = identity,
170 indirect_strict_weak_order<projected<const T*, Proj>> Comp = ranges::less>
171 constexpr ranges::minmax_result<const T&>
172 minmax(const T& a, const T& b, Comp comp = {}, Proj proj = {}); // since C++20
173
174 template<copyable T, class Proj = identity,
175 indirect_strict_weak_order<projected<const T*, Proj>> Comp = ranges::less>
176 constexpr ranges::minmax_result<T>
177 minmax(initializer_list<T> r, Comp comp = {}, Proj proj = {}); // since C++20
178
179 template<input_range R, class Proj = identity,
180 indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less>
181 requires indirectly_copyable_storable<iterator_t<R>, range_value_t<R>*>
182 constexpr ranges::minmax_result<range_value_t<R>>
183 minmax(R&& r, Comp comp = {}, Proj proj = {}); // since C++20
184
185 template<forward_iterator I, sentinel_for<I> S, class Proj = identity,
186 indirect_strict_weak_order<projected<I, Proj>> Comp = ranges::less>
187 constexpr ranges::minmax_element_result<I>
188 minmax_element(I first, S last, Comp comp = {}, Proj proj = {}); // since C++20
189
190 template<forward_range R, class Proj = identity,
191 indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less>
192 constexpr ranges::minmax_element_result<borrowed_iterator_t<R>>
193 minmax_element(R&& r, Comp comp = {}, Proj proj = {}); // since C++20
Nikolas Klauser1d837502022-04-15 11:43:40194
195 template<class I, class O>
196 using copy_result = in_out_result<I, O>; // since C++20
197
198 template<class I, class O>
199 using copy_n_result = in_out_result<I, O>; // since C++20
200
201 template<class I, class O>
202 using copy_if_result = in_out_result<I, O>; // since C++20
203
204 template<class I1, class I2>
205 using copy_backward_result = in_out_result<I1, I2>; // since C++20
206
207 template<input_iterator I, sentinel_for<I> S, weakly_incrementable O>
208 requires indirectly_copyable<I, O>
209 constexpr ranges::copy_result<I, O> ranges::copy(I first, S last, O result); // since C++20
210
211 template<input_range R, weakly_incrementable O>
212 requires indirectly_copyable<iterator_t<R>, O>
213 constexpr ranges::copy_result<borrowed_iterator_t<R>, O> ranges::copy(R&& r, O result); // since C++20
214
215 template<input_iterator I, weakly_incrementable O>
216 requires indirectly_copyable<I, O>
217 constexpr ranges::copy_n_result<I, O>
218 ranges::copy_n(I first, iter_difference_t<I> n, O result); // since C++20
219
220 template<input_iterator I, sentinel_for<I> S, weakly_incrementable O, class Proj = identity,
221 indirect_unary_predicate<projected<I, Proj>> Pred>
222 requires indirectly_copyable<I, O>
223 constexpr ranges::copy_if_result<I, O>
224 ranges::copy_if(I first, S last, O result, Pred pred, Proj proj = {}); // since C++20
225
226 template<input_range R, weakly_incrementable O, class Proj = identity,
227 indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
228 requires indirectly_copyable<iterator_t<R>, O>
229 constexpr ranges::copy_if_result<borrowed_iterator_t<R>, O>
230 ranges::copy_if(R&& r, O result, Pred pred, Proj proj = {}); // since C++20
231
232 template<bidirectional_iterator I1, sentinel_for<I1> S1, bidirectional_iterator I2>
233 requires indirectly_copyable<I1, I2>
234 constexpr ranges::copy_backward_result<I1, I2>
235 ranges::copy_backward(I1 first, S1 last, I2 result); // since C++20
236
237 template<bidirectional_range R, bidirectional_iterator I>
238 requires indirectly_copyable<iterator_t<R>, I>
239 constexpr ranges::copy_backward_result<borrowed_iterator_t<R>, I>
240 ranges::copy_backward(R&& r, I result); // since C++20
Nikolas Klauserd3729bb2022-01-14 01:55:51241}
242
Marshall Clow706ffef2018-01-15 17:20:36243 constexpr bool // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16244 all_of(InputIterator first, InputIterator last, Predicate pred);
245
246template <class InputIterator, class Predicate>
Marshall Clow706ffef2018-01-15 17:20:36247 constexpr bool // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16248 any_of(InputIterator first, InputIterator last, Predicate pred);
249
250template <class InputIterator, class Predicate>
Marshall Clow706ffef2018-01-15 17:20:36251 constexpr bool // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16252 none_of(InputIterator first, InputIterator last, Predicate pred);
253
254template <class InputIterator, class Function>
Marshall Clow1b9a4ff2018-01-22 20:44:33255 constexpr Function // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16256 for_each(InputIterator first, InputIterator last, Function f);
257
Marshall Clowd5c65ff2017-05-25 02:29:54258template<class InputIterator, class Size, class Function>
Marshall Clow1b9a4ff2018-01-22 20:44:33259 constexpr InputIterator // constexpr in C++20
260 for_each_n(InputIterator first, Size n, Function f); // C++17
Marshall Clowd5c65ff2017-05-25 02:29:54261
Howard Hinnant3e519522010-05-11 19:42:16262template <class InputIterator, class T>
Marshall Clow86944282018-01-15 19:26:05263 constexpr InputIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16264 find(InputIterator first, InputIterator last, const T& value);
265
266template <class InputIterator, class Predicate>
Marshall Clow86944282018-01-15 19:26:05267 constexpr InputIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16268 find_if(InputIterator first, InputIterator last, Predicate pred);
269
270template<class InputIterator, class Predicate>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:18271 constexpr InputIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16272 find_if_not(InputIterator first, InputIterator last, Predicate pred);
273
274template <class ForwardIterator1, class ForwardIterator2>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:18275 constexpr ForwardIterator1 // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16276 find_end(ForwardIterator1 first1, ForwardIterator1 last1,
277 ForwardIterator2 first2, ForwardIterator2 last2);
278
279template <class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:18280 constexpr ForwardIterator1 // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16281 find_end(ForwardIterator1 first1, ForwardIterator1 last1,
282 ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred);
283
284template <class ForwardIterator1, class ForwardIterator2>
Marshall Clow86944282018-01-15 19:26:05285 constexpr ForwardIterator1 // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16286 find_first_of(ForwardIterator1 first1, ForwardIterator1 last1,
287 ForwardIterator2 first2, ForwardIterator2 last2);
288
289template <class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
Marshall Clow86944282018-01-15 19:26:05290 constexpr ForwardIterator1 // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16291 find_first_of(ForwardIterator1 first1, ForwardIterator1 last1,
292 ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred);
293
294template <class ForwardIterator>
Marshall Clow86944282018-01-15 19:26:05295 constexpr ForwardIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16296 adjacent_find(ForwardIterator first, ForwardIterator last);
297
298template <class ForwardIterator, class BinaryPredicate>
Marshall Clow86944282018-01-15 19:26:05299 constexpr ForwardIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16300 adjacent_find(ForwardIterator first, ForwardIterator last, BinaryPredicate pred);
301
302template <class InputIterator, class T>
Marshall Clow056f15e2018-01-15 19:40:34303 constexpr typename iterator_traits<InputIterator>::difference_type // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16304 count(InputIterator first, InputIterator last, const T& value);
305
306template <class InputIterator, class Predicate>
Marshall Clow056f15e2018-01-15 19:40:34307 constexpr typename iterator_traits<InputIterator>::difference_type // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16308 count_if(InputIterator first, InputIterator last, Predicate pred);
309
310template <class InputIterator1, class InputIterator2>
Marshall Clow6538e28d2018-01-16 02:04:10311 constexpr pair<InputIterator1, InputIterator2> // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16312 mismatch(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2);
313
Marshall Clow0b0bbd22013-05-09 21:14:23314template <class InputIterator1, class InputIterator2>
Marshall Clow6538e28d2018-01-16 02:04:10315 constexpr pair<InputIterator1, InputIterator2> // constexpr in C++20
Aditya Kumar331fb802016-08-25 11:52:38316 mismatch(InputIterator1 first1, InputIterator1 last1,
Marshall Clow0b0bbd22013-05-09 21:14:23317 InputIterator2 first2, InputIterator2 last2); // **C++14**
318
Howard Hinnant3e519522010-05-11 19:42:16319template <class InputIterator1, class InputIterator2, class BinaryPredicate>
Marshall Clow6538e28d2018-01-16 02:04:10320 constexpr pair<InputIterator1, InputIterator2> // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16321 mismatch(InputIterator1 first1, InputIterator1 last1,
322 InputIterator2 first2, BinaryPredicate pred);
323
Marshall Clow0b0bbd22013-05-09 21:14:23324template <class InputIterator1, class InputIterator2, class BinaryPredicate>
Marshall Clow6538e28d2018-01-16 02:04:10325 constexpr pair<InputIterator1, InputIterator2> // constexpr in C++20
Marshall Clow0b0bbd22013-05-09 21:14:23326 mismatch(InputIterator1 first1, InputIterator1 last1,
327 InputIterator2 first2, InputIterator2 last2,
328 BinaryPredicate pred); // **C++14**
329
Howard Hinnant3e519522010-05-11 19:42:16330template <class InputIterator1, class InputIterator2>
Marshall Clow6538e28d2018-01-16 02:04:10331 constexpr bool // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16332 equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2);
333
Marshall Clow0b0bbd22013-05-09 21:14:23334template <class InputIterator1, class InputIterator2>
Marshall Clow6538e28d2018-01-16 02:04:10335 constexpr bool // constexpr in C++20
Aditya Kumar331fb802016-08-25 11:52:38336 equal(InputIterator1 first1, InputIterator1 last1,
Marshall Clow0b0bbd22013-05-09 21:14:23337 InputIterator2 first2, InputIterator2 last2); // **C++14**
338
Howard Hinnant3e519522010-05-11 19:42:16339template <class InputIterator1, class InputIterator2, class BinaryPredicate>
Marshall Clow6538e28d2018-01-16 02:04:10340 constexpr bool // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16341 equal(InputIterator1 first1, InputIterator1 last1,
342 InputIterator2 first2, BinaryPredicate pred);
343
Marshall Clow0b0bbd22013-05-09 21:14:23344template <class InputIterator1, class InputIterator2, class BinaryPredicate>
Marshall Clow6538e28d2018-01-16 02:04:10345 constexpr bool // constexpr in C++20
Marshall Clow0b0bbd22013-05-09 21:14:23346 equal(InputIterator1 first1, InputIterator1 last1,
347 InputIterator2 first2, InputIterator2 last2,
348 BinaryPredicate pred); // **C++14**
349
Howard Hinnant3e519522010-05-11 19:42:16350template<class ForwardIterator1, class ForwardIterator2>
Marshall Clow49c76432018-01-15 16:16:32351 constexpr bool // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16352 is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
353 ForwardIterator2 first2);
354
Marshall Clow0b0bbd22013-05-09 21:14:23355template<class ForwardIterator1, class ForwardIterator2>
Marshall Clow49c76432018-01-15 16:16:32356 constexpr bool // constexpr in C++20
Marshall Clow0b0bbd22013-05-09 21:14:23357 is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
358 ForwardIterator2 first2, ForwardIterator2 last2); // **C++14**
359
Howard Hinnant3e519522010-05-11 19:42:16360template<class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
Marshall Clow49c76432018-01-15 16:16:32361 constexpr bool // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16362 is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
363 ForwardIterator2 first2, BinaryPredicate pred);
364
Marshall Clow0b0bbd22013-05-09 21:14:23365template<class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
Marshall Clow49c76432018-01-15 16:16:32366 constexpr bool // constexpr in C++20
Marshall Clow0b0bbd22013-05-09 21:14:23367 is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
368 ForwardIterator2 first2, ForwardIterator2 last2,
369 BinaryPredicate pred); // **C++14**
370
Howard Hinnant3e519522010-05-11 19:42:16371template <class ForwardIterator1, class ForwardIterator2>
Marshall Clow12f0a772018-01-16 15:48:27372 constexpr ForwardIterator1 // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16373 search(ForwardIterator1 first1, ForwardIterator1 last1,
374 ForwardIterator2 first2, ForwardIterator2 last2);
375
376template <class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
Marshall Clow12f0a772018-01-16 15:48:27377 constexpr ForwardIterator1 // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16378 search(ForwardIterator1 first1, ForwardIterator1 last1,
379 ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred);
380
381template <class ForwardIterator, class Size, class T>
Marshall Clow12f0a772018-01-16 15:48:27382 constexpr ForwardIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16383 search_n(ForwardIterator first, ForwardIterator last, Size count, const T& value);
384
385template <class ForwardIterator, class Size, class T, class BinaryPredicate>
Marshall Clow12f0a772018-01-16 15:48:27386 constexpr ForwardIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16387 search_n(ForwardIterator first, ForwardIterator last,
388 Size count, const T& value, BinaryPredicate pred);
389
390template <class InputIterator, class OutputIterator>
Louis Dionne13c90a52019-11-06 12:02:41391 constexpr OutputIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16392 copy(InputIterator first, InputIterator last, OutputIterator result);
393
394template<class InputIterator, class OutputIterator, class Predicate>
Louis Dionne13c90a52019-11-06 12:02:41395 constexpr OutputIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16396 copy_if(InputIterator first, InputIterator last,
397 OutputIterator result, Predicate pred);
398
399template<class InputIterator, class Size, class OutputIterator>
Louis Dionne13c90a52019-11-06 12:02:41400 constexpr OutputIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16401 copy_n(InputIterator first, Size n, OutputIterator result);
402
403template <class BidirectionalIterator1, class BidirectionalIterator2>
Louis Dionne13c90a52019-11-06 12:02:41404 constexpr BidirectionalIterator2 // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16405 copy_backward(BidirectionalIterator1 first, BidirectionalIterator1 last,
406 BidirectionalIterator2 result);
407
408template <class ForwardIterator1, class ForwardIterator2>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:18409 constexpr ForwardIterator2 // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16410 swap_ranges(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2);
411
Nikolas Klauser9d905312022-02-10 12:33:03412template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2>
413 requires indirectly_swappable<I1, I2>
414 constexpr ranges::swap_ranges_result<I1, I2>
415 ranges::swap_ranges(I1 first1, S1 last1, I2 first2, S2 last2);
416
417template<input_range R1, input_range R2>
418 requires indirectly_swappable<iterator_t<R1>, iterator_t<R2>>
419 constexpr ranges::swap_ranges_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>>
420 ranges::swap_ranges(R1&& r1, R2&& r2);
421
Howard Hinnant3e519522010-05-11 19:42:16422template <class ForwardIterator1, class ForwardIterator2>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:18423 constexpr void // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16424 iter_swap(ForwardIterator1 a, ForwardIterator2 b);
425
426template <class InputIterator, class OutputIterator, class UnaryOperation>
Marshall Clow99894b62018-01-19 17:45:39427 constexpr OutputIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16428 transform(InputIterator first, InputIterator last, OutputIterator result, UnaryOperation op);
429
430template <class InputIterator1, class InputIterator2, class OutputIterator, class BinaryOperation>
Marshall Clow99894b62018-01-19 17:45:39431 constexpr OutputIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16432 transform(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2,
433 OutputIterator result, BinaryOperation binary_op);
434
435template <class ForwardIterator, class T>
Marshall Clow12c74232018-01-19 18:07:29436 constexpr void // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16437 replace(ForwardIterator first, ForwardIterator last, const T& old_value, const T& new_value);
438
439template <class ForwardIterator, class Predicate, class T>
Marshall Clow12c74232018-01-19 18:07:29440 constexpr void // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16441 replace_if(ForwardIterator first, ForwardIterator last, Predicate pred, const T& new_value);
442
443template <class InputIterator, class OutputIterator, class T>
Marshall Clow12c74232018-01-19 18:07:29444 constexpr OutputIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16445 replace_copy(InputIterator first, InputIterator last, OutputIterator result,
446 const T& old_value, const T& new_value);
447
448template <class InputIterator, class OutputIterator, class Predicate, class T>
Marshall Clow12c74232018-01-19 18:07:29449 constexpr OutputIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16450 replace_copy_if(InputIterator first, InputIterator last, OutputIterator result, Predicate pred, const T& new_value);
451
452template <class ForwardIterator, class T>
Marshall Clow4bfb9312018-01-20 20:14:32453 constexpr void // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16454 fill(ForwardIterator first, ForwardIterator last, const T& value);
455
456template <class OutputIterator, class Size, class T>
Marshall Clow4bfb9312018-01-20 20:14:32457 constexpr OutputIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16458 fill_n(OutputIterator first, Size n, const T& value);
459
460template <class ForwardIterator, class Generator>
Marshall Clow4bfb9312018-01-20 20:14:32461 constexpr void // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16462 generate(ForwardIterator first, ForwardIterator last, Generator gen);
463
464template <class OutputIterator, class Size, class Generator>
Marshall Clow4bfb9312018-01-20 20:14:32465 constexpr OutputIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16466 generate_n(OutputIterator first, Size n, Generator gen);
467
468template <class ForwardIterator, class T>
Marshall Clowe8ea8292018-01-22 21:43:04469 constexpr ForwardIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16470 remove(ForwardIterator first, ForwardIterator last, const T& value);
471
472template <class ForwardIterator, class Predicate>
Marshall Clowe8ea8292018-01-22 21:43:04473 constexpr ForwardIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16474 remove_if(ForwardIterator first, ForwardIterator last, Predicate pred);
475
476template <class InputIterator, class OutputIterator, class T>
Marshall Clowe8ea8292018-01-22 21:43:04477 constexpr OutputIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16478 remove_copy(InputIterator first, InputIterator last, OutputIterator result, const T& value);
479
480template <class InputIterator, class OutputIterator, class Predicate>
Marshall Clowe8ea8292018-01-22 21:43:04481 constexpr OutputIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16482 remove_copy_if(InputIterator first, InputIterator last, OutputIterator result, Predicate pred);
483
484template <class ForwardIterator>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:18485 constexpr ForwardIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16486 unique(ForwardIterator first, ForwardIterator last);
487
488template <class ForwardIterator, class BinaryPredicate>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:18489 constexpr ForwardIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16490 unique(ForwardIterator first, ForwardIterator last, BinaryPredicate pred);
491
492template <class InputIterator, class OutputIterator>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:18493 constexpr OutputIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16494 unique_copy(InputIterator first, InputIterator last, OutputIterator result);
495
496template <class InputIterator, class OutputIterator, class BinaryPredicate>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:18497 constexpr OutputIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16498 unique_copy(InputIterator first, InputIterator last, OutputIterator result, BinaryPredicate pred);
499
500template <class BidirectionalIterator>
Arthur O'Dwyerf851db32020-12-17 05:01:08501 constexpr void // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16502 reverse(BidirectionalIterator first, BidirectionalIterator last);
503
504template <class BidirectionalIterator, class OutputIterator>
Marshall Clowe8ea8292018-01-22 21:43:04505 constexpr OutputIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16506 reverse_copy(BidirectionalIterator first, BidirectionalIterator last, OutputIterator result);
507
508template <class ForwardIterator>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:18509 constexpr ForwardIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16510 rotate(ForwardIterator first, ForwardIterator middle, ForwardIterator last);
511
512template <class ForwardIterator, class OutputIterator>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:18513 constexpr OutputIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16514 rotate_copy(ForwardIterator first, ForwardIterator middle, ForwardIterator last, OutputIterator result);
515
516template <class RandomAccessIterator>
517 void
Marshall Clow0f37a412017-03-23 13:43:37518 random_shuffle(RandomAccessIterator first, RandomAccessIterator last); // deprecated in C++14, removed in C++17
Howard Hinnant3e519522010-05-11 19:42:16519
520template <class RandomAccessIterator, class RandomNumberGenerator>
521 void
Marshall Clow06965c12014-03-03 06:14:19522 random_shuffle(RandomAccessIterator first, RandomAccessIterator last,
Marshall Clow0f37a412017-03-23 13:43:37523 RandomNumberGenerator& rand); // deprecated in C++14, removed in C++17
Howard Hinnant3e519522010-05-11 19:42:16524
Eric Fiseliere7154702016-08-28 22:14:37525template<class PopulationIterator, class SampleIterator,
526 class Distance, class UniformRandomBitGenerator>
527 SampleIterator sample(PopulationIterator first, PopulationIterator last,
528 SampleIterator out, Distance n,
529 UniformRandomBitGenerator&& g); // C++17
530
Howard Hinnantf9d540b2010-05-26 17:49:34531template<class RandomAccessIterator, class UniformRandomNumberGenerator>
532 void shuffle(RandomAccessIterator first, RandomAccessIterator last,
Howard Hinnantfb340102010-11-18 01:47:02533 UniformRandomNumberGenerator&& g);
Howard Hinnantf9d540b2010-05-26 17:49:34534
Arthur O'Dwyer3fbd3ea2020-12-26 06:39:03535template<class ForwardIterator>
536 constexpr ForwardIterator
537 shift_left(ForwardIterator first, ForwardIterator last,
538 typename iterator_traits<ForwardIterator>::difference_type n); // C++20
539
540template<class ForwardIterator>
541 constexpr ForwardIterator
542 shift_right(ForwardIterator first, ForwardIterator last,
543 typename iterator_traits<ForwardIterator>::difference_type n); // C++20
544
Howard Hinnant3e519522010-05-11 19:42:16545template <class InputIterator, class Predicate>
Marshall Clow49c76432018-01-15 16:16:32546 constexpr bool // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16547 is_partitioned(InputIterator first, InputIterator last, Predicate pred);
548
549template <class ForwardIterator, class Predicate>
Arthur O'Dwyerf851db32020-12-17 05:01:08550 constexpr ForwardIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16551 partition(ForwardIterator first, ForwardIterator last, Predicate pred);
552
553template <class InputIterator, class OutputIterator1,
554 class OutputIterator2, class Predicate>
Marshall Clow1b9a4ff2018-01-22 20:44:33555 constexpr pair<OutputIterator1, OutputIterator2> // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16556 partition_copy(InputIterator first, InputIterator last,
557 OutputIterator1 out_true, OutputIterator2 out_false,
558 Predicate pred);
559
560template <class ForwardIterator, class Predicate>
561 ForwardIterator
562 stable_partition(ForwardIterator first, ForwardIterator last, Predicate pred);
563
564template<class ForwardIterator, class Predicate>
Marshall Clowd57c03d2018-01-16 02:34:41565 constexpr ForwardIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16566 partition_point(ForwardIterator first, ForwardIterator last, Predicate pred);
567
568template <class ForwardIterator>
Marshall Clow49c76432018-01-15 16:16:32569 constexpr bool // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16570 is_sorted(ForwardIterator first, ForwardIterator last);
571
572template <class ForwardIterator, class Compare>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:18573 constexpr bool // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16574 is_sorted(ForwardIterator first, ForwardIterator last, Compare comp);
575
576template<class ForwardIterator>
Marshall Clow056f15e2018-01-15 19:40:34577 constexpr ForwardIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16578 is_sorted_until(ForwardIterator first, ForwardIterator last);
579
580template <class ForwardIterator, class Compare>
Marshall Clow056f15e2018-01-15 19:40:34581 constexpr ForwardIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16582 is_sorted_until(ForwardIterator first, ForwardIterator last, Compare comp);
583
584template <class RandomAccessIterator>
Arthur O'Dwyer493f1402020-12-20 20:21:42585 constexpr void // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16586 sort(RandomAccessIterator first, RandomAccessIterator last);
587
588template <class RandomAccessIterator, class Compare>
Arthur O'Dwyer493f1402020-12-20 20:21:42589 constexpr void // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16590 sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
591
592template <class RandomAccessIterator>
593 void
594 stable_sort(RandomAccessIterator first, RandomAccessIterator last);
595
596template <class RandomAccessIterator, class Compare>
597 void
598 stable_sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
599
600template <class RandomAccessIterator>
Arthur O'Dwyer5386aa22020-12-17 05:26:18601 constexpr void // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16602 partial_sort(RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last);
603
604template <class RandomAccessIterator, class Compare>
Arthur O'Dwyer5386aa22020-12-17 05:26:18605 constexpr void // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16606 partial_sort(RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last, Compare comp);
607
608template <class InputIterator, class RandomAccessIterator>
Arthur O'Dwyer5386aa22020-12-17 05:26:18609 constexpr RandomAccessIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16610 partial_sort_copy(InputIterator first, InputIterator last,
611 RandomAccessIterator result_first, RandomAccessIterator result_last);
612
613template <class InputIterator, class RandomAccessIterator, class Compare>
Arthur O'Dwyer5386aa22020-12-17 05:26:18614 constexpr RandomAccessIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16615 partial_sort_copy(InputIterator first, InputIterator last,
616 RandomAccessIterator result_first, RandomAccessIterator result_last, Compare comp);
617
618template <class RandomAccessIterator>
Arthur O'Dwyer5d956562021-02-04 23:12:52619 constexpr void // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16620 nth_element(RandomAccessIterator first, RandomAccessIterator nth, RandomAccessIterator last);
621
622template <class RandomAccessIterator, class Compare>
Arthur O'Dwyer5d956562021-02-04 23:12:52623 constexpr void // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16624 nth_element(RandomAccessIterator first, RandomAccessIterator nth, RandomAccessIterator last, Compare comp);
625
626template <class ForwardIterator, class T>
Marshall Clowd57c03d2018-01-16 02:34:41627 constexpr ForwardIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16628 lower_bound(ForwardIterator first, ForwardIterator last, const T& value);
629
630template <class ForwardIterator, class T, class Compare>
Marshall Clowd57c03d2018-01-16 02:34:41631 constexpr ForwardIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16632 lower_bound(ForwardIterator first, ForwardIterator last, const T& value, Compare comp);
633
634template <class ForwardIterator, class T>
Marshall Clowd57c03d2018-01-16 02:34:41635 constexpr ForwardIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16636 upper_bound(ForwardIterator first, ForwardIterator last, const T& value);
637
638template <class ForwardIterator, class T, class Compare>
Marshall Clowd57c03d2018-01-16 02:34:41639 constexpr ForwardIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16640 upper_bound(ForwardIterator first, ForwardIterator last, const T& value, Compare comp);
641
642template <class ForwardIterator, class T>
Marshall Clowd57c03d2018-01-16 02:34:41643 constexpr pair<ForwardIterator, ForwardIterator> // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16644 equal_range(ForwardIterator first, ForwardIterator last, const T& value);
645
646template <class ForwardIterator, class T, class Compare>
Marshall Clowd57c03d2018-01-16 02:34:41647 constexpr pair<ForwardIterator, ForwardIterator> // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16648 equal_range(ForwardIterator first, ForwardIterator last, const T& value, Compare comp);
649
650template <class ForwardIterator, class T>
Marshall Clowd57c03d2018-01-16 02:34:41651 constexpr bool // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16652 binary_search(ForwardIterator first, ForwardIterator last, const T& value);
653
654template <class ForwardIterator, class T, class Compare>
Marshall Clow8da1a482018-01-22 23:10:40655 constexpr bool // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16656 binary_search(ForwardIterator first, ForwardIterator last, const T& value, Compare comp);
657
658template <class InputIterator1, class InputIterator2, class OutputIterator>
Arthur O'Dwyer14098cf2020-12-04 18:47:12659 constexpr OutputIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16660 merge(InputIterator1 first1, InputIterator1 last1,
661 InputIterator2 first2, InputIterator2 last2, OutputIterator result);
662
663template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
Arthur O'Dwyer14098cf2020-12-04 18:47:12664 constexpr OutputIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16665 merge(InputIterator1 first1, InputIterator1 last1,
666 InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
667
668template <class BidirectionalIterator>
669 void
670 inplace_merge(BidirectionalIterator first, BidirectionalIterator middle, BidirectionalIterator last);
671
672template <class BidirectionalIterator, class Compare>
673 void
674 inplace_merge(BidirectionalIterator first, BidirectionalIterator middle, BidirectionalIterator last, Compare comp);
675
676template <class InputIterator1, class InputIterator2>
Marshall Clow8da1a482018-01-22 23:10:40677 constexpr bool // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16678 includes(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2);
679
680template <class InputIterator1, class InputIterator2, class Compare>
Marshall Clow8da1a482018-01-22 23:10:40681 constexpr bool // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16682 includes(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, Compare comp);
683
684template <class InputIterator1, class InputIterator2, class OutputIterator>
Arthur O'Dwyer14098cf2020-12-04 18:47:12685 constexpr OutputIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16686 set_union(InputIterator1 first1, InputIterator1 last1,
687 InputIterator2 first2, InputIterator2 last2, OutputIterator result);
688
689template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
Arthur O'Dwyer14098cf2020-12-04 18:47:12690 constexpr OutputIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16691 set_union(InputIterator1 first1, InputIterator1 last1,
692 InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
693
694template <class InputIterator1, class InputIterator2, class OutputIterator>
Marshall Clow8da1a482018-01-22 23:10:40695 constexpr OutputIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16696 set_intersection(InputIterator1 first1, InputIterator1 last1,
697 InputIterator2 first2, InputIterator2 last2, OutputIterator result);
698
699template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
Marshall Clow8da1a482018-01-22 23:10:40700 constexpr OutputIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16701 set_intersection(InputIterator1 first1, InputIterator1 last1,
702 InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
703
704template <class InputIterator1, class InputIterator2, class OutputIterator>
Arthur O'Dwyer14098cf2020-12-04 18:47:12705 constexpr OutputIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16706 set_difference(InputIterator1 first1, InputIterator1 last1,
707 InputIterator2 first2, InputIterator2 last2, OutputIterator result);
708
709template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
Arthur O'Dwyer14098cf2020-12-04 18:47:12710 constexpr OutputIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16711 set_difference(InputIterator1 first1, InputIterator1 last1,
712 InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
713
714template <class InputIterator1, class InputIterator2, class OutputIterator>
Arthur O'Dwyer14098cf2020-12-04 18:47:12715 constexpr OutputIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16716 set_symmetric_difference(InputIterator1 first1, InputIterator1 last1,
717 InputIterator2 first2, InputIterator2 last2, OutputIterator result);
718
719template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
Arthur O'Dwyer14098cf2020-12-04 18:47:12720 constexpr OutputIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16721 set_symmetric_difference(InputIterator1 first1, InputIterator1 last1,
722 InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
723
724template <class RandomAccessIterator>
Arthur O'Dwyer5386aa22020-12-17 05:26:18725 constexpr void // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16726 push_heap(RandomAccessIterator first, RandomAccessIterator last);
727
728template <class RandomAccessIterator, class Compare>
Arthur O'Dwyer5386aa22020-12-17 05:26:18729 constexpr void // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16730 push_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
731
732template <class RandomAccessIterator>
Arthur O'Dwyer5386aa22020-12-17 05:26:18733 constexpr void // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16734 pop_heap(RandomAccessIterator first, RandomAccessIterator last);
735
736template <class RandomAccessIterator, class Compare>
Arthur O'Dwyer5386aa22020-12-17 05:26:18737 constexpr void // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16738 pop_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
739
740template <class RandomAccessIterator>
Arthur O'Dwyer5386aa22020-12-17 05:26:18741 constexpr void // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16742 make_heap(RandomAccessIterator first, RandomAccessIterator last);
743
744template <class RandomAccessIterator, class Compare>
Arthur O'Dwyer5386aa22020-12-17 05:26:18745 constexpr void // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16746 make_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
747
748template <class RandomAccessIterator>
Arthur O'Dwyer5386aa22020-12-17 05:26:18749 constexpr void // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16750 sort_heap(RandomAccessIterator first, RandomAccessIterator last);
751
752template <class RandomAccessIterator, class Compare>
Arthur O'Dwyer5386aa22020-12-17 05:26:18753 constexpr void // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16754 sort_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
755
Howard Hinnantb3371f62010-08-22 00:02:43756template <class RandomAccessIterator>
Marshall Clow49c76432018-01-15 16:16:32757 constexpr bool // constexpr in C++20
Howard Hinnantb3371f62010-08-22 00:02:43758 is_heap(RandomAccessIterator first, RandomAccessiterator last);
Howard Hinnant3e519522010-05-11 19:42:16759
Howard Hinnantb3371f62010-08-22 00:02:43760template <class RandomAccessIterator, class Compare>
Marshall Clow49c76432018-01-15 16:16:32761 constexpr bool // constexpr in C++20
Howard Hinnantb3371f62010-08-22 00:02:43762 is_heap(RandomAccessIterator first, RandomAccessiterator last, Compare comp);
Howard Hinnant3e519522010-05-11 19:42:16763
Howard Hinnantb3371f62010-08-22 00:02:43764template <class RandomAccessIterator>
Marshall Clow49c76432018-01-15 16:16:32765 constexpr RandomAccessIterator // constexpr in C++20
Howard Hinnantb3371f62010-08-22 00:02:43766 is_heap_until(RandomAccessIterator first, RandomAccessiterator last);
Howard Hinnant3e519522010-05-11 19:42:16767
Howard Hinnantb3371f62010-08-22 00:02:43768template <class RandomAccessIterator, class Compare>
Marshall Clow49c76432018-01-15 16:16:32769 constexpr RandomAccessIterator // constexpr in C++20
Howard Hinnantb3371f62010-08-22 00:02:43770 is_heap_until(RandomAccessIterator first, RandomAccessiterator last, Compare comp);
Howard Hinnant3e519522010-05-11 19:42:16771
Howard Hinnant4eb27b72010-08-21 20:10:01772template <class ForwardIterator>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:18773 constexpr ForwardIterator // constexpr in C++14
774 min_element(ForwardIterator first, ForwardIterator last);
Howard Hinnant4eb27b72010-08-21 20:10:01775
776template <class ForwardIterator, class Compare>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:18777 constexpr ForwardIterator // constexpr in C++14
778 min_element(ForwardIterator first, ForwardIterator last, Compare comp);
Howard Hinnant4eb27b72010-08-21 20:10:01779
Howard Hinnant3e519522010-05-11 19:42:16780template <class T>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:18781 constexpr const T& // constexpr in C++14
782 min(const T& a, const T& b);
Howard Hinnant3e519522010-05-11 19:42:16783
784template <class T, class Compare>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:18785 constexpr const T& // constexpr in C++14
786 min(const T& a, const T& b, Compare comp);
Howard Hinnant3e519522010-05-11 19:42:16787
Howard Hinnant4eb27b72010-08-21 20:10:01788template<class T>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:18789 constexpr T // constexpr in C++14
790 min(initializer_list<T> t);
Howard Hinnant4eb27b72010-08-21 20:10:01791
792template<class T, class Compare>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:18793 constexpr T // constexpr in C++14
794 min(initializer_list<T> t, Compare comp);
Howard Hinnant4eb27b72010-08-21 20:10:01795
Marshall Clow146c14a2016-03-07 22:43:49796template<class T>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:18797 constexpr const T& clamp(const T& v, const T& lo, const T& hi); // C++17
Marshall Clow146c14a2016-03-07 22:43:49798
799template<class T, class Compare>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:18800 constexpr const T& clamp(const T& v, const T& lo, const T& hi, Compare comp); // C++17
Marshall Clow146c14a2016-03-07 22:43:49801
Howard Hinnant4eb27b72010-08-21 20:10:01802template <class ForwardIterator>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:18803 constexpr ForwardIterator // constexpr in C++14
804 max_element(ForwardIterator first, ForwardIterator last);
Howard Hinnant4eb27b72010-08-21 20:10:01805
806template <class ForwardIterator, class Compare>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:18807 constexpr ForwardIterator // constexpr in C++14
808 max_element(ForwardIterator first, ForwardIterator last, Compare comp);
Howard Hinnant4eb27b72010-08-21 20:10:01809
Howard Hinnant3e519522010-05-11 19:42:16810template <class T>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:18811 constexpr const T& // constexpr in C++14
812 max(const T& a, const T& b);
Howard Hinnant3e519522010-05-11 19:42:16813
814template <class T, class Compare>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:18815 constexpr const T& // constexpr in C++14
816 max(const T& a, const T& b, Compare comp);
Howard Hinnant3e519522010-05-11 19:42:16817
Howard Hinnant4eb27b72010-08-21 20:10:01818template<class T>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:18819 constexpr T // constexpr in C++14
820 max(initializer_list<T> t);
Howard Hinnant3e519522010-05-11 19:42:16821
Howard Hinnant4eb27b72010-08-21 20:10:01822template<class T, class Compare>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:18823 constexpr T // constexpr in C++14
824 max(initializer_list<T> t, Compare comp);
Howard Hinnant3e519522010-05-11 19:42:16825
Howard Hinnant4eb27b72010-08-21 20:10:01826template<class ForwardIterator>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:18827 constexpr pair<ForwardIterator, ForwardIterator> // constexpr in C++14
828 minmax_element(ForwardIterator first, ForwardIterator last);
Howard Hinnant3e519522010-05-11 19:42:16829
Howard Hinnant4eb27b72010-08-21 20:10:01830template<class ForwardIterator, class Compare>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:18831 constexpr pair<ForwardIterator, ForwardIterator> // constexpr in C++14
832 minmax_element(ForwardIterator first, ForwardIterator last, Compare comp);
Howard Hinnant4eb27b72010-08-21 20:10:01833
834template<class T>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:18835 constexpr pair<const T&, const T&> // constexpr in C++14
836 minmax(const T& a, const T& b);
Howard Hinnant4eb27b72010-08-21 20:10:01837
838template<class T, class Compare>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:18839 constexpr pair<const T&, const T&> // constexpr in C++14
840 minmax(const T& a, const T& b, Compare comp);
Howard Hinnant4eb27b72010-08-21 20:10:01841
842template<class T>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:18843 constexpr pair<T, T> // constexpr in C++14
844 minmax(initializer_list<T> t);
Howard Hinnant4eb27b72010-08-21 20:10:01845
846template<class T, class Compare>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:18847 constexpr pair<T, T> // constexpr in C++14
848 minmax(initializer_list<T> t, Compare comp);
Howard Hinnant3e519522010-05-11 19:42:16849
850template <class InputIterator1, class InputIterator2>
Marshall Clow1b9a4ff2018-01-22 20:44:33851 constexpr bool // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16852 lexicographical_compare(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2);
853
854template <class InputIterator1, class InputIterator2, class Compare>
Marshall Clow1b9a4ff2018-01-22 20:44:33855 constexpr bool // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16856 lexicographical_compare(InputIterator1 first1, InputIterator1 last1,
857 InputIterator2 first2, InputIterator2 last2, Compare comp);
858
859template <class BidirectionalIterator>
Arthur O'Dwyerf851db32020-12-17 05:01:08860 constexpr bool // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16861 next_permutation(BidirectionalIterator first, BidirectionalIterator last);
862
863template <class BidirectionalIterator, class Compare>
Arthur O'Dwyerf851db32020-12-17 05:01:08864 constexpr bool // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16865 next_permutation(BidirectionalIterator first, BidirectionalIterator last, Compare comp);
866
867template <class BidirectionalIterator>
Arthur O'Dwyerf851db32020-12-17 05:01:08868 constexpr bool // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16869 prev_permutation(BidirectionalIterator first, BidirectionalIterator last);
870
871template <class BidirectionalIterator, class Compare>
Arthur O'Dwyerf851db32020-12-17 05:01:08872 constexpr bool // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16873 prev_permutation(BidirectionalIterator first, BidirectionalIterator last, Compare comp);
Howard Hinnant3e519522010-05-11 19:42:16874} // std
875
876*/
877
Louis Dionne385cc252022-03-25 16:55:36878#include <__assert> // all public C++ headers provide the assertion handler
Arthur O'Dwyerea2206d2022-02-04 18:09:30879#include <__bits>
Howard Hinnant3e519522010-05-11 19:42:16880#include <__config>
Louis Dionne134723e2021-06-17 15:30:11881#include <__debug>
Howard Hinnanta1d07d52012-07-26 17:09:09882#include <cstddef>
Arthur O'Dwyerbfbd73f2021-05-19 15:57:04883#include <cstring>
884#include <functional>
885#include <initializer_list>
Arthur O'Dwyerbfbd73f2021-05-19 15:57:04886#include <iterator>
887#include <memory>
888#include <type_traits>
Marshall Clowf56972e2018-09-12 19:41:40889#include <version>
Howard Hinnant5d1a7012013-08-14 18:00:20890
Louis Dionne134723e2021-06-17 15:30:11891#include <__algorithm/adjacent_find.h>
892#include <__algorithm/all_of.h>
893#include <__algorithm/any_of.h>
894#include <__algorithm/binary_search.h>
895#include <__algorithm/clamp.h>
896#include <__algorithm/comp.h>
897#include <__algorithm/comp_ref_type.h>
898#include <__algorithm/copy.h>
899#include <__algorithm/copy_backward.h>
900#include <__algorithm/copy_if.h>
901#include <__algorithm/copy_n.h>
902#include <__algorithm/count.h>
903#include <__algorithm/count_if.h>
904#include <__algorithm/equal.h>
905#include <__algorithm/equal_range.h>
Louis Dionne134723e2021-06-17 15:30:11906#include <__algorithm/fill.h>
Arthur O'Dwyer4d81a462022-01-07 14:45:05907#include <__algorithm/fill_n.h>
Louis Dionne134723e2021-06-17 15:30:11908#include <__algorithm/find.h>
909#include <__algorithm/find_end.h>
910#include <__algorithm/find_first_of.h>
911#include <__algorithm/find_if.h>
912#include <__algorithm/find_if_not.h>
913#include <__algorithm/for_each.h>
914#include <__algorithm/for_each_n.h>
Louis Dionne134723e2021-06-17 15:30:11915#include <__algorithm/generate.h>
Arthur O'Dwyer4d81a462022-01-07 14:45:05916#include <__algorithm/generate_n.h>
Louis Dionne134723e2021-06-17 15:30:11917#include <__algorithm/half_positive.h>
Nikolas Klauser68f41312022-02-21 22:07:02918#include <__algorithm/in_found_result.h>
Nikolas Klauser1e77b392022-02-11 16:01:58919#include <__algorithm/in_fun_result.h>
Nikolas Klauserf3514af2022-01-25 10:21:47920#include <__algorithm/in_in_out_result.h>
Nikolas Klauserd3729bb2022-01-14 01:55:51921#include <__algorithm/in_in_result.h>
Nikolas Klauser610979b2022-02-03 01:17:03922#include <__algorithm/in_out_out_result.h>
Konstantin Varlamov8d23b742022-01-11 06:49:37923#include <__algorithm/in_out_result.h>
Louis Dionne134723e2021-06-17 15:30:11924#include <__algorithm/includes.h>
925#include <__algorithm/inplace_merge.h>
926#include <__algorithm/is_heap.h>
927#include <__algorithm/is_heap_until.h>
928#include <__algorithm/is_partitioned.h>
929#include <__algorithm/is_permutation.h>
930#include <__algorithm/is_sorted.h>
931#include <__algorithm/is_sorted_until.h>
Christopher Di Bella6adbc832021-06-05 02:47:47932#include <__algorithm/iter_swap.h>
Louis Dionne134723e2021-06-17 15:30:11933#include <__algorithm/lexicographical_compare.h>
934#include <__algorithm/lower_bound.h>
935#include <__algorithm/make_heap.h>
936#include <__algorithm/max.h>
937#include <__algorithm/max_element.h>
938#include <__algorithm/merge.h>
939#include <__algorithm/min.h>
940#include <__algorithm/min_element.h>
Nikolas Klauser807766b2022-02-21 21:48:36941#include <__algorithm/min_max_result.h>
Louis Dionne134723e2021-06-17 15:30:11942#include <__algorithm/minmax.h>
943#include <__algorithm/minmax_element.h>
944#include <__algorithm/mismatch.h>
945#include <__algorithm/move.h>
946#include <__algorithm/move_backward.h>
947#include <__algorithm/next_permutation.h>
948#include <__algorithm/none_of.h>
949#include <__algorithm/nth_element.h>
950#include <__algorithm/partial_sort.h>
951#include <__algorithm/partial_sort_copy.h>
952#include <__algorithm/partition.h>
953#include <__algorithm/partition_copy.h>
954#include <__algorithm/partition_point.h>
955#include <__algorithm/pop_heap.h>
956#include <__algorithm/prev_permutation.h>
957#include <__algorithm/push_heap.h>
Nikolas Klauser1d837502022-04-15 11:43:40958#include <__algorithm/ranges_copy.h>
959#include <__algorithm/ranges_copy_backward.h>
960#include <__algorithm/ranges_copy_if.h>
961#include <__algorithm/ranges_copy_n.h>
Nikolas Klauser1306b102022-04-07 11:02:02962#include <__algorithm/ranges_count.h>
963#include <__algorithm/ranges_count_if.h>
Nikolas Klauseree0f8c42022-03-12 00:45:35964#include <__algorithm/ranges_find.h>
965#include <__algorithm/ranges_find_if.h>
966#include <__algorithm/ranges_find_if_not.h>
Nikolas Klausere476df52022-04-03 07:17:01967#include <__algorithm/ranges_max.h>
Nikolas Klauser205557c2022-03-07 16:01:52968#include <__algorithm/ranges_max_element.h>
Nikolas Klauserf83d8332022-03-18 01:57:08969#include <__algorithm/ranges_min.h>
Nikolas Klauser3b470d12022-02-11 12:11:57970#include <__algorithm/ranges_min_element.h>
Nikolas Klauser58d9ab72022-04-13 20:59:09971#include <__algorithm/ranges_minmax.h>
972#include <__algorithm/ranges_minmax_element.h>
Nikolas Klauserc2cd15a2022-03-08 22:12:35973#include <__algorithm/ranges_mismatch.h>
Nikolas Klauser9d905312022-02-10 12:33:03974#include <__algorithm/ranges_swap_ranges.h>
Nikolas Klauser3ba85482022-04-05 09:05:36975#include <__algorithm/ranges_transform.h>
Louis Dionne134723e2021-06-17 15:30:11976#include <__algorithm/remove.h>
977#include <__algorithm/remove_copy.h>
978#include <__algorithm/remove_copy_if.h>
979#include <__algorithm/remove_if.h>
980#include <__algorithm/replace.h>
981#include <__algorithm/replace_copy.h>
982#include <__algorithm/replace_copy_if.h>
983#include <__algorithm/replace_if.h>
984#include <__algorithm/reverse.h>
985#include <__algorithm/reverse_copy.h>
986#include <__algorithm/rotate.h>
987#include <__algorithm/rotate_copy.h>
988#include <__algorithm/sample.h>
989#include <__algorithm/search.h>
990#include <__algorithm/search_n.h>
991#include <__algorithm/set_difference.h>
992#include <__algorithm/set_intersection.h>
993#include <__algorithm/set_symmetric_difference.h>
994#include <__algorithm/set_union.h>
995#include <__algorithm/shift_left.h>
996#include <__algorithm/shift_right.h>
997#include <__algorithm/shuffle.h>
998#include <__algorithm/sift_down.h>
999#include <__algorithm/sort.h>
1000#include <__algorithm/sort_heap.h>
1001#include <__algorithm/stable_partition.h>
1002#include <__algorithm/stable_sort.h>
Christopher Di Bella6adbc832021-06-05 02:47:471003#include <__algorithm/swap_ranges.h>
Louis Dionne134723e2021-06-17 15:30:111004#include <__algorithm/transform.h>
Louis Dionne134723e2021-06-17 15:30:111005#include <__algorithm/unique.h>
Arthur O'Dwyer4d81a462022-01-07 14:45:051006#include <__algorithm/unique_copy.h>
Louis Dionne134723e2021-06-17 15:30:111007#include <__algorithm/unwrap_iter.h>
1008#include <__algorithm/upper_bound.h>
Eric Fiselierc1bd9192014-08-10 23:53:081009
Howard Hinnant073458b2011-10-17 20:05:101010#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Arthur O'Dwyerfa6b9e42022-02-02 01:16:401011# pragma GCC system_header
Howard Hinnant073458b2011-10-17 20:05:101012#endif
Howard Hinnant3e519522010-05-11 19:42:161013
Louis Dionne0a06eb92019-08-05 18:29:141014#if defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS) && _LIBCPP_STD_VER >= 17
Louis Dionne95689242019-08-06 21:11:241015# include <__pstl_algorithm>
Louis Dionne0a06eb92019-08-05 18:29:141016#endif
1017
Louis Dionne4cd6ca12021-04-20 16:03:321018#endif // _LIBCPP_ALGORITHM