blob: 8383b40f20ef973c7ed059a4542ea6c68dbc2354 [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
Louis Dionne9bd93882021-11-17 16:25:01 -05002//===----------------------------------------------------------------------===//
Howard Hinnantc51e1022010-05-11 19:42:16 +00003//
Chandler Carruthd2012102019-01-19 10:56:40 +00004// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Howard Hinnantc51e1022010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_ALGORITHM
11#define _LIBCPP_ALGORITHM
12
13/*
14 algorithm synopsis
15
16#include <initializer_list>
17
18namespace std
19{
20
Nikolas Klauserf74be4e2022-01-14 02:55:51 +010021namespace ranges {
Nikolas Klauser671b4752022-02-11 17:01:58 +010022 template <class I, class F>
Nikolas Klauser2e263162022-02-21 22:48:36 +010023 struct in_fun_result; // since C++20
Nikolas Klauser671b4752022-02-11 17:01:58 +010024
Nikolas Klauserf74be4e2022-01-14 02:55:51 +010025 template <class I1, class I2>
Nikolas Klauser2e263162022-02-21 22:48:36 +010026 struct in_in_result; // since C++20
Nikolas Klauser05e2cd82022-01-25 11:21:47 +010027
28 template <class I1, class I2, class O>
Nikolas Klauser2e263162022-02-21 22:48:36 +010029 struct in_in_out_result; // since C++20
Nikolas Klauser61ce8162022-02-03 02:17:03 +010030
31 template <class I, class O1, class O2>
32 struct in_out_out_result; // since C++20
Nikolas Klauser671b4752022-02-11 17:01:58 +010033
Nikolas Klauser2e263162022-02-21 22:48:36 +010034 template <class I1, class I2>
35 struct min_max_result; // since C++20
36
Nikolas Klauserdd5ad212022-02-21 23:07:02 +010037 template <class I>
38 struct in_found_result; // since C++20
39
Nikolas Klauser0a62a172022-02-11 13:11:57 +010040 template<forward_iterator I, sentinel_for<I> S, class Proj = identity,
41 indirect_strict_weak_order<projected<I, Proj>> Comp = ranges::less> // since C++20
42 constexpr I min_element(I first, S last, Comp comp = {}, Proj proj = {});
43
44 template<forward_range R, class Proj = identity,
45 indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less> // since C++20
46 constexpr borrowed_iterator_t<R> min_element(R&& r, Comp comp = {}, Proj proj = {});
Nikolas Klauser12fc9bf2022-03-08 23:12:35 +010047
48 template <input_iterator I1, sentinel_for<_I1> S1, input_iterator I2, sentinel_for<_I2> S2,
49 class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
50 requires indirectly_comparable<I1, I2, Pred, Proj1, Proj2>
51 constexpr mismatch_result<_I1, _I2>
52 mismatch()(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}) // since C++20
53
54 template <input_range R1, input_range R2,
55 class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
56 requires indirectly_comparable<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
57 constexpr mismatch_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>>
58 mismatch(R1&& r1, R2&& r2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}) // since C++20
Nikolas Klauser37d076e2022-03-12 01:45:35 +010059
60 template<input_iterator I, sentinel_for<I> S, class T, class Proj = identity>
61 requires indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T*>
62 constexpr I find(I first, S last, const T& value, Proj proj = {}); // since C++20
63
64 template<input_range R, class T, class Proj = identity>
65 requires indirect_binary_predicate<ranges::equal_to, projected<iterator_t<R>, Proj>, const T*>
66 constexpr borrowed_iterator_t<R>
67 find(R&& r, const T& value, Proj proj = {}); // since C++20
68
69 template<input_iterator I, sentinel_for<I> S, class Proj = identity,
70 indirect_unary_predicate<projected<I, Proj>> Pred>
71 constexpr I find_if(I first, S last, Pred pred, Proj proj = {}); // since C++20
72
73 template<input_range R, class Proj = identity,
74 indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
75 constexpr borrowed_iterator_t<R>
76 find_if(R&& r, Pred pred, Proj proj = {}); // since C++20
77
78 template<input_iterator I, sentinel_for<I> S, class Proj = identity,
79 indirect_unary_predicate<projected<I, Proj>> Pred>
80 constexpr I find_if_not(I first, S last, Pred pred, Proj proj = {}); // since C++20
81
82 template<input_range R, class Proj = identity,
83 indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
84 constexpr borrowed_iterator_t<R>
85 find_if_not(R&& r, Pred pred, Proj proj = {}); // since C++20
Nikolas Klauserf74be4e2022-01-14 02:55:51 +010086}
87
Howard Hinnantc51e1022010-05-11 19:42:16 +000088template <class InputIterator, class Predicate>
Marshall Clowd607fdb2018-01-15 17:20:36 +000089 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000090 all_of(InputIterator first, InputIterator last, Predicate pred);
91
92template <class InputIterator, class Predicate>
Marshall Clowd607fdb2018-01-15 17:20:36 +000093 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000094 any_of(InputIterator first, InputIterator last, Predicate pred);
95
96template <class InputIterator, class Predicate>
Marshall Clowd607fdb2018-01-15 17:20:36 +000097 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000098 none_of(InputIterator first, InputIterator last, Predicate pred);
99
100template <class InputIterator, class Function>
Marshall Clow5492c8a2018-01-22 20:44:33 +0000101 constexpr Function // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000102 for_each(InputIterator first, InputIterator last, Function f);
103
Marshall Clowde0169c2017-05-25 02:29:54 +0000104template<class InputIterator, class Size, class Function>
Marshall Clow5492c8a2018-01-22 20:44:33 +0000105 constexpr InputIterator // constexpr in C++20
106 for_each_n(InputIterator first, Size n, Function f); // C++17
Marshall Clowde0169c2017-05-25 02:29:54 +0000107
Howard Hinnantc51e1022010-05-11 19:42:16 +0000108template <class InputIterator, class T>
Marshall Clowee0161e2018-01-15 19:26:05 +0000109 constexpr InputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000110 find(InputIterator first, InputIterator last, const T& value);
111
112template <class InputIterator, class Predicate>
Marshall Clowee0161e2018-01-15 19:26:05 +0000113 constexpr InputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000114 find_if(InputIterator first, InputIterator last, Predicate pred);
115
116template<class InputIterator, class Predicate>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500117 constexpr InputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000118 find_if_not(InputIterator first, InputIterator last, Predicate pred);
119
120template <class ForwardIterator1, class ForwardIterator2>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500121 constexpr ForwardIterator1 // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000122 find_end(ForwardIterator1 first1, ForwardIterator1 last1,
123 ForwardIterator2 first2, ForwardIterator2 last2);
124
125template <class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500126 constexpr ForwardIterator1 // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000127 find_end(ForwardIterator1 first1, ForwardIterator1 last1,
128 ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred);
129
130template <class ForwardIterator1, class ForwardIterator2>
Marshall Clowee0161e2018-01-15 19:26:05 +0000131 constexpr ForwardIterator1 // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000132 find_first_of(ForwardIterator1 first1, ForwardIterator1 last1,
133 ForwardIterator2 first2, ForwardIterator2 last2);
134
135template <class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
Marshall Clowee0161e2018-01-15 19:26:05 +0000136 constexpr ForwardIterator1 // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000137 find_first_of(ForwardIterator1 first1, ForwardIterator1 last1,
138 ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred);
139
140template <class ForwardIterator>
Marshall Clowee0161e2018-01-15 19:26:05 +0000141 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000142 adjacent_find(ForwardIterator first, ForwardIterator last);
143
144template <class ForwardIterator, class BinaryPredicate>
Marshall Clowee0161e2018-01-15 19:26:05 +0000145 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000146 adjacent_find(ForwardIterator first, ForwardIterator last, BinaryPredicate pred);
147
148template <class InputIterator, class T>
Marshall Clow3c0558f2018-01-15 19:40:34 +0000149 constexpr typename iterator_traits<InputIterator>::difference_type // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000150 count(InputIterator first, InputIterator last, const T& value);
151
152template <class InputIterator, class Predicate>
Marshall Clow3c0558f2018-01-15 19:40:34 +0000153 constexpr typename iterator_traits<InputIterator>::difference_type // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000154 count_if(InputIterator first, InputIterator last, Predicate pred);
155
156template <class InputIterator1, class InputIterator2>
Marshall Clow30bf3022018-01-16 02:04:10 +0000157 constexpr pair<InputIterator1, InputIterator2> // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000158 mismatch(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2);
159
Marshall Clow96b42b22013-05-09 21:14:23 +0000160template <class InputIterator1, class InputIterator2>
Marshall Clow30bf3022018-01-16 02:04:10 +0000161 constexpr pair<InputIterator1, InputIterator2> // constexpr in C++20
Aditya Kumar3a0179a2016-08-25 11:52:38 +0000162 mismatch(InputIterator1 first1, InputIterator1 last1,
Marshall Clow96b42b22013-05-09 21:14:23 +0000163 InputIterator2 first2, InputIterator2 last2); // **C++14**
164
Howard Hinnantc51e1022010-05-11 19:42:16 +0000165template <class InputIterator1, class InputIterator2, class BinaryPredicate>
Marshall Clow30bf3022018-01-16 02:04:10 +0000166 constexpr pair<InputIterator1, InputIterator2> // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000167 mismatch(InputIterator1 first1, InputIterator1 last1,
168 InputIterator2 first2, BinaryPredicate pred);
169
Marshall Clow96b42b22013-05-09 21:14:23 +0000170template <class InputIterator1, class InputIterator2, class BinaryPredicate>
Marshall Clow30bf3022018-01-16 02:04:10 +0000171 constexpr pair<InputIterator1, InputIterator2> // constexpr in C++20
Marshall Clow96b42b22013-05-09 21:14:23 +0000172 mismatch(InputIterator1 first1, InputIterator1 last1,
173 InputIterator2 first2, InputIterator2 last2,
174 BinaryPredicate pred); // **C++14**
175
Howard Hinnantc51e1022010-05-11 19:42:16 +0000176template <class InputIterator1, class InputIterator2>
Marshall Clow30bf3022018-01-16 02:04:10 +0000177 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000178 equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2);
179
Marshall Clow96b42b22013-05-09 21:14:23 +0000180template <class InputIterator1, class InputIterator2>
Marshall Clow30bf3022018-01-16 02:04:10 +0000181 constexpr bool // constexpr in C++20
Aditya Kumar3a0179a2016-08-25 11:52:38 +0000182 equal(InputIterator1 first1, InputIterator1 last1,
Marshall Clow96b42b22013-05-09 21:14:23 +0000183 InputIterator2 first2, InputIterator2 last2); // **C++14**
184
Howard Hinnantc51e1022010-05-11 19:42:16 +0000185template <class InputIterator1, class InputIterator2, class BinaryPredicate>
Marshall Clow30bf3022018-01-16 02:04:10 +0000186 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000187 equal(InputIterator1 first1, InputIterator1 last1,
188 InputIterator2 first2, BinaryPredicate pred);
189
Marshall Clow96b42b22013-05-09 21:14:23 +0000190template <class InputIterator1, class InputIterator2, class BinaryPredicate>
Marshall Clow30bf3022018-01-16 02:04:10 +0000191 constexpr bool // constexpr in C++20
Marshall Clow96b42b22013-05-09 21:14:23 +0000192 equal(InputIterator1 first1, InputIterator1 last1,
193 InputIterator2 first2, InputIterator2 last2,
194 BinaryPredicate pred); // **C++14**
195
Howard Hinnantc51e1022010-05-11 19:42:16 +0000196template<class ForwardIterator1, class ForwardIterator2>
Marshall Clow96d050a2018-01-15 16:16:32 +0000197 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000198 is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
199 ForwardIterator2 first2);
200
Marshall Clow96b42b22013-05-09 21:14:23 +0000201template<class ForwardIterator1, class ForwardIterator2>
Marshall Clow96d050a2018-01-15 16:16:32 +0000202 constexpr bool // constexpr in C++20
Marshall Clow96b42b22013-05-09 21:14:23 +0000203 is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
204 ForwardIterator2 first2, ForwardIterator2 last2); // **C++14**
205
Howard Hinnantc51e1022010-05-11 19:42:16 +0000206template<class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
Marshall Clow96d050a2018-01-15 16:16:32 +0000207 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000208 is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
209 ForwardIterator2 first2, BinaryPredicate pred);
210
Marshall Clow96b42b22013-05-09 21:14:23 +0000211template<class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
Marshall Clow96d050a2018-01-15 16:16:32 +0000212 constexpr bool // constexpr in C++20
Marshall Clow96b42b22013-05-09 21:14:23 +0000213 is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
214 ForwardIterator2 first2, ForwardIterator2 last2,
215 BinaryPredicate pred); // **C++14**
216
Howard Hinnantc51e1022010-05-11 19:42:16 +0000217template <class ForwardIterator1, class ForwardIterator2>
Marshall Clow323fc5b2018-01-16 15:48:27 +0000218 constexpr ForwardIterator1 // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000219 search(ForwardIterator1 first1, ForwardIterator1 last1,
220 ForwardIterator2 first2, ForwardIterator2 last2);
221
222template <class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
Marshall Clow323fc5b2018-01-16 15:48:27 +0000223 constexpr ForwardIterator1 // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000224 search(ForwardIterator1 first1, ForwardIterator1 last1,
225 ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred);
226
227template <class ForwardIterator, class Size, class T>
Marshall Clow323fc5b2018-01-16 15:48:27 +0000228 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000229 search_n(ForwardIterator first, ForwardIterator last, Size count, const T& value);
230
231template <class ForwardIterator, class Size, class T, class BinaryPredicate>
Marshall Clow323fc5b2018-01-16 15:48:27 +0000232 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000233 search_n(ForwardIterator first, ForwardIterator last,
234 Size count, const T& value, BinaryPredicate pred);
235
236template <class InputIterator, class OutputIterator>
Louis Dionne65b433b2019-11-06 12:02:41 +0000237 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000238 copy(InputIterator first, InputIterator last, OutputIterator result);
239
240template<class InputIterator, class OutputIterator, class Predicate>
Louis Dionne65b433b2019-11-06 12:02:41 +0000241 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000242 copy_if(InputIterator first, InputIterator last,
243 OutputIterator result, Predicate pred);
244
245template<class InputIterator, class Size, class OutputIterator>
Louis Dionne65b433b2019-11-06 12:02:41 +0000246 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000247 copy_n(InputIterator first, Size n, OutputIterator result);
248
249template <class BidirectionalIterator1, class BidirectionalIterator2>
Louis Dionne65b433b2019-11-06 12:02:41 +0000250 constexpr BidirectionalIterator2 // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000251 copy_backward(BidirectionalIterator1 first, BidirectionalIterator1 last,
252 BidirectionalIterator2 result);
253
254template <class ForwardIterator1, class ForwardIterator2>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500255 constexpr ForwardIterator2 // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000256 swap_ranges(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2);
257
Nikolas Klauser4ceab5f2022-02-10 13:33:03 +0100258template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2>
259 requires indirectly_swappable<I1, I2>
260 constexpr ranges::swap_ranges_result<I1, I2>
261 ranges::swap_ranges(I1 first1, S1 last1, I2 first2, S2 last2);
262
263template<input_range R1, input_range R2>
264 requires indirectly_swappable<iterator_t<R1>, iterator_t<R2>>
265 constexpr ranges::swap_ranges_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>>
266 ranges::swap_ranges(R1&& r1, R2&& r2);
267
Howard Hinnantc51e1022010-05-11 19:42:16 +0000268template <class ForwardIterator1, class ForwardIterator2>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500269 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000270 iter_swap(ForwardIterator1 a, ForwardIterator2 b);
271
272template <class InputIterator, class OutputIterator, class UnaryOperation>
Marshall Clow31427c62018-01-19 17:45:39 +0000273 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000274 transform(InputIterator first, InputIterator last, OutputIterator result, UnaryOperation op);
275
276template <class InputIterator1, class InputIterator2, class OutputIterator, class BinaryOperation>
Marshall Clow31427c62018-01-19 17:45:39 +0000277 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000278 transform(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2,
279 OutputIterator result, BinaryOperation binary_op);
280
281template <class ForwardIterator, class T>
Marshall Clow01bbbd22018-01-19 18:07:29 +0000282 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000283 replace(ForwardIterator first, ForwardIterator last, const T& old_value, const T& new_value);
284
285template <class ForwardIterator, class Predicate, class T>
Marshall Clow01bbbd22018-01-19 18:07:29 +0000286 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000287 replace_if(ForwardIterator first, ForwardIterator last, Predicate pred, const T& new_value);
288
289template <class InputIterator, class OutputIterator, class T>
Marshall Clow01bbbd22018-01-19 18:07:29 +0000290 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000291 replace_copy(InputIterator first, InputIterator last, OutputIterator result,
292 const T& old_value, const T& new_value);
293
294template <class InputIterator, class OutputIterator, class Predicate, class T>
Marshall Clow01bbbd22018-01-19 18:07:29 +0000295 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000296 replace_copy_if(InputIterator first, InputIterator last, OutputIterator result, Predicate pred, const T& new_value);
297
298template <class ForwardIterator, class T>
Marshall Clowe9cdc5c2018-01-20 20:14:32 +0000299 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000300 fill(ForwardIterator first, ForwardIterator last, const T& value);
301
302template <class OutputIterator, class Size, class T>
Marshall Clowe9cdc5c2018-01-20 20:14:32 +0000303 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000304 fill_n(OutputIterator first, Size n, const T& value);
305
306template <class ForwardIterator, class Generator>
Marshall Clowe9cdc5c2018-01-20 20:14:32 +0000307 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000308 generate(ForwardIterator first, ForwardIterator last, Generator gen);
309
310template <class OutputIterator, class Size, class Generator>
Marshall Clowe9cdc5c2018-01-20 20:14:32 +0000311 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000312 generate_n(OutputIterator first, Size n, Generator gen);
313
314template <class ForwardIterator, class T>
Marshall Clow7c0fbd82018-01-22 21:43:04 +0000315 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000316 remove(ForwardIterator first, ForwardIterator last, const T& value);
317
318template <class ForwardIterator, class Predicate>
Marshall Clow7c0fbd82018-01-22 21:43:04 +0000319 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000320 remove_if(ForwardIterator first, ForwardIterator last, Predicate pred);
321
322template <class InputIterator, class OutputIterator, class T>
Marshall Clow7c0fbd82018-01-22 21:43:04 +0000323 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000324 remove_copy(InputIterator first, InputIterator last, OutputIterator result, const T& value);
325
326template <class InputIterator, class OutputIterator, class Predicate>
Marshall Clow7c0fbd82018-01-22 21:43:04 +0000327 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000328 remove_copy_if(InputIterator first, InputIterator last, OutputIterator result, Predicate pred);
329
330template <class ForwardIterator>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500331 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000332 unique(ForwardIterator first, ForwardIterator last);
333
334template <class ForwardIterator, class BinaryPredicate>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500335 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000336 unique(ForwardIterator first, ForwardIterator last, BinaryPredicate pred);
337
338template <class InputIterator, class OutputIterator>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500339 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000340 unique_copy(InputIterator first, InputIterator last, OutputIterator result);
341
342template <class InputIterator, class OutputIterator, class BinaryPredicate>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500343 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000344 unique_copy(InputIterator first, InputIterator last, OutputIterator result, BinaryPredicate pred);
345
346template <class BidirectionalIterator>
Arthur O'Dwyere50e7472020-12-17 00:01:08 -0500347 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000348 reverse(BidirectionalIterator first, BidirectionalIterator last);
349
350template <class BidirectionalIterator, class OutputIterator>
Marshall Clow7c0fbd82018-01-22 21:43:04 +0000351 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000352 reverse_copy(BidirectionalIterator first, BidirectionalIterator last, OutputIterator result);
353
354template <class ForwardIterator>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500355 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000356 rotate(ForwardIterator first, ForwardIterator middle, ForwardIterator last);
357
358template <class ForwardIterator, class OutputIterator>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500359 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000360 rotate_copy(ForwardIterator first, ForwardIterator middle, ForwardIterator last, OutputIterator result);
361
362template <class RandomAccessIterator>
363 void
Marshall Clowfac06e52017-03-23 13:43:37 +0000364 random_shuffle(RandomAccessIterator first, RandomAccessIterator last); // deprecated in C++14, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000365
366template <class RandomAccessIterator, class RandomNumberGenerator>
367 void
Marshall Clow83f35392014-03-03 06:14:19 +0000368 random_shuffle(RandomAccessIterator first, RandomAccessIterator last,
Marshall Clowfac06e52017-03-23 13:43:37 +0000369 RandomNumberGenerator& rand); // deprecated in C++14, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000370
Eric Fiselier1208fcd2016-08-28 22:14:37 +0000371template<class PopulationIterator, class SampleIterator,
372 class Distance, class UniformRandomBitGenerator>
373 SampleIterator sample(PopulationIterator first, PopulationIterator last,
374 SampleIterator out, Distance n,
375 UniformRandomBitGenerator&& g); // C++17
376
Howard Hinnant578ac0f2010-05-26 17:49:34 +0000377template<class RandomAccessIterator, class UniformRandomNumberGenerator>
378 void shuffle(RandomAccessIterator first, RandomAccessIterator last,
Howard Hinnanta5e71782010-11-18 01:47:02 +0000379 UniformRandomNumberGenerator&& g);
Howard Hinnant578ac0f2010-05-26 17:49:34 +0000380
Arthur O'Dwyercea050d2020-12-26 01:39:03 -0500381template<class ForwardIterator>
382 constexpr ForwardIterator
383 shift_left(ForwardIterator first, ForwardIterator last,
384 typename iterator_traits<ForwardIterator>::difference_type n); // C++20
385
386template<class ForwardIterator>
387 constexpr ForwardIterator
388 shift_right(ForwardIterator first, ForwardIterator last,
389 typename iterator_traits<ForwardIterator>::difference_type n); // C++20
390
Howard Hinnantc51e1022010-05-11 19:42:16 +0000391template <class InputIterator, class Predicate>
Marshall Clow96d050a2018-01-15 16:16:32 +0000392 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000393 is_partitioned(InputIterator first, InputIterator last, Predicate pred);
394
395template <class ForwardIterator, class Predicate>
Arthur O'Dwyere50e7472020-12-17 00:01:08 -0500396 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000397 partition(ForwardIterator first, ForwardIterator last, Predicate pred);
398
399template <class InputIterator, class OutputIterator1,
400 class OutputIterator2, class Predicate>
Marshall Clow5492c8a2018-01-22 20:44:33 +0000401 constexpr pair<OutputIterator1, OutputIterator2> // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000402 partition_copy(InputIterator first, InputIterator last,
403 OutputIterator1 out_true, OutputIterator2 out_false,
404 Predicate pred);
405
406template <class ForwardIterator, class Predicate>
407 ForwardIterator
408 stable_partition(ForwardIterator first, ForwardIterator last, Predicate pred);
409
410template<class ForwardIterator, class Predicate>
Marshall Clowe00916c2018-01-16 02:34:41 +0000411 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000412 partition_point(ForwardIterator first, ForwardIterator last, Predicate pred);
413
414template <class ForwardIterator>
Marshall Clow96d050a2018-01-15 16:16:32 +0000415 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000416 is_sorted(ForwardIterator first, ForwardIterator last);
417
418template <class ForwardIterator, class Compare>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500419 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000420 is_sorted(ForwardIterator first, ForwardIterator last, Compare comp);
421
422template<class ForwardIterator>
Marshall Clow3c0558f2018-01-15 19:40:34 +0000423 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000424 is_sorted_until(ForwardIterator first, ForwardIterator last);
425
426template <class ForwardIterator, class Compare>
Marshall Clow3c0558f2018-01-15 19:40:34 +0000427 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000428 is_sorted_until(ForwardIterator first, ForwardIterator last, Compare comp);
429
430template <class RandomAccessIterator>
Arthur O'Dwyer1bb0f672020-12-20 15:21:42 -0500431 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000432 sort(RandomAccessIterator first, RandomAccessIterator last);
433
434template <class RandomAccessIterator, class Compare>
Arthur O'Dwyer1bb0f672020-12-20 15:21:42 -0500435 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000436 sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
437
438template <class RandomAccessIterator>
439 void
440 stable_sort(RandomAccessIterator first, RandomAccessIterator last);
441
442template <class RandomAccessIterator, class Compare>
443 void
444 stable_sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
445
446template <class RandomAccessIterator>
Arthur O'Dwyer2dfea5d2020-12-17 00:26:18 -0500447 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000448 partial_sort(RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last);
449
450template <class RandomAccessIterator, class Compare>
Arthur O'Dwyer2dfea5d2020-12-17 00:26:18 -0500451 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000452 partial_sort(RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last, Compare comp);
453
454template <class InputIterator, class RandomAccessIterator>
Arthur O'Dwyer2dfea5d2020-12-17 00:26:18 -0500455 constexpr RandomAccessIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000456 partial_sort_copy(InputIterator first, InputIterator last,
457 RandomAccessIterator result_first, RandomAccessIterator result_last);
458
459template <class InputIterator, class RandomAccessIterator, class Compare>
Arthur O'Dwyer2dfea5d2020-12-17 00:26:18 -0500460 constexpr RandomAccessIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000461 partial_sort_copy(InputIterator first, InputIterator last,
462 RandomAccessIterator result_first, RandomAccessIterator result_last, Compare comp);
463
464template <class RandomAccessIterator>
Arthur O'Dwyer4f5717b2021-02-04 18:12:52 -0500465 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000466 nth_element(RandomAccessIterator first, RandomAccessIterator nth, RandomAccessIterator last);
467
468template <class RandomAccessIterator, class Compare>
Arthur O'Dwyer4f5717b2021-02-04 18:12:52 -0500469 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000470 nth_element(RandomAccessIterator first, RandomAccessIterator nth, RandomAccessIterator last, Compare comp);
471
472template <class ForwardIterator, class T>
Marshall Clowe00916c2018-01-16 02:34:41 +0000473 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000474 lower_bound(ForwardIterator first, ForwardIterator last, const T& value);
475
476template <class ForwardIterator, class T, class Compare>
Marshall Clowe00916c2018-01-16 02:34:41 +0000477 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000478 lower_bound(ForwardIterator first, ForwardIterator last, const T& value, Compare comp);
479
480template <class ForwardIterator, class T>
Marshall Clowe00916c2018-01-16 02:34:41 +0000481 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000482 upper_bound(ForwardIterator first, ForwardIterator last, const T& value);
483
484template <class ForwardIterator, class T, class Compare>
Marshall Clowe00916c2018-01-16 02:34:41 +0000485 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000486 upper_bound(ForwardIterator first, ForwardIterator last, const T& value, Compare comp);
487
488template <class ForwardIterator, class T>
Marshall Clowe00916c2018-01-16 02:34:41 +0000489 constexpr pair<ForwardIterator, ForwardIterator> // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000490 equal_range(ForwardIterator first, ForwardIterator last, const T& value);
491
492template <class ForwardIterator, class T, class Compare>
Marshall Clowe00916c2018-01-16 02:34:41 +0000493 constexpr pair<ForwardIterator, ForwardIterator> // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000494 equal_range(ForwardIterator first, ForwardIterator last, const T& value, Compare comp);
495
496template <class ForwardIterator, class T>
Marshall Clowe00916c2018-01-16 02:34:41 +0000497 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000498 binary_search(ForwardIterator first, ForwardIterator last, const T& value);
499
500template <class ForwardIterator, class T, class Compare>
Marshall Clowc0b7f972018-01-22 23:10:40 +0000501 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000502 binary_search(ForwardIterator first, ForwardIterator last, const T& value, Compare comp);
503
504template <class InputIterator1, class InputIterator2, class OutputIterator>
Arthur O'Dwyer5afc5692020-12-04 13:47:12 -0500505 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000506 merge(InputIterator1 first1, InputIterator1 last1,
507 InputIterator2 first2, InputIterator2 last2, OutputIterator result);
508
509template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
Arthur O'Dwyer5afc5692020-12-04 13:47:12 -0500510 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000511 merge(InputIterator1 first1, InputIterator1 last1,
512 InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
513
514template <class BidirectionalIterator>
515 void
516 inplace_merge(BidirectionalIterator first, BidirectionalIterator middle, BidirectionalIterator last);
517
518template <class BidirectionalIterator, class Compare>
519 void
520 inplace_merge(BidirectionalIterator first, BidirectionalIterator middle, BidirectionalIterator last, Compare comp);
521
522template <class InputIterator1, class InputIterator2>
Marshall Clowc0b7f972018-01-22 23:10:40 +0000523 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000524 includes(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2);
525
526template <class InputIterator1, class InputIterator2, class Compare>
Marshall Clowc0b7f972018-01-22 23:10:40 +0000527 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000528 includes(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, Compare comp);
529
530template <class InputIterator1, class InputIterator2, class OutputIterator>
Arthur O'Dwyer5afc5692020-12-04 13:47:12 -0500531 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000532 set_union(InputIterator1 first1, InputIterator1 last1,
533 InputIterator2 first2, InputIterator2 last2, OutputIterator result);
534
535template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
Arthur O'Dwyer5afc5692020-12-04 13:47:12 -0500536 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000537 set_union(InputIterator1 first1, InputIterator1 last1,
538 InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
539
540template <class InputIterator1, class InputIterator2, class OutputIterator>
Marshall Clowc0b7f972018-01-22 23:10:40 +0000541 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000542 set_intersection(InputIterator1 first1, InputIterator1 last1,
543 InputIterator2 first2, InputIterator2 last2, OutputIterator result);
544
545template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
Marshall Clowc0b7f972018-01-22 23:10:40 +0000546 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000547 set_intersection(InputIterator1 first1, InputIterator1 last1,
548 InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
549
550template <class InputIterator1, class InputIterator2, class OutputIterator>
Arthur O'Dwyer5afc5692020-12-04 13:47:12 -0500551 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000552 set_difference(InputIterator1 first1, InputIterator1 last1,
553 InputIterator2 first2, InputIterator2 last2, OutputIterator result);
554
555template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
Arthur O'Dwyer5afc5692020-12-04 13:47:12 -0500556 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000557 set_difference(InputIterator1 first1, InputIterator1 last1,
558 InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
559
560template <class InputIterator1, class InputIterator2, class OutputIterator>
Arthur O'Dwyer5afc5692020-12-04 13:47:12 -0500561 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000562 set_symmetric_difference(InputIterator1 first1, InputIterator1 last1,
563 InputIterator2 first2, InputIterator2 last2, OutputIterator result);
564
565template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
Arthur O'Dwyer5afc5692020-12-04 13:47:12 -0500566 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000567 set_symmetric_difference(InputIterator1 first1, InputIterator1 last1,
568 InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
569
570template <class RandomAccessIterator>
Arthur O'Dwyer2dfea5d2020-12-17 00:26:18 -0500571 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000572 push_heap(RandomAccessIterator first, RandomAccessIterator last);
573
574template <class RandomAccessIterator, class Compare>
Arthur O'Dwyer2dfea5d2020-12-17 00:26:18 -0500575 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000576 push_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
577
578template <class RandomAccessIterator>
Arthur O'Dwyer2dfea5d2020-12-17 00:26:18 -0500579 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000580 pop_heap(RandomAccessIterator first, RandomAccessIterator last);
581
582template <class RandomAccessIterator, class Compare>
Arthur O'Dwyer2dfea5d2020-12-17 00:26:18 -0500583 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000584 pop_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
585
586template <class RandomAccessIterator>
Arthur O'Dwyer2dfea5d2020-12-17 00:26:18 -0500587 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000588 make_heap(RandomAccessIterator first, RandomAccessIterator last);
589
590template <class RandomAccessIterator, class Compare>
Arthur O'Dwyer2dfea5d2020-12-17 00:26:18 -0500591 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000592 make_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
593
594template <class RandomAccessIterator>
Arthur O'Dwyer2dfea5d2020-12-17 00:26:18 -0500595 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000596 sort_heap(RandomAccessIterator first, RandomAccessIterator last);
597
598template <class RandomAccessIterator, class Compare>
Arthur O'Dwyer2dfea5d2020-12-17 00:26:18 -0500599 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000600 sort_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
601
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000602template <class RandomAccessIterator>
Marshall Clow96d050a2018-01-15 16:16:32 +0000603 constexpr bool // constexpr in C++20
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000604 is_heap(RandomAccessIterator first, RandomAccessiterator last);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000605
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000606template <class RandomAccessIterator, class Compare>
Marshall Clow96d050a2018-01-15 16:16:32 +0000607 constexpr bool // constexpr in C++20
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000608 is_heap(RandomAccessIterator first, RandomAccessiterator last, Compare comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000609
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000610template <class RandomAccessIterator>
Marshall Clow96d050a2018-01-15 16:16:32 +0000611 constexpr RandomAccessIterator // constexpr in C++20
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000612 is_heap_until(RandomAccessIterator first, RandomAccessiterator last);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000613
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000614template <class RandomAccessIterator, class Compare>
Marshall Clow96d050a2018-01-15 16:16:32 +0000615 constexpr RandomAccessIterator // constexpr in C++20
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000616 is_heap_until(RandomAccessIterator first, RandomAccessiterator last, Compare comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000617
Howard Hinnantb120e7a2010-08-21 20:10:01 +0000618template <class ForwardIterator>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500619 constexpr ForwardIterator // constexpr in C++14
620 min_element(ForwardIterator first, ForwardIterator last);
Howard Hinnantb120e7a2010-08-21 20:10:01 +0000621
622template <class ForwardIterator, class Compare>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500623 constexpr ForwardIterator // constexpr in C++14
624 min_element(ForwardIterator first, ForwardIterator last, Compare comp);
Howard Hinnantb120e7a2010-08-21 20:10:01 +0000625
Howard Hinnantc51e1022010-05-11 19:42:16 +0000626template <class T>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500627 constexpr const T& // constexpr in C++14
628 min(const T& a, const T& b);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000629
630template <class T, class Compare>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500631 constexpr const T& // constexpr in C++14
632 min(const T& a, const T& b, Compare comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000633
Howard Hinnantb120e7a2010-08-21 20:10:01 +0000634template<class T>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500635 constexpr T // constexpr in C++14
636 min(initializer_list<T> t);
Howard Hinnantb120e7a2010-08-21 20:10:01 +0000637
638template<class T, class Compare>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500639 constexpr T // constexpr in C++14
640 min(initializer_list<T> t, Compare comp);
Howard Hinnantb120e7a2010-08-21 20:10:01 +0000641
Marshall Clow3e18d0e2016-03-07 22:43:49 +0000642template<class T>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500643 constexpr const T& clamp(const T& v, const T& lo, const T& hi); // C++17
Marshall Clow3e18d0e2016-03-07 22:43:49 +0000644
645template<class T, class Compare>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500646 constexpr const T& clamp(const T& v, const T& lo, const T& hi, Compare comp); // C++17
Marshall Clow3e18d0e2016-03-07 22:43:49 +0000647
Howard Hinnantb120e7a2010-08-21 20:10:01 +0000648template <class ForwardIterator>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500649 constexpr ForwardIterator // constexpr in C++14
650 max_element(ForwardIterator first, ForwardIterator last);
Howard Hinnantb120e7a2010-08-21 20:10:01 +0000651
652template <class ForwardIterator, class Compare>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500653 constexpr ForwardIterator // constexpr in C++14
654 max_element(ForwardIterator first, ForwardIterator last, Compare comp);
Howard Hinnantb120e7a2010-08-21 20:10:01 +0000655
Howard Hinnantc51e1022010-05-11 19:42:16 +0000656template <class T>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500657 constexpr const T& // constexpr in C++14
658 max(const T& a, const T& b);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000659
660template <class T, class Compare>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500661 constexpr const T& // constexpr in C++14
662 max(const T& a, const T& b, Compare comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000663
Howard Hinnantb120e7a2010-08-21 20:10:01 +0000664template<class T>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500665 constexpr T // constexpr in C++14
666 max(initializer_list<T> t);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000667
Howard Hinnantb120e7a2010-08-21 20:10:01 +0000668template<class T, class Compare>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500669 constexpr T // constexpr in C++14
670 max(initializer_list<T> t, Compare comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000671
Howard Hinnantb120e7a2010-08-21 20:10:01 +0000672template<class ForwardIterator>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500673 constexpr pair<ForwardIterator, ForwardIterator> // constexpr in C++14
674 minmax_element(ForwardIterator first, ForwardIterator last);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000675
Howard Hinnantb120e7a2010-08-21 20:10:01 +0000676template<class ForwardIterator, class Compare>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500677 constexpr pair<ForwardIterator, ForwardIterator> // constexpr in C++14
678 minmax_element(ForwardIterator first, ForwardIterator last, Compare comp);
Howard Hinnantb120e7a2010-08-21 20:10:01 +0000679
680template<class T>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500681 constexpr pair<const T&, const T&> // constexpr in C++14
682 minmax(const T& a, const T& b);
Howard Hinnantb120e7a2010-08-21 20:10:01 +0000683
684template<class T, class Compare>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500685 constexpr pair<const T&, const T&> // constexpr in C++14
686 minmax(const T& a, const T& b, Compare comp);
Howard Hinnantb120e7a2010-08-21 20:10:01 +0000687
688template<class T>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500689 constexpr pair<T, T> // constexpr in C++14
690 minmax(initializer_list<T> t);
Howard Hinnantb120e7a2010-08-21 20:10:01 +0000691
692template<class T, class Compare>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500693 constexpr pair<T, T> // constexpr in C++14
694 minmax(initializer_list<T> t, Compare comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000695
696template <class InputIterator1, class InputIterator2>
Marshall Clow5492c8a2018-01-22 20:44:33 +0000697 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000698 lexicographical_compare(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2);
699
700template <class InputIterator1, class InputIterator2, class Compare>
Marshall Clow5492c8a2018-01-22 20:44:33 +0000701 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000702 lexicographical_compare(InputIterator1 first1, InputIterator1 last1,
703 InputIterator2 first2, InputIterator2 last2, Compare comp);
704
705template <class BidirectionalIterator>
Arthur O'Dwyere50e7472020-12-17 00:01:08 -0500706 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000707 next_permutation(BidirectionalIterator first, BidirectionalIterator last);
708
709template <class BidirectionalIterator, class Compare>
Arthur O'Dwyere50e7472020-12-17 00:01:08 -0500710 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000711 next_permutation(BidirectionalIterator first, BidirectionalIterator last, Compare comp);
712
713template <class BidirectionalIterator>
Arthur O'Dwyere50e7472020-12-17 00:01:08 -0500714 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000715 prev_permutation(BidirectionalIterator first, BidirectionalIterator last);
716
717template <class BidirectionalIterator, class Compare>
Arthur O'Dwyere50e7472020-12-17 00:01:08 -0500718 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000719 prev_permutation(BidirectionalIterator first, BidirectionalIterator last, Compare comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000720} // std
721
722*/
723
Arthur O'Dwyer3693d7a2022-02-04 13:09:30 -0500724#include <__bits>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000725#include <__config>
Louis Dionnea60dd872021-06-17 11:30:11 -0400726#include <__debug>
Howard Hinnant60e5cf42012-07-26 17:09:09 +0000727#include <cstddef>
Arthur O'Dwyeref181602021-05-19 11:57:04 -0400728#include <cstring>
729#include <functional>
730#include <initializer_list>
731#include <iterator>
732#include <memory>
733#include <type_traits>
Marshall Clow0a1e7502018-09-12 19:41:40 +0000734#include <version>
Howard Hinnantea382952013-08-14 18:00:20 +0000735
Louis Dionnea60dd872021-06-17 11:30:11 -0400736#include <__algorithm/adjacent_find.h>
737#include <__algorithm/all_of.h>
738#include <__algorithm/any_of.h>
739#include <__algorithm/binary_search.h>
740#include <__algorithm/clamp.h>
741#include <__algorithm/comp.h>
742#include <__algorithm/comp_ref_type.h>
743#include <__algorithm/copy.h>
744#include <__algorithm/copy_backward.h>
745#include <__algorithm/copy_if.h>
746#include <__algorithm/copy_n.h>
747#include <__algorithm/count.h>
748#include <__algorithm/count_if.h>
749#include <__algorithm/equal.h>
750#include <__algorithm/equal_range.h>
Louis Dionnea60dd872021-06-17 11:30:11 -0400751#include <__algorithm/fill.h>
Arthur O'Dwyer65077c02022-01-07 09:45:05 -0500752#include <__algorithm/fill_n.h>
Louis Dionnea60dd872021-06-17 11:30:11 -0400753#include <__algorithm/find.h>
754#include <__algorithm/find_end.h>
755#include <__algorithm/find_first_of.h>
756#include <__algorithm/find_if.h>
757#include <__algorithm/find_if_not.h>
758#include <__algorithm/for_each.h>
759#include <__algorithm/for_each_n.h>
Louis Dionnea60dd872021-06-17 11:30:11 -0400760#include <__algorithm/generate.h>
Arthur O'Dwyer65077c02022-01-07 09:45:05 -0500761#include <__algorithm/generate_n.h>
Louis Dionnea60dd872021-06-17 11:30:11 -0400762#include <__algorithm/half_positive.h>
Nikolas Klauserdd5ad212022-02-21 23:07:02 +0100763#include <__algorithm/in_found_result.h>
Nikolas Klauser671b4752022-02-11 17:01:58 +0100764#include <__algorithm/in_fun_result.h>
Nikolas Klauser05e2cd82022-01-25 11:21:47 +0100765#include <__algorithm/in_in_out_result.h>
Nikolas Klauserf74be4e2022-01-14 02:55:51 +0100766#include <__algorithm/in_in_result.h>
Nikolas Klauser61ce8162022-02-03 02:17:03 +0100767#include <__algorithm/in_out_out_result.h>
Konstantin Varlamov74736812022-01-10 22:49:37 -0800768#include <__algorithm/in_out_result.h>
Louis Dionnea60dd872021-06-17 11:30:11 -0400769#include <__algorithm/includes.h>
770#include <__algorithm/inplace_merge.h>
771#include <__algorithm/is_heap.h>
772#include <__algorithm/is_heap_until.h>
773#include <__algorithm/is_partitioned.h>
774#include <__algorithm/is_permutation.h>
775#include <__algorithm/is_sorted.h>
776#include <__algorithm/is_sorted_until.h>
Christopher Di Bella41f26e82021-06-05 02:47:47 +0000777#include <__algorithm/iter_swap.h>
Louis Dionnea60dd872021-06-17 11:30:11 -0400778#include <__algorithm/lexicographical_compare.h>
779#include <__algorithm/lower_bound.h>
780#include <__algorithm/make_heap.h>
781#include <__algorithm/max.h>
782#include <__algorithm/max_element.h>
783#include <__algorithm/merge.h>
784#include <__algorithm/min.h>
785#include <__algorithm/min_element.h>
Nikolas Klauser2e263162022-02-21 22:48:36 +0100786#include <__algorithm/min_max_result.h>
Louis Dionnea60dd872021-06-17 11:30:11 -0400787#include <__algorithm/minmax.h>
788#include <__algorithm/minmax_element.h>
789#include <__algorithm/mismatch.h>
790#include <__algorithm/move.h>
791#include <__algorithm/move_backward.h>
792#include <__algorithm/next_permutation.h>
793#include <__algorithm/none_of.h>
794#include <__algorithm/nth_element.h>
795#include <__algorithm/partial_sort.h>
796#include <__algorithm/partial_sort_copy.h>
797#include <__algorithm/partition.h>
798#include <__algorithm/partition_copy.h>
799#include <__algorithm/partition_point.h>
800#include <__algorithm/pop_heap.h>
801#include <__algorithm/prev_permutation.h>
802#include <__algorithm/push_heap.h>
Nikolas Klauser37d076e2022-03-12 01:45:35 +0100803#include <__algorithm/ranges_find.h>
804#include <__algorithm/ranges_find_if.h>
805#include <__algorithm/ranges_find_if_not.h>
Nikolas Klauserf2a69ea2022-03-07 17:01:52 +0100806#include <__algorithm/ranges_max_element.h>
Nikolas Klauser0a62a172022-02-11 13:11:57 +0100807#include <__algorithm/ranges_min_element.h>
Nikolas Klauser12fc9bf2022-03-08 23:12:35 +0100808#include <__algorithm/ranges_mismatch.h>
Nikolas Klauser4ceab5f2022-02-10 13:33:03 +0100809#include <__algorithm/ranges_swap_ranges.h>
Louis Dionnea60dd872021-06-17 11:30:11 -0400810#include <__algorithm/remove.h>
811#include <__algorithm/remove_copy.h>
812#include <__algorithm/remove_copy_if.h>
813#include <__algorithm/remove_if.h>
814#include <__algorithm/replace.h>
815#include <__algorithm/replace_copy.h>
816#include <__algorithm/replace_copy_if.h>
817#include <__algorithm/replace_if.h>
818#include <__algorithm/reverse.h>
819#include <__algorithm/reverse_copy.h>
820#include <__algorithm/rotate.h>
821#include <__algorithm/rotate_copy.h>
822#include <__algorithm/sample.h>
823#include <__algorithm/search.h>
824#include <__algorithm/search_n.h>
825#include <__algorithm/set_difference.h>
826#include <__algorithm/set_intersection.h>
827#include <__algorithm/set_symmetric_difference.h>
828#include <__algorithm/set_union.h>
829#include <__algorithm/shift_left.h>
830#include <__algorithm/shift_right.h>
831#include <__algorithm/shuffle.h>
832#include <__algorithm/sift_down.h>
833#include <__algorithm/sort.h>
834#include <__algorithm/sort_heap.h>
835#include <__algorithm/stable_partition.h>
836#include <__algorithm/stable_sort.h>
Christopher Di Bella41f26e82021-06-05 02:47:47 +0000837#include <__algorithm/swap_ranges.h>
Louis Dionnea60dd872021-06-17 11:30:11 -0400838#include <__algorithm/transform.h>
Louis Dionnea60dd872021-06-17 11:30:11 -0400839#include <__algorithm/unique.h>
Arthur O'Dwyer65077c02022-01-07 09:45:05 -0500840#include <__algorithm/unique_copy.h>
Louis Dionnea60dd872021-06-17 11:30:11 -0400841#include <__algorithm/unwrap_iter.h>
842#include <__algorithm/upper_bound.h>
Eric Fiselier14b6de92014-08-10 23:53:08 +0000843
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000844#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Arthur O'Dwyer6eeaa002022-02-01 20:16:40 -0500845# pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000846#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000847
Louis Dionne59d0b3c2019-08-05 18:29:14 +0000848#if defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS) && _LIBCPP_STD_VER >= 17
Louis Dionned53d8c02019-08-06 21:11:24 +0000849# include <__pstl_algorithm>
Louis Dionne59d0b3c2019-08-05 18:29:14 +0000850#endif
851
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400852#endif // _LIBCPP_ALGORITHM