blob: be10e3065f2f079d84a184f76448f52e2e41e60f [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>
23 struct in_fun_result; // since C++20
24
Nikolas Klauserd3729bb2022-01-14 01:55:5125 template <class I1, class I2>
Nikolas Klauserf3514af2022-01-25 10:21:4726 struct in_in_result; // since C++20
27
28 template <class I1, class I2, class O>
29 struct in_in_out_result; // since C++20
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
34 template<class I, class O>
35 struct in_out_result; // since C++20
Nikolas Klauserd3729bb2022-01-14 01:55:5136}
37
Howard Hinnant3e519522010-05-11 19:42:1638template <class InputIterator, class Predicate>
Marshall Clow706ffef2018-01-15 17:20:3639 constexpr bool // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:1640 all_of(InputIterator first, InputIterator last, Predicate pred);
41
42template <class InputIterator, class Predicate>
Marshall Clow706ffef2018-01-15 17:20:3643 constexpr bool // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:1644 any_of(InputIterator first, InputIterator last, Predicate pred);
45
46template <class InputIterator, class Predicate>
Marshall Clow706ffef2018-01-15 17:20:3647 constexpr bool // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:1648 none_of(InputIterator first, InputIterator last, Predicate pred);
49
50template <class InputIterator, class Function>
Marshall Clow1b9a4ff2018-01-22 20:44:3351 constexpr Function // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:1652 for_each(InputIterator first, InputIterator last, Function f);
53
Marshall Clowd5c65ff2017-05-25 02:29:5454template<class InputIterator, class Size, class Function>
Marshall Clow1b9a4ff2018-01-22 20:44:3355 constexpr InputIterator // constexpr in C++20
56 for_each_n(InputIterator first, Size n, Function f); // C++17
Marshall Clowd5c65ff2017-05-25 02:29:5457
Howard Hinnant3e519522010-05-11 19:42:1658template <class InputIterator, class T>
Marshall Clow86944282018-01-15 19:26:0559 constexpr InputIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:1660 find(InputIterator first, InputIterator last, const T& value);
61
62template <class InputIterator, class Predicate>
Marshall Clow86944282018-01-15 19:26:0563 constexpr InputIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:1664 find_if(InputIterator first, InputIterator last, Predicate pred);
65
66template<class InputIterator, class Predicate>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:1867 constexpr InputIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:1668 find_if_not(InputIterator first, InputIterator last, Predicate pred);
69
70template <class ForwardIterator1, class ForwardIterator2>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:1871 constexpr ForwardIterator1 // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:1672 find_end(ForwardIterator1 first1, ForwardIterator1 last1,
73 ForwardIterator2 first2, ForwardIterator2 last2);
74
75template <class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:1876 constexpr ForwardIterator1 // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:1677 find_end(ForwardIterator1 first1, ForwardIterator1 last1,
78 ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred);
79
80template <class ForwardIterator1, class ForwardIterator2>
Marshall Clow86944282018-01-15 19:26:0581 constexpr ForwardIterator1 // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:1682 find_first_of(ForwardIterator1 first1, ForwardIterator1 last1,
83 ForwardIterator2 first2, ForwardIterator2 last2);
84
85template <class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
Marshall Clow86944282018-01-15 19:26:0586 constexpr ForwardIterator1 // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:1687 find_first_of(ForwardIterator1 first1, ForwardIterator1 last1,
88 ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred);
89
90template <class ForwardIterator>
Marshall Clow86944282018-01-15 19:26:0591 constexpr ForwardIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:1692 adjacent_find(ForwardIterator first, ForwardIterator last);
93
94template <class ForwardIterator, class BinaryPredicate>
Marshall Clow86944282018-01-15 19:26:0595 constexpr ForwardIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:1696 adjacent_find(ForwardIterator first, ForwardIterator last, BinaryPredicate pred);
97
98template <class InputIterator, class T>
Marshall Clow056f15e2018-01-15 19:40:3499 constexpr typename iterator_traits<InputIterator>::difference_type // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16100 count(InputIterator first, InputIterator last, const T& value);
101
102template <class InputIterator, class Predicate>
Marshall Clow056f15e2018-01-15 19:40:34103 constexpr typename iterator_traits<InputIterator>::difference_type // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16104 count_if(InputIterator first, InputIterator last, Predicate pred);
105
106template <class InputIterator1, class InputIterator2>
Marshall Clow6538e28d2018-01-16 02:04:10107 constexpr pair<InputIterator1, InputIterator2> // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16108 mismatch(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2);
109
Marshall Clow0b0bbd22013-05-09 21:14:23110template <class InputIterator1, class InputIterator2>
Marshall Clow6538e28d2018-01-16 02:04:10111 constexpr pair<InputIterator1, InputIterator2> // constexpr in C++20
Aditya Kumar331fb802016-08-25 11:52:38112 mismatch(InputIterator1 first1, InputIterator1 last1,
Marshall Clow0b0bbd22013-05-09 21:14:23113 InputIterator2 first2, InputIterator2 last2); // **C++14**
114
Howard Hinnant3e519522010-05-11 19:42:16115template <class InputIterator1, class InputIterator2, class BinaryPredicate>
Marshall Clow6538e28d2018-01-16 02:04:10116 constexpr pair<InputIterator1, InputIterator2> // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16117 mismatch(InputIterator1 first1, InputIterator1 last1,
118 InputIterator2 first2, BinaryPredicate pred);
119
Marshall Clow0b0bbd22013-05-09 21:14:23120template <class InputIterator1, class InputIterator2, class BinaryPredicate>
Marshall Clow6538e28d2018-01-16 02:04:10121 constexpr pair<InputIterator1, InputIterator2> // constexpr in C++20
Marshall Clow0b0bbd22013-05-09 21:14:23122 mismatch(InputIterator1 first1, InputIterator1 last1,
123 InputIterator2 first2, InputIterator2 last2,
124 BinaryPredicate pred); // **C++14**
125
Howard Hinnant3e519522010-05-11 19:42:16126template <class InputIterator1, class InputIterator2>
Marshall Clow6538e28d2018-01-16 02:04:10127 constexpr bool // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16128 equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2);
129
Marshall Clow0b0bbd22013-05-09 21:14:23130template <class InputIterator1, class InputIterator2>
Marshall Clow6538e28d2018-01-16 02:04:10131 constexpr bool // constexpr in C++20
Aditya Kumar331fb802016-08-25 11:52:38132 equal(InputIterator1 first1, InputIterator1 last1,
Marshall Clow0b0bbd22013-05-09 21:14:23133 InputIterator2 first2, InputIterator2 last2); // **C++14**
134
Howard Hinnant3e519522010-05-11 19:42:16135template <class InputIterator1, class InputIterator2, class BinaryPredicate>
Marshall Clow6538e28d2018-01-16 02:04:10136 constexpr bool // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16137 equal(InputIterator1 first1, InputIterator1 last1,
138 InputIterator2 first2, BinaryPredicate pred);
139
Marshall Clow0b0bbd22013-05-09 21:14:23140template <class InputIterator1, class InputIterator2, class BinaryPredicate>
Marshall Clow6538e28d2018-01-16 02:04:10141 constexpr bool // constexpr in C++20
Marshall Clow0b0bbd22013-05-09 21:14:23142 equal(InputIterator1 first1, InputIterator1 last1,
143 InputIterator2 first2, InputIterator2 last2,
144 BinaryPredicate pred); // **C++14**
145
Howard Hinnant3e519522010-05-11 19:42:16146template<class ForwardIterator1, class ForwardIterator2>
Marshall Clow49c76432018-01-15 16:16:32147 constexpr bool // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16148 is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
149 ForwardIterator2 first2);
150
Marshall Clow0b0bbd22013-05-09 21:14:23151template<class ForwardIterator1, class ForwardIterator2>
Marshall Clow49c76432018-01-15 16:16:32152 constexpr bool // constexpr in C++20
Marshall Clow0b0bbd22013-05-09 21:14:23153 is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
154 ForwardIterator2 first2, ForwardIterator2 last2); // **C++14**
155
Howard Hinnant3e519522010-05-11 19:42:16156template<class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
Marshall Clow49c76432018-01-15 16:16:32157 constexpr bool // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16158 is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
159 ForwardIterator2 first2, BinaryPredicate pred);
160
Marshall Clow0b0bbd22013-05-09 21:14:23161template<class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
Marshall Clow49c76432018-01-15 16:16:32162 constexpr bool // constexpr in C++20
Marshall Clow0b0bbd22013-05-09 21:14:23163 is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
164 ForwardIterator2 first2, ForwardIterator2 last2,
165 BinaryPredicate pred); // **C++14**
166
Howard Hinnant3e519522010-05-11 19:42:16167template <class ForwardIterator1, class ForwardIterator2>
Marshall Clow12f0a772018-01-16 15:48:27168 constexpr ForwardIterator1 // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16169 search(ForwardIterator1 first1, ForwardIterator1 last1,
170 ForwardIterator2 first2, ForwardIterator2 last2);
171
172template <class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
Marshall Clow12f0a772018-01-16 15:48:27173 constexpr ForwardIterator1 // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16174 search(ForwardIterator1 first1, ForwardIterator1 last1,
175 ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred);
176
177template <class ForwardIterator, class Size, class T>
Marshall Clow12f0a772018-01-16 15:48:27178 constexpr ForwardIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16179 search_n(ForwardIterator first, ForwardIterator last, Size count, const T& value);
180
181template <class ForwardIterator, class Size, class T, class BinaryPredicate>
Marshall Clow12f0a772018-01-16 15:48:27182 constexpr ForwardIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16183 search_n(ForwardIterator first, ForwardIterator last,
184 Size count, const T& value, BinaryPredicate pred);
185
186template <class InputIterator, class OutputIterator>
Louis Dionne13c90a52019-11-06 12:02:41187 constexpr OutputIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16188 copy(InputIterator first, InputIterator last, OutputIterator result);
189
190template<class InputIterator, class OutputIterator, class Predicate>
Louis Dionne13c90a52019-11-06 12:02:41191 constexpr OutputIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16192 copy_if(InputIterator first, InputIterator last,
193 OutputIterator result, Predicate pred);
194
195template<class InputIterator, class Size, class OutputIterator>
Louis Dionne13c90a52019-11-06 12:02:41196 constexpr OutputIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16197 copy_n(InputIterator first, Size n, OutputIterator result);
198
199template <class BidirectionalIterator1, class BidirectionalIterator2>
Louis Dionne13c90a52019-11-06 12:02:41200 constexpr BidirectionalIterator2 // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16201 copy_backward(BidirectionalIterator1 first, BidirectionalIterator1 last,
202 BidirectionalIterator2 result);
203
204template <class ForwardIterator1, class ForwardIterator2>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:18205 constexpr ForwardIterator2 // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16206 swap_ranges(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2);
207
Nikolas Klauser9d905312022-02-10 12:33:03208template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2>
209 requires indirectly_swappable<I1, I2>
210 constexpr ranges::swap_ranges_result<I1, I2>
211 ranges::swap_ranges(I1 first1, S1 last1, I2 first2, S2 last2);
212
213template<input_range R1, input_range R2>
214 requires indirectly_swappable<iterator_t<R1>, iterator_t<R2>>
215 constexpr ranges::swap_ranges_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>>
216 ranges::swap_ranges(R1&& r1, R2&& r2);
217
Howard Hinnant3e519522010-05-11 19:42:16218template <class ForwardIterator1, class ForwardIterator2>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:18219 constexpr void // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16220 iter_swap(ForwardIterator1 a, ForwardIterator2 b);
221
222template <class InputIterator, class OutputIterator, class UnaryOperation>
Marshall Clow99894b62018-01-19 17:45:39223 constexpr OutputIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16224 transform(InputIterator first, InputIterator last, OutputIterator result, UnaryOperation op);
225
226template <class InputIterator1, class InputIterator2, class OutputIterator, class BinaryOperation>
Marshall Clow99894b62018-01-19 17:45:39227 constexpr OutputIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16228 transform(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2,
229 OutputIterator result, BinaryOperation binary_op);
230
231template <class ForwardIterator, class T>
Marshall Clow12c74232018-01-19 18:07:29232 constexpr void // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16233 replace(ForwardIterator first, ForwardIterator last, const T& old_value, const T& new_value);
234
235template <class ForwardIterator, class Predicate, class T>
Marshall Clow12c74232018-01-19 18:07:29236 constexpr void // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16237 replace_if(ForwardIterator first, ForwardIterator last, Predicate pred, const T& new_value);
238
239template <class InputIterator, class OutputIterator, class T>
Marshall Clow12c74232018-01-19 18:07:29240 constexpr OutputIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16241 replace_copy(InputIterator first, InputIterator last, OutputIterator result,
242 const T& old_value, const T& new_value);
243
244template <class InputIterator, class OutputIterator, class Predicate, class T>
Marshall Clow12c74232018-01-19 18:07:29245 constexpr OutputIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16246 replace_copy_if(InputIterator first, InputIterator last, OutputIterator result, Predicate pred, const T& new_value);
247
248template <class ForwardIterator, class T>
Marshall Clow4bfb9312018-01-20 20:14:32249 constexpr void // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16250 fill(ForwardIterator first, ForwardIterator last, const T& value);
251
252template <class OutputIterator, class Size, class T>
Marshall Clow4bfb9312018-01-20 20:14:32253 constexpr OutputIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16254 fill_n(OutputIterator first, Size n, const T& value);
255
256template <class ForwardIterator, class Generator>
Marshall Clow4bfb9312018-01-20 20:14:32257 constexpr void // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16258 generate(ForwardIterator first, ForwardIterator last, Generator gen);
259
260template <class OutputIterator, class Size, class Generator>
Marshall Clow4bfb9312018-01-20 20:14:32261 constexpr OutputIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16262 generate_n(OutputIterator first, Size n, Generator gen);
263
264template <class ForwardIterator, class T>
Marshall Clowe8ea8292018-01-22 21:43:04265 constexpr ForwardIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16266 remove(ForwardIterator first, ForwardIterator last, const T& value);
267
268template <class ForwardIterator, class Predicate>
Marshall Clowe8ea8292018-01-22 21:43:04269 constexpr ForwardIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16270 remove_if(ForwardIterator first, ForwardIterator last, Predicate pred);
271
272template <class InputIterator, class OutputIterator, class T>
Marshall Clowe8ea8292018-01-22 21:43:04273 constexpr OutputIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16274 remove_copy(InputIterator first, InputIterator last, OutputIterator result, const T& value);
275
276template <class InputIterator, class OutputIterator, class Predicate>
Marshall Clowe8ea8292018-01-22 21:43:04277 constexpr OutputIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16278 remove_copy_if(InputIterator first, InputIterator last, OutputIterator result, Predicate pred);
279
280template <class ForwardIterator>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:18281 constexpr ForwardIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16282 unique(ForwardIterator first, ForwardIterator last);
283
284template <class ForwardIterator, class BinaryPredicate>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:18285 constexpr ForwardIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16286 unique(ForwardIterator first, ForwardIterator last, BinaryPredicate pred);
287
288template <class InputIterator, class OutputIterator>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:18289 constexpr OutputIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16290 unique_copy(InputIterator first, InputIterator last, OutputIterator result);
291
292template <class InputIterator, class OutputIterator, class BinaryPredicate>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:18293 constexpr OutputIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16294 unique_copy(InputIterator first, InputIterator last, OutputIterator result, BinaryPredicate pred);
295
296template <class BidirectionalIterator>
Arthur O'Dwyerf851db32020-12-17 05:01:08297 constexpr void // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16298 reverse(BidirectionalIterator first, BidirectionalIterator last);
299
300template <class BidirectionalIterator, class OutputIterator>
Marshall Clowe8ea8292018-01-22 21:43:04301 constexpr OutputIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16302 reverse_copy(BidirectionalIterator first, BidirectionalIterator last, OutputIterator result);
303
304template <class ForwardIterator>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:18305 constexpr ForwardIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16306 rotate(ForwardIterator first, ForwardIterator middle, ForwardIterator last);
307
308template <class ForwardIterator, class OutputIterator>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:18309 constexpr OutputIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16310 rotate_copy(ForwardIterator first, ForwardIterator middle, ForwardIterator last, OutputIterator result);
311
312template <class RandomAccessIterator>
313 void
Marshall Clow0f37a412017-03-23 13:43:37314 random_shuffle(RandomAccessIterator first, RandomAccessIterator last); // deprecated in C++14, removed in C++17
Howard Hinnant3e519522010-05-11 19:42:16315
316template <class RandomAccessIterator, class RandomNumberGenerator>
317 void
Marshall Clow06965c12014-03-03 06:14:19318 random_shuffle(RandomAccessIterator first, RandomAccessIterator last,
Marshall Clow0f37a412017-03-23 13:43:37319 RandomNumberGenerator& rand); // deprecated in C++14, removed in C++17
Howard Hinnant3e519522010-05-11 19:42:16320
Eric Fiseliere7154702016-08-28 22:14:37321template<class PopulationIterator, class SampleIterator,
322 class Distance, class UniformRandomBitGenerator>
323 SampleIterator sample(PopulationIterator first, PopulationIterator last,
324 SampleIterator out, Distance n,
325 UniformRandomBitGenerator&& g); // C++17
326
Howard Hinnantf9d540b2010-05-26 17:49:34327template<class RandomAccessIterator, class UniformRandomNumberGenerator>
328 void shuffle(RandomAccessIterator first, RandomAccessIterator last,
Howard Hinnantfb340102010-11-18 01:47:02329 UniformRandomNumberGenerator&& g);
Howard Hinnantf9d540b2010-05-26 17:49:34330
Arthur O'Dwyer3fbd3ea2020-12-26 06:39:03331template<class ForwardIterator>
332 constexpr ForwardIterator
333 shift_left(ForwardIterator first, ForwardIterator last,
334 typename iterator_traits<ForwardIterator>::difference_type n); // C++20
335
336template<class ForwardIterator>
337 constexpr ForwardIterator
338 shift_right(ForwardIterator first, ForwardIterator last,
339 typename iterator_traits<ForwardIterator>::difference_type n); // C++20
340
Howard Hinnant3e519522010-05-11 19:42:16341template <class InputIterator, class Predicate>
Marshall Clow49c76432018-01-15 16:16:32342 constexpr bool // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16343 is_partitioned(InputIterator first, InputIterator last, Predicate pred);
344
345template <class ForwardIterator, class Predicate>
Arthur O'Dwyerf851db32020-12-17 05:01:08346 constexpr ForwardIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16347 partition(ForwardIterator first, ForwardIterator last, Predicate pred);
348
349template <class InputIterator, class OutputIterator1,
350 class OutputIterator2, class Predicate>
Marshall Clow1b9a4ff2018-01-22 20:44:33351 constexpr pair<OutputIterator1, OutputIterator2> // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16352 partition_copy(InputIterator first, InputIterator last,
353 OutputIterator1 out_true, OutputIterator2 out_false,
354 Predicate pred);
355
356template <class ForwardIterator, class Predicate>
357 ForwardIterator
358 stable_partition(ForwardIterator first, ForwardIterator last, Predicate pred);
359
360template<class ForwardIterator, class Predicate>
Marshall Clowd57c03d2018-01-16 02:34:41361 constexpr ForwardIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16362 partition_point(ForwardIterator first, ForwardIterator last, Predicate pred);
363
364template <class ForwardIterator>
Marshall Clow49c76432018-01-15 16:16:32365 constexpr bool // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16366 is_sorted(ForwardIterator first, ForwardIterator last);
367
368template <class ForwardIterator, class Compare>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:18369 constexpr bool // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16370 is_sorted(ForwardIterator first, ForwardIterator last, Compare comp);
371
372template<class ForwardIterator>
Marshall Clow056f15e2018-01-15 19:40:34373 constexpr ForwardIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16374 is_sorted_until(ForwardIterator first, ForwardIterator last);
375
376template <class ForwardIterator, class Compare>
Marshall Clow056f15e2018-01-15 19:40:34377 constexpr ForwardIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16378 is_sorted_until(ForwardIterator first, ForwardIterator last, Compare comp);
379
380template <class RandomAccessIterator>
Arthur O'Dwyer493f1402020-12-20 20:21:42381 constexpr void // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16382 sort(RandomAccessIterator first, RandomAccessIterator last);
383
384template <class RandomAccessIterator, class Compare>
Arthur O'Dwyer493f1402020-12-20 20:21:42385 constexpr void // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16386 sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
387
388template <class RandomAccessIterator>
389 void
390 stable_sort(RandomAccessIterator first, RandomAccessIterator last);
391
392template <class RandomAccessIterator, class Compare>
393 void
394 stable_sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
395
396template <class RandomAccessIterator>
Arthur O'Dwyer5386aa22020-12-17 05:26:18397 constexpr void // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16398 partial_sort(RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last);
399
400template <class RandomAccessIterator, class Compare>
Arthur O'Dwyer5386aa22020-12-17 05:26:18401 constexpr void // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16402 partial_sort(RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last, Compare comp);
403
404template <class InputIterator, class RandomAccessIterator>
Arthur O'Dwyer5386aa22020-12-17 05:26:18405 constexpr RandomAccessIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16406 partial_sort_copy(InputIterator first, InputIterator last,
407 RandomAccessIterator result_first, RandomAccessIterator result_last);
408
409template <class InputIterator, class RandomAccessIterator, class Compare>
Arthur O'Dwyer5386aa22020-12-17 05:26:18410 constexpr RandomAccessIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16411 partial_sort_copy(InputIterator first, InputIterator last,
412 RandomAccessIterator result_first, RandomAccessIterator result_last, Compare comp);
413
414template <class RandomAccessIterator>
Arthur O'Dwyer5d956562021-02-04 23:12:52415 constexpr void // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16416 nth_element(RandomAccessIterator first, RandomAccessIterator nth, RandomAccessIterator last);
417
418template <class RandomAccessIterator, class Compare>
Arthur O'Dwyer5d956562021-02-04 23:12:52419 constexpr void // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16420 nth_element(RandomAccessIterator first, RandomAccessIterator nth, RandomAccessIterator last, Compare comp);
421
422template <class ForwardIterator, class T>
Marshall Clowd57c03d2018-01-16 02:34:41423 constexpr ForwardIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16424 lower_bound(ForwardIterator first, ForwardIterator last, const T& value);
425
426template <class ForwardIterator, class T, class Compare>
Marshall Clowd57c03d2018-01-16 02:34:41427 constexpr ForwardIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16428 lower_bound(ForwardIterator first, ForwardIterator last, const T& value, Compare comp);
429
430template <class ForwardIterator, class T>
Marshall Clowd57c03d2018-01-16 02:34:41431 constexpr ForwardIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16432 upper_bound(ForwardIterator first, ForwardIterator last, const T& value);
433
434template <class ForwardIterator, class T, class Compare>
Marshall Clowd57c03d2018-01-16 02:34:41435 constexpr ForwardIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16436 upper_bound(ForwardIterator first, ForwardIterator last, const T& value, Compare comp);
437
438template <class ForwardIterator, class T>
Marshall Clowd57c03d2018-01-16 02:34:41439 constexpr pair<ForwardIterator, ForwardIterator> // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16440 equal_range(ForwardIterator first, ForwardIterator last, const T& value);
441
442template <class ForwardIterator, class T, class Compare>
Marshall Clowd57c03d2018-01-16 02:34:41443 constexpr pair<ForwardIterator, ForwardIterator> // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16444 equal_range(ForwardIterator first, ForwardIterator last, const T& value, Compare comp);
445
446template <class ForwardIterator, class T>
Marshall Clowd57c03d2018-01-16 02:34:41447 constexpr bool // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16448 binary_search(ForwardIterator first, ForwardIterator last, const T& value);
449
450template <class ForwardIterator, class T, class Compare>
Marshall Clow8da1a482018-01-22 23:10:40451 constexpr bool // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16452 binary_search(ForwardIterator first, ForwardIterator last, const T& value, Compare comp);
453
454template <class InputIterator1, class InputIterator2, class OutputIterator>
Arthur O'Dwyer14098cf2020-12-04 18:47:12455 constexpr OutputIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16456 merge(InputIterator1 first1, InputIterator1 last1,
457 InputIterator2 first2, InputIterator2 last2, OutputIterator result);
458
459template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
Arthur O'Dwyer14098cf2020-12-04 18:47:12460 constexpr OutputIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16461 merge(InputIterator1 first1, InputIterator1 last1,
462 InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
463
464template <class BidirectionalIterator>
465 void
466 inplace_merge(BidirectionalIterator first, BidirectionalIterator middle, BidirectionalIterator last);
467
468template <class BidirectionalIterator, class Compare>
469 void
470 inplace_merge(BidirectionalIterator first, BidirectionalIterator middle, BidirectionalIterator last, Compare comp);
471
472template <class InputIterator1, class InputIterator2>
Marshall Clow8da1a482018-01-22 23:10:40473 constexpr bool // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16474 includes(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2);
475
476template <class InputIterator1, class InputIterator2, class Compare>
Marshall Clow8da1a482018-01-22 23:10:40477 constexpr bool // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16478 includes(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, Compare comp);
479
480template <class InputIterator1, class InputIterator2, class OutputIterator>
Arthur O'Dwyer14098cf2020-12-04 18:47:12481 constexpr OutputIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16482 set_union(InputIterator1 first1, InputIterator1 last1,
483 InputIterator2 first2, InputIterator2 last2, OutputIterator result);
484
485template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
Arthur O'Dwyer14098cf2020-12-04 18:47:12486 constexpr OutputIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16487 set_union(InputIterator1 first1, InputIterator1 last1,
488 InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
489
490template <class InputIterator1, class InputIterator2, class OutputIterator>
Marshall Clow8da1a482018-01-22 23:10:40491 constexpr OutputIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16492 set_intersection(InputIterator1 first1, InputIterator1 last1,
493 InputIterator2 first2, InputIterator2 last2, OutputIterator result);
494
495template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
Marshall Clow8da1a482018-01-22 23:10:40496 constexpr OutputIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16497 set_intersection(InputIterator1 first1, InputIterator1 last1,
498 InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
499
500template <class InputIterator1, class InputIterator2, class OutputIterator>
Arthur O'Dwyer14098cf2020-12-04 18:47:12501 constexpr OutputIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16502 set_difference(InputIterator1 first1, InputIterator1 last1,
503 InputIterator2 first2, InputIterator2 last2, OutputIterator result);
504
505template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
Arthur O'Dwyer14098cf2020-12-04 18:47:12506 constexpr OutputIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16507 set_difference(InputIterator1 first1, InputIterator1 last1,
508 InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
509
510template <class InputIterator1, class InputIterator2, class OutputIterator>
Arthur O'Dwyer14098cf2020-12-04 18:47:12511 constexpr OutputIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16512 set_symmetric_difference(InputIterator1 first1, InputIterator1 last1,
513 InputIterator2 first2, InputIterator2 last2, OutputIterator result);
514
515template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
Arthur O'Dwyer14098cf2020-12-04 18:47:12516 constexpr OutputIterator // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16517 set_symmetric_difference(InputIterator1 first1, InputIterator1 last1,
518 InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
519
520template <class RandomAccessIterator>
Arthur O'Dwyer5386aa22020-12-17 05:26:18521 constexpr void // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16522 push_heap(RandomAccessIterator first, RandomAccessIterator last);
523
524template <class RandomAccessIterator, class Compare>
Arthur O'Dwyer5386aa22020-12-17 05:26:18525 constexpr void // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16526 push_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
527
528template <class RandomAccessIterator>
Arthur O'Dwyer5386aa22020-12-17 05:26:18529 constexpr void // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16530 pop_heap(RandomAccessIterator first, RandomAccessIterator last);
531
532template <class RandomAccessIterator, class Compare>
Arthur O'Dwyer5386aa22020-12-17 05:26:18533 constexpr void // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16534 pop_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
535
536template <class RandomAccessIterator>
Arthur O'Dwyer5386aa22020-12-17 05:26:18537 constexpr void // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16538 make_heap(RandomAccessIterator first, RandomAccessIterator last);
539
540template <class RandomAccessIterator, class Compare>
Arthur O'Dwyer5386aa22020-12-17 05:26:18541 constexpr void // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16542 make_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
543
544template <class RandomAccessIterator>
Arthur O'Dwyer5386aa22020-12-17 05:26:18545 constexpr void // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16546 sort_heap(RandomAccessIterator first, RandomAccessIterator last);
547
548template <class RandomAccessIterator, class Compare>
Arthur O'Dwyer5386aa22020-12-17 05:26:18549 constexpr void // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16550 sort_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
551
Howard Hinnantb3371f62010-08-22 00:02:43552template <class RandomAccessIterator>
Marshall Clow49c76432018-01-15 16:16:32553 constexpr bool // constexpr in C++20
Howard Hinnantb3371f62010-08-22 00:02:43554 is_heap(RandomAccessIterator first, RandomAccessiterator last);
Howard Hinnant3e519522010-05-11 19:42:16555
Howard Hinnantb3371f62010-08-22 00:02:43556template <class RandomAccessIterator, class Compare>
Marshall Clow49c76432018-01-15 16:16:32557 constexpr bool // constexpr in C++20
Howard Hinnantb3371f62010-08-22 00:02:43558 is_heap(RandomAccessIterator first, RandomAccessiterator last, Compare comp);
Howard Hinnant3e519522010-05-11 19:42:16559
Howard Hinnantb3371f62010-08-22 00:02:43560template <class RandomAccessIterator>
Marshall Clow49c76432018-01-15 16:16:32561 constexpr RandomAccessIterator // constexpr in C++20
Howard Hinnantb3371f62010-08-22 00:02:43562 is_heap_until(RandomAccessIterator first, RandomAccessiterator last);
Howard Hinnant3e519522010-05-11 19:42:16563
Howard Hinnantb3371f62010-08-22 00:02:43564template <class RandomAccessIterator, class Compare>
Marshall Clow49c76432018-01-15 16:16:32565 constexpr RandomAccessIterator // constexpr in C++20
Howard Hinnantb3371f62010-08-22 00:02:43566 is_heap_until(RandomAccessIterator first, RandomAccessiterator last, Compare comp);
Howard Hinnant3e519522010-05-11 19:42:16567
Howard Hinnant4eb27b72010-08-21 20:10:01568template <class ForwardIterator>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:18569 constexpr ForwardIterator // constexpr in C++14
570 min_element(ForwardIterator first, ForwardIterator last);
Howard Hinnant4eb27b72010-08-21 20:10:01571
572template <class ForwardIterator, class Compare>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:18573 constexpr ForwardIterator // constexpr in C++14
574 min_element(ForwardIterator first, ForwardIterator last, Compare comp);
Howard Hinnant4eb27b72010-08-21 20:10:01575
Howard Hinnant3e519522010-05-11 19:42:16576template <class T>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:18577 constexpr const T& // constexpr in C++14
578 min(const T& a, const T& b);
Howard Hinnant3e519522010-05-11 19:42:16579
580template <class T, class Compare>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:18581 constexpr const T& // constexpr in C++14
582 min(const T& a, const T& b, Compare comp);
Howard Hinnant3e519522010-05-11 19:42:16583
Howard Hinnant4eb27b72010-08-21 20:10:01584template<class T>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:18585 constexpr T // constexpr in C++14
586 min(initializer_list<T> t);
Howard Hinnant4eb27b72010-08-21 20:10:01587
588template<class T, class Compare>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:18589 constexpr T // constexpr in C++14
590 min(initializer_list<T> t, Compare comp);
Howard Hinnant4eb27b72010-08-21 20:10:01591
Marshall Clow146c14a2016-03-07 22:43:49592template<class T>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:18593 constexpr const T& clamp(const T& v, const T& lo, const T& hi); // C++17
Marshall Clow146c14a2016-03-07 22:43:49594
595template<class T, class Compare>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:18596 constexpr const T& clamp(const T& v, const T& lo, const T& hi, Compare comp); // C++17
Marshall Clow146c14a2016-03-07 22:43:49597
Howard Hinnant4eb27b72010-08-21 20:10:01598template <class ForwardIterator>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:18599 constexpr ForwardIterator // constexpr in C++14
600 max_element(ForwardIterator first, ForwardIterator last);
Howard Hinnant4eb27b72010-08-21 20:10:01601
602template <class ForwardIterator, class Compare>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:18603 constexpr ForwardIterator // constexpr in C++14
604 max_element(ForwardIterator first, ForwardIterator last, Compare comp);
Howard Hinnant4eb27b72010-08-21 20:10:01605
Howard Hinnant3e519522010-05-11 19:42:16606template <class T>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:18607 constexpr const T& // constexpr in C++14
608 max(const T& a, const T& b);
Howard Hinnant3e519522010-05-11 19:42:16609
610template <class T, class Compare>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:18611 constexpr const T& // constexpr in C++14
612 max(const T& a, const T& b, Compare comp);
Howard Hinnant3e519522010-05-11 19:42:16613
Howard Hinnant4eb27b72010-08-21 20:10:01614template<class T>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:18615 constexpr T // constexpr in C++14
616 max(initializer_list<T> t);
Howard Hinnant3e519522010-05-11 19:42:16617
Howard Hinnant4eb27b72010-08-21 20:10:01618template<class T, class Compare>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:18619 constexpr T // constexpr in C++14
620 max(initializer_list<T> t, Compare comp);
Howard Hinnant3e519522010-05-11 19:42:16621
Howard Hinnant4eb27b72010-08-21 20:10:01622template<class ForwardIterator>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:18623 constexpr pair<ForwardIterator, ForwardIterator> // constexpr in C++14
624 minmax_element(ForwardIterator first, ForwardIterator last);
Howard Hinnant3e519522010-05-11 19:42:16625
Howard Hinnant4eb27b72010-08-21 20:10:01626template<class ForwardIterator, class Compare>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:18627 constexpr pair<ForwardIterator, ForwardIterator> // constexpr in C++14
628 minmax_element(ForwardIterator first, ForwardIterator last, Compare comp);
Howard Hinnant4eb27b72010-08-21 20:10:01629
630template<class T>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:18631 constexpr pair<const T&, const T&> // constexpr in C++14
632 minmax(const T& a, const T& b);
Howard Hinnant4eb27b72010-08-21 20:10:01633
634template<class T, class Compare>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:18635 constexpr pair<const T&, const T&> // constexpr in C++14
636 minmax(const T& a, const T& b, Compare comp);
Howard Hinnant4eb27b72010-08-21 20:10:01637
638template<class T>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:18639 constexpr pair<T, T> // constexpr in C++14
640 minmax(initializer_list<T> t);
Howard Hinnant4eb27b72010-08-21 20:10:01641
642template<class T, class Compare>
Arthur O'Dwyerb8bc4e12020-12-03 01:02:18643 constexpr pair<T, T> // constexpr in C++14
644 minmax(initializer_list<T> t, Compare comp);
Howard Hinnant3e519522010-05-11 19:42:16645
646template <class InputIterator1, class InputIterator2>
Marshall Clow1b9a4ff2018-01-22 20:44:33647 constexpr bool // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16648 lexicographical_compare(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2);
649
650template <class InputIterator1, class InputIterator2, class Compare>
Marshall Clow1b9a4ff2018-01-22 20:44:33651 constexpr bool // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16652 lexicographical_compare(InputIterator1 first1, InputIterator1 last1,
653 InputIterator2 first2, InputIterator2 last2, Compare comp);
654
655template <class BidirectionalIterator>
Arthur O'Dwyerf851db32020-12-17 05:01:08656 constexpr bool // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16657 next_permutation(BidirectionalIterator first, BidirectionalIterator last);
658
659template <class BidirectionalIterator, class Compare>
Arthur O'Dwyerf851db32020-12-17 05:01:08660 constexpr bool // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16661 next_permutation(BidirectionalIterator first, BidirectionalIterator last, Compare comp);
662
663template <class BidirectionalIterator>
Arthur O'Dwyerf851db32020-12-17 05:01:08664 constexpr bool // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16665 prev_permutation(BidirectionalIterator first, BidirectionalIterator last);
666
667template <class BidirectionalIterator, class Compare>
Arthur O'Dwyerf851db32020-12-17 05:01:08668 constexpr bool // constexpr in C++20
Howard Hinnant3e519522010-05-11 19:42:16669 prev_permutation(BidirectionalIterator first, BidirectionalIterator last, Compare comp);
Howard Hinnant3e519522010-05-11 19:42:16670} // std
671
672*/
673
Arthur O'Dwyerea2206d2022-02-04 18:09:30674#include <__bits>
Howard Hinnant3e519522010-05-11 19:42:16675#include <__config>
Louis Dionne134723e2021-06-17 15:30:11676#include <__debug>
Howard Hinnanta1d07d52012-07-26 17:09:09677#include <cstddef>
Arthur O'Dwyerbfbd73f2021-05-19 15:57:04678#include <cstring>
679#include <functional>
680#include <initializer_list>
Arthur O'Dwyerbfbd73f2021-05-19 15:57:04681#include <iterator>
682#include <memory>
683#include <type_traits>
Arthur O'Dwyerea2206d2022-02-04 18:09:30684#include <utility>
Marshall Clowf56972e2018-09-12 19:41:40685#include <version>
Howard Hinnant5d1a7012013-08-14 18:00:20686
Louis Dionne134723e2021-06-17 15:30:11687#include <__algorithm/adjacent_find.h>
688#include <__algorithm/all_of.h>
689#include <__algorithm/any_of.h>
690#include <__algorithm/binary_search.h>
691#include <__algorithm/clamp.h>
692#include <__algorithm/comp.h>
693#include <__algorithm/comp_ref_type.h>
694#include <__algorithm/copy.h>
695#include <__algorithm/copy_backward.h>
696#include <__algorithm/copy_if.h>
697#include <__algorithm/copy_n.h>
698#include <__algorithm/count.h>
699#include <__algorithm/count_if.h>
700#include <__algorithm/equal.h>
701#include <__algorithm/equal_range.h>
Louis Dionne134723e2021-06-17 15:30:11702#include <__algorithm/fill.h>
Arthur O'Dwyer4d81a462022-01-07 14:45:05703#include <__algorithm/fill_n.h>
Louis Dionne134723e2021-06-17 15:30:11704#include <__algorithm/find.h>
705#include <__algorithm/find_end.h>
706#include <__algorithm/find_first_of.h>
707#include <__algorithm/find_if.h>
708#include <__algorithm/find_if_not.h>
709#include <__algorithm/for_each.h>
710#include <__algorithm/for_each_n.h>
Louis Dionne134723e2021-06-17 15:30:11711#include <__algorithm/generate.h>
Arthur O'Dwyer4d81a462022-01-07 14:45:05712#include <__algorithm/generate_n.h>
Louis Dionne134723e2021-06-17 15:30:11713#include <__algorithm/half_positive.h>
Nikolas Klauser1e77b392022-02-11 16:01:58714#include <__algorithm/in_fun_result.h>
Nikolas Klauserf3514af2022-01-25 10:21:47715#include <__algorithm/in_in_out_result.h>
Nikolas Klauserd3729bb2022-01-14 01:55:51716#include <__algorithm/in_in_result.h>
Nikolas Klauser610979b2022-02-03 01:17:03717#include <__algorithm/in_out_out_result.h>
Konstantin Varlamov8d23b742022-01-11 06:49:37718#include <__algorithm/in_out_result.h>
Louis Dionne134723e2021-06-17 15:30:11719#include <__algorithm/includes.h>
720#include <__algorithm/inplace_merge.h>
721#include <__algorithm/is_heap.h>
722#include <__algorithm/is_heap_until.h>
723#include <__algorithm/is_partitioned.h>
724#include <__algorithm/is_permutation.h>
725#include <__algorithm/is_sorted.h>
726#include <__algorithm/is_sorted_until.h>
Christopher Di Bella6adbc832021-06-05 02:47:47727#include <__algorithm/iter_swap.h>
Louis Dionne134723e2021-06-17 15:30:11728#include <__algorithm/lexicographical_compare.h>
729#include <__algorithm/lower_bound.h>
730#include <__algorithm/make_heap.h>
731#include <__algorithm/max.h>
732#include <__algorithm/max_element.h>
733#include <__algorithm/merge.h>
734#include <__algorithm/min.h>
735#include <__algorithm/min_element.h>
736#include <__algorithm/minmax.h>
737#include <__algorithm/minmax_element.h>
738#include <__algorithm/mismatch.h>
739#include <__algorithm/move.h>
740#include <__algorithm/move_backward.h>
741#include <__algorithm/next_permutation.h>
742#include <__algorithm/none_of.h>
743#include <__algorithm/nth_element.h>
744#include <__algorithm/partial_sort.h>
745#include <__algorithm/partial_sort_copy.h>
746#include <__algorithm/partition.h>
747#include <__algorithm/partition_copy.h>
748#include <__algorithm/partition_point.h>
749#include <__algorithm/pop_heap.h>
750#include <__algorithm/prev_permutation.h>
751#include <__algorithm/push_heap.h>
Nikolas Klauser9d905312022-02-10 12:33:03752#include <__algorithm/ranges_swap_ranges.h>
Louis Dionne134723e2021-06-17 15:30:11753#include <__algorithm/remove.h>
754#include <__algorithm/remove_copy.h>
755#include <__algorithm/remove_copy_if.h>
756#include <__algorithm/remove_if.h>
757#include <__algorithm/replace.h>
758#include <__algorithm/replace_copy.h>
759#include <__algorithm/replace_copy_if.h>
760#include <__algorithm/replace_if.h>
761#include <__algorithm/reverse.h>
762#include <__algorithm/reverse_copy.h>
763#include <__algorithm/rotate.h>
764#include <__algorithm/rotate_copy.h>
765#include <__algorithm/sample.h>
766#include <__algorithm/search.h>
767#include <__algorithm/search_n.h>
768#include <__algorithm/set_difference.h>
769#include <__algorithm/set_intersection.h>
770#include <__algorithm/set_symmetric_difference.h>
771#include <__algorithm/set_union.h>
772#include <__algorithm/shift_left.h>
773#include <__algorithm/shift_right.h>
774#include <__algorithm/shuffle.h>
775#include <__algorithm/sift_down.h>
776#include <__algorithm/sort.h>
777#include <__algorithm/sort_heap.h>
778#include <__algorithm/stable_partition.h>
779#include <__algorithm/stable_sort.h>
Christopher Di Bella6adbc832021-06-05 02:47:47780#include <__algorithm/swap_ranges.h>
Louis Dionne134723e2021-06-17 15:30:11781#include <__algorithm/transform.h>
Louis Dionne134723e2021-06-17 15:30:11782#include <__algorithm/unique.h>
Arthur O'Dwyer4d81a462022-01-07 14:45:05783#include <__algorithm/unique_copy.h>
Louis Dionne134723e2021-06-17 15:30:11784#include <__algorithm/unwrap_iter.h>
785#include <__algorithm/upper_bound.h>
Eric Fiselierc1bd9192014-08-10 23:53:08786
Howard Hinnant073458b2011-10-17 20:05:10787#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Arthur O'Dwyerfa6b9e42022-02-02 01:16:40788# pragma GCC system_header
Howard Hinnant073458b2011-10-17 20:05:10789#endif
Howard Hinnant3e519522010-05-11 19:42:16790
Louis Dionne0a06eb92019-08-05 18:29:14791#if defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS) && _LIBCPP_STD_VER >= 17
Louis Dionne95689242019-08-06 21:11:24792# include <__pstl_algorithm>
Louis Dionne0a06eb92019-08-05 18:29:14793#endif
794
Louis Dionne4cd6ca12021-04-20 16:03:32795#endif // _LIBCPP_ALGORITHM