blob: a7912cc4a2620e6d43bf6ff08e3c3c08c75ccb53 [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
Louis Dionne9bd93882021-11-17 16:25:01 -05002//===----------------------------------------------------------------------===//
Howard Hinnantc51e1022010-05-11 19:42:16 +00003//
Chandler Carruthd2012102019-01-19 10:56:40 +00004// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Howard Hinnantc51e1022010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_ALGORITHM
11#define _LIBCPP_ALGORITHM
12
13/*
14 algorithm synopsis
15
16#include <initializer_list>
17
18namespace std
19{
20
Nikolas Klauserf74be4e2022-01-14 02:55:51 +010021namespace ranges {
Nikolas Klauser671b4752022-02-11 17:01:58 +010022 template <class I, class F>
Nikolas Klauser2e263162022-02-21 22:48:36 +010023 struct in_fun_result; // since C++20
Nikolas Klauser671b4752022-02-11 17:01:58 +010024
Nikolas Klauserf74be4e2022-01-14 02:55:51 +010025 template <class I1, class I2>
Nikolas Klauser2e263162022-02-21 22:48:36 +010026 struct in_in_result; // since C++20
Nikolas Klauser05e2cd82022-01-25 11:21:47 +010027
28 template <class I1, class I2, class O>
Nikolas Klauser2e263162022-02-21 22:48:36 +010029 struct in_in_out_result; // since C++20
Nikolas Klauser61ce8162022-02-03 02:17:03 +010030
31 template <class I, class O1, class O2>
32 struct in_out_out_result; // since C++20
Nikolas Klauser671b4752022-02-11 17:01:58 +010033
Nikolas Klauser2e263162022-02-21 22:48:36 +010034 template <class I1, class I2>
35 struct min_max_result; // since C++20
36
Nikolas Klauserdd5ad212022-02-21 23:07:02 +010037 template <class I>
38 struct in_found_result; // since C++20
39
Nikolas Klauser0a62a172022-02-11 13:11:57 +010040 template<forward_iterator I, sentinel_for<I> S, class Proj = identity,
41 indirect_strict_weak_order<projected<I, Proj>> Comp = ranges::less> // since C++20
42 constexpr I min_element(I first, S last, Comp comp = {}, Proj proj = {});
43
44 template<forward_range R, class Proj = identity,
45 indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less> // since C++20
46 constexpr borrowed_iterator_t<R> min_element(R&& r, Comp comp = {}, Proj proj = {});
Nikolas Klauser12fc9bf2022-03-08 23:12:35 +010047
48 template <input_iterator I1, sentinel_for<_I1> S1, input_iterator I2, sentinel_for<_I2> S2,
49 class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
50 requires indirectly_comparable<I1, I2, Pred, Proj1, Proj2>
51 constexpr mismatch_result<_I1, _I2>
52 mismatch()(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}) // since C++20
53
54 template <input_range R1, input_range R2,
55 class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
56 requires indirectly_comparable<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
57 constexpr mismatch_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>>
58 mismatch(R1&& r1, R2&& r2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}) // since C++20
Nikolas Klauser37d076e2022-03-12 01:45:35 +010059
Nikolas Klauser37d076e2022-03-12 01:45:35 +010060 requires indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T*>
61 constexpr I find(I first, S last, const T& value, Proj proj = {}); // since C++20
62
63 template<input_range R, class T, class Proj = identity>
64 requires indirect_binary_predicate<ranges::equal_to, projected<iterator_t<R>, Proj>, const T*>
65 constexpr borrowed_iterator_t<R>
66 find(R&& r, const T& value, Proj proj = {}); // since C++20
67
68 template<input_iterator I, sentinel_for<I> S, class Proj = identity,
69 indirect_unary_predicate<projected<I, Proj>> Pred>
70 constexpr I find_if(I first, S last, Pred pred, Proj proj = {}); // since C++20
71
72 template<input_range R, class Proj = identity,
73 indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
74 constexpr borrowed_iterator_t<R>
75 find_if(R&& r, Pred pred, Proj proj = {}); // since C++20
76
77 template<input_iterator I, sentinel_for<I> S, class Proj = identity,
78 indirect_unary_predicate<projected<I, Proj>> Pred>
79 constexpr I find_if_not(I first, S last, Pred pred, Proj proj = {}); // since C++20
80
81 template<input_range R, class Proj = identity,
82 indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
83 constexpr borrowed_iterator_t<R>
84 find_if_not(R&& r, Pred pred, Proj proj = {}); // since C++20
Nikolas Klauser3559e452022-03-18 02:57:08 +010085
Nikolas Klauser573cd6f2022-04-03 09:17:01 +020086 template<class T, class Proj = identity,
87 indirect_strict_weak_order<projected<const T*, Proj>> Comp = ranges::less>
88 constexpr const T& min(const T& a, const T& b, Comp comp = {}, Proj proj = {}); // since C++20
Nikolas Klauser3559e452022-03-18 02:57:08 +010089
Nikolas Klauser573cd6f2022-04-03 09:17:01 +020090 template<copyable T, class Proj = identity,
91 indirect_strict_weak_order<projected<const T*, Proj>> Comp = ranges::less>
92 constexpr T min(initializer_list<T> r, Comp comp = {}, Proj proj = {}); // since C++20
Nikolas Klauser3559e452022-03-18 02:57:08 +010093
94 template<input_range R, class Proj = identity,
95 indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less>
96 requires indirectly_copyable_storable<iterator_t<R>, range_value_t<R>*>
97 constexpr range_value_t<R>
98 min(R&& r, Comp comp = {}, Proj proj = {}); // since C++20
Nikolas Klauser573cd6f2022-04-03 09:17:01 +020099
100 template<class T, class Proj = identity,
101 indirect_strict_weak_order<projected<const T*, Proj>> Comp = ranges::less>
102 constexpr const T& max(const T& a, const T& b, Comp comp = {}, Proj proj = {}); // since C++20
103
104 template<copyable T, class Proj = identity,
105 indirect_strict_weak_order<projected<const T*, Proj>> Comp = ranges::less>
106 constexpr T max(initializer_list<T> r, Comp comp = {}, Proj proj = {}); // since C++20
107
108 template<input_range R, class Proj = identity,
109 indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less>
110 requires indirectly_copyable_storable<iterator_t<R>, range_value_t<R>*>
111 constexpr range_value_t<R>
112 max(R&& r, Comp comp = {}, Proj proj = {}); // since C++20
Nikolas Klauserf74be4e2022-01-14 02:55:51 +0100113}
114
Marshall Clowd607fdb2018-01-15 17:20:36 +0000115 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000116 all_of(InputIterator first, InputIterator last, Predicate pred);
117
118template <class InputIterator, class Predicate>
Marshall Clowd607fdb2018-01-15 17:20:36 +0000119 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000120 any_of(InputIterator first, InputIterator last, Predicate pred);
121
122template <class InputIterator, class Predicate>
Marshall Clowd607fdb2018-01-15 17:20:36 +0000123 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000124 none_of(InputIterator first, InputIterator last, Predicate pred);
125
126template <class InputIterator, class Function>
Marshall Clow5492c8a2018-01-22 20:44:33 +0000127 constexpr Function // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000128 for_each(InputIterator first, InputIterator last, Function f);
129
Marshall Clowde0169c2017-05-25 02:29:54 +0000130template<class InputIterator, class Size, class Function>
Marshall Clow5492c8a2018-01-22 20:44:33 +0000131 constexpr InputIterator // constexpr in C++20
132 for_each_n(InputIterator first, Size n, Function f); // C++17
Marshall Clowde0169c2017-05-25 02:29:54 +0000133
Howard Hinnantc51e1022010-05-11 19:42:16 +0000134template <class InputIterator, class T>
Marshall Clowee0161e2018-01-15 19:26:05 +0000135 constexpr InputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000136 find(InputIterator first, InputIterator last, const T& value);
137
138template <class InputIterator, class Predicate>
Marshall Clowee0161e2018-01-15 19:26:05 +0000139 constexpr InputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000140 find_if(InputIterator first, InputIterator last, Predicate pred);
141
142template<class InputIterator, class Predicate>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500143 constexpr InputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000144 find_if_not(InputIterator first, InputIterator last, Predicate pred);
145
146template <class ForwardIterator1, class ForwardIterator2>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500147 constexpr ForwardIterator1 // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000148 find_end(ForwardIterator1 first1, ForwardIterator1 last1,
149 ForwardIterator2 first2, ForwardIterator2 last2);
150
151template <class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500152 constexpr ForwardIterator1 // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000153 find_end(ForwardIterator1 first1, ForwardIterator1 last1,
154 ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred);
155
156template <class ForwardIterator1, class ForwardIterator2>
Marshall Clowee0161e2018-01-15 19:26:05 +0000157 constexpr ForwardIterator1 // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000158 find_first_of(ForwardIterator1 first1, ForwardIterator1 last1,
159 ForwardIterator2 first2, ForwardIterator2 last2);
160
161template <class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
Marshall Clowee0161e2018-01-15 19:26:05 +0000162 constexpr ForwardIterator1 // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000163 find_first_of(ForwardIterator1 first1, ForwardIterator1 last1,
164 ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred);
165
166template <class ForwardIterator>
Marshall Clowee0161e2018-01-15 19:26:05 +0000167 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000168 adjacent_find(ForwardIterator first, ForwardIterator last);
169
170template <class ForwardIterator, class BinaryPredicate>
Marshall Clowee0161e2018-01-15 19:26:05 +0000171 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000172 adjacent_find(ForwardIterator first, ForwardIterator last, BinaryPredicate pred);
173
174template <class InputIterator, class T>
Marshall Clow3c0558f2018-01-15 19:40:34 +0000175 constexpr typename iterator_traits<InputIterator>::difference_type // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000176 count(InputIterator first, InputIterator last, const T& value);
177
178template <class InputIterator, class Predicate>
Marshall Clow3c0558f2018-01-15 19:40:34 +0000179 constexpr typename iterator_traits<InputIterator>::difference_type // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000180 count_if(InputIterator first, InputIterator last, Predicate pred);
181
182template <class InputIterator1, class InputIterator2>
Marshall Clow30bf3022018-01-16 02:04:10 +0000183 constexpr pair<InputIterator1, InputIterator2> // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000184 mismatch(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2);
185
Marshall Clow96b42b22013-05-09 21:14:23 +0000186template <class InputIterator1, class InputIterator2>
Marshall Clow30bf3022018-01-16 02:04:10 +0000187 constexpr pair<InputIterator1, InputIterator2> // constexpr in C++20
Aditya Kumar3a0179a2016-08-25 11:52:38 +0000188 mismatch(InputIterator1 first1, InputIterator1 last1,
Marshall Clow96b42b22013-05-09 21:14:23 +0000189 InputIterator2 first2, InputIterator2 last2); // **C++14**
190
Howard Hinnantc51e1022010-05-11 19:42:16 +0000191template <class InputIterator1, class InputIterator2, class BinaryPredicate>
Marshall Clow30bf3022018-01-16 02:04:10 +0000192 constexpr pair<InputIterator1, InputIterator2> // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000193 mismatch(InputIterator1 first1, InputIterator1 last1,
194 InputIterator2 first2, BinaryPredicate pred);
195
Marshall Clow96b42b22013-05-09 21:14:23 +0000196template <class InputIterator1, class InputIterator2, class BinaryPredicate>
Marshall Clow30bf3022018-01-16 02:04:10 +0000197 constexpr pair<InputIterator1, InputIterator2> // constexpr in C++20
Marshall Clow96b42b22013-05-09 21:14:23 +0000198 mismatch(InputIterator1 first1, InputIterator1 last1,
199 InputIterator2 first2, InputIterator2 last2,
200 BinaryPredicate pred); // **C++14**
201
Howard Hinnantc51e1022010-05-11 19:42:16 +0000202template <class InputIterator1, class InputIterator2>
Marshall Clow30bf3022018-01-16 02:04:10 +0000203 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000204 equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2);
205
Marshall Clow96b42b22013-05-09 21:14:23 +0000206template <class InputIterator1, class InputIterator2>
Marshall Clow30bf3022018-01-16 02:04:10 +0000207 constexpr bool // constexpr in C++20
Aditya Kumar3a0179a2016-08-25 11:52:38 +0000208 equal(InputIterator1 first1, InputIterator1 last1,
Marshall Clow96b42b22013-05-09 21:14:23 +0000209 InputIterator2 first2, InputIterator2 last2); // **C++14**
210
Howard Hinnantc51e1022010-05-11 19:42:16 +0000211template <class InputIterator1, class InputIterator2, class BinaryPredicate>
Marshall Clow30bf3022018-01-16 02:04:10 +0000212 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000213 equal(InputIterator1 first1, InputIterator1 last1,
214 InputIterator2 first2, BinaryPredicate pred);
215
Marshall Clow96b42b22013-05-09 21:14:23 +0000216template <class InputIterator1, class InputIterator2, class BinaryPredicate>
Marshall Clow30bf3022018-01-16 02:04:10 +0000217 constexpr bool // constexpr in C++20
Marshall Clow96b42b22013-05-09 21:14:23 +0000218 equal(InputIterator1 first1, InputIterator1 last1,
219 InputIterator2 first2, InputIterator2 last2,
220 BinaryPredicate pred); // **C++14**
221
Howard Hinnantc51e1022010-05-11 19:42:16 +0000222template<class ForwardIterator1, class ForwardIterator2>
Marshall Clow96d050a2018-01-15 16:16:32 +0000223 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000224 is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
225 ForwardIterator2 first2);
226
Marshall Clow96b42b22013-05-09 21:14:23 +0000227template<class ForwardIterator1, class ForwardIterator2>
Marshall Clow96d050a2018-01-15 16:16:32 +0000228 constexpr bool // constexpr in C++20
Marshall Clow96b42b22013-05-09 21:14:23 +0000229 is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
230 ForwardIterator2 first2, ForwardIterator2 last2); // **C++14**
231
Howard Hinnantc51e1022010-05-11 19:42:16 +0000232template<class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
Marshall Clow96d050a2018-01-15 16:16:32 +0000233 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000234 is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
235 ForwardIterator2 first2, BinaryPredicate pred);
236
Marshall Clow96b42b22013-05-09 21:14:23 +0000237template<class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
Marshall Clow96d050a2018-01-15 16:16:32 +0000238 constexpr bool // constexpr in C++20
Marshall Clow96b42b22013-05-09 21:14:23 +0000239 is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
240 ForwardIterator2 first2, ForwardIterator2 last2,
241 BinaryPredicate pred); // **C++14**
242
Howard Hinnantc51e1022010-05-11 19:42:16 +0000243template <class ForwardIterator1, class ForwardIterator2>
Marshall Clow323fc5b2018-01-16 15:48:27 +0000244 constexpr ForwardIterator1 // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000245 search(ForwardIterator1 first1, ForwardIterator1 last1,
246 ForwardIterator2 first2, ForwardIterator2 last2);
247
248template <class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
Marshall Clow323fc5b2018-01-16 15:48:27 +0000249 constexpr ForwardIterator1 // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000250 search(ForwardIterator1 first1, ForwardIterator1 last1,
251 ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred);
252
253template <class ForwardIterator, class Size, class T>
Marshall Clow323fc5b2018-01-16 15:48:27 +0000254 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000255 search_n(ForwardIterator first, ForwardIterator last, Size count, const T& value);
256
257template <class ForwardIterator, class Size, class T, class BinaryPredicate>
Marshall Clow323fc5b2018-01-16 15:48:27 +0000258 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000259 search_n(ForwardIterator first, ForwardIterator last,
260 Size count, const T& value, BinaryPredicate pred);
261
262template <class InputIterator, class OutputIterator>
Louis Dionne65b433b2019-11-06 12:02:41 +0000263 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000264 copy(InputIterator first, InputIterator last, OutputIterator result);
265
266template<class InputIterator, class OutputIterator, class Predicate>
Louis Dionne65b433b2019-11-06 12:02:41 +0000267 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000268 copy_if(InputIterator first, InputIterator last,
269 OutputIterator result, Predicate pred);
270
271template<class InputIterator, class Size, class OutputIterator>
Louis Dionne65b433b2019-11-06 12:02:41 +0000272 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000273 copy_n(InputIterator first, Size n, OutputIterator result);
274
275template <class BidirectionalIterator1, class BidirectionalIterator2>
Louis Dionne65b433b2019-11-06 12:02:41 +0000276 constexpr BidirectionalIterator2 // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000277 copy_backward(BidirectionalIterator1 first, BidirectionalIterator1 last,
278 BidirectionalIterator2 result);
279
280template <class ForwardIterator1, class ForwardIterator2>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500281 constexpr ForwardIterator2 // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000282 swap_ranges(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2);
283
Nikolas Klauser4ceab5f2022-02-10 13:33:03 +0100284template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2>
285 requires indirectly_swappable<I1, I2>
286 constexpr ranges::swap_ranges_result<I1, I2>
287 ranges::swap_ranges(I1 first1, S1 last1, I2 first2, S2 last2);
288
289template<input_range R1, input_range R2>
290 requires indirectly_swappable<iterator_t<R1>, iterator_t<R2>>
291 constexpr ranges::swap_ranges_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>>
292 ranges::swap_ranges(R1&& r1, R2&& r2);
293
Howard Hinnantc51e1022010-05-11 19:42:16 +0000294template <class ForwardIterator1, class ForwardIterator2>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500295 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000296 iter_swap(ForwardIterator1 a, ForwardIterator2 b);
297
298template <class InputIterator, class OutputIterator, class UnaryOperation>
Marshall Clow31427c62018-01-19 17:45:39 +0000299 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000300 transform(InputIterator first, InputIterator last, OutputIterator result, UnaryOperation op);
301
302template <class InputIterator1, class InputIterator2, class OutputIterator, class BinaryOperation>
Marshall Clow31427c62018-01-19 17:45:39 +0000303 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000304 transform(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2,
305 OutputIterator result, BinaryOperation binary_op);
306
307template <class ForwardIterator, class T>
Marshall Clow01bbbd22018-01-19 18:07:29 +0000308 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000309 replace(ForwardIterator first, ForwardIterator last, const T& old_value, const T& new_value);
310
311template <class ForwardIterator, class Predicate, class T>
Marshall Clow01bbbd22018-01-19 18:07:29 +0000312 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000313 replace_if(ForwardIterator first, ForwardIterator last, Predicate pred, const T& new_value);
314
315template <class InputIterator, class OutputIterator, class T>
Marshall Clow01bbbd22018-01-19 18:07:29 +0000316 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000317 replace_copy(InputIterator first, InputIterator last, OutputIterator result,
318 const T& old_value, const T& new_value);
319
320template <class InputIterator, class OutputIterator, class Predicate, class T>
Marshall Clow01bbbd22018-01-19 18:07:29 +0000321 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000322 replace_copy_if(InputIterator first, InputIterator last, OutputIterator result, Predicate pred, const T& new_value);
323
324template <class ForwardIterator, class T>
Marshall Clowe9cdc5c2018-01-20 20:14:32 +0000325 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000326 fill(ForwardIterator first, ForwardIterator last, const T& value);
327
328template <class OutputIterator, class Size, class T>
Marshall Clowe9cdc5c2018-01-20 20:14:32 +0000329 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000330 fill_n(OutputIterator first, Size n, const T& value);
331
332template <class ForwardIterator, class Generator>
Marshall Clowe9cdc5c2018-01-20 20:14:32 +0000333 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000334 generate(ForwardIterator first, ForwardIterator last, Generator gen);
335
336template <class OutputIterator, class Size, class Generator>
Marshall Clowe9cdc5c2018-01-20 20:14:32 +0000337 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000338 generate_n(OutputIterator first, Size n, Generator gen);
339
340template <class ForwardIterator, class T>
Marshall Clow7c0fbd82018-01-22 21:43:04 +0000341 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000342 remove(ForwardIterator first, ForwardIterator last, const T& value);
343
344template <class ForwardIterator, class Predicate>
Marshall Clow7c0fbd82018-01-22 21:43:04 +0000345 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000346 remove_if(ForwardIterator first, ForwardIterator last, Predicate pred);
347
348template <class InputIterator, class OutputIterator, class T>
Marshall Clow7c0fbd82018-01-22 21:43:04 +0000349 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000350 remove_copy(InputIterator first, InputIterator last, OutputIterator result, const T& value);
351
352template <class InputIterator, class OutputIterator, class Predicate>
Marshall Clow7c0fbd82018-01-22 21:43:04 +0000353 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000354 remove_copy_if(InputIterator first, InputIterator last, OutputIterator result, Predicate pred);
355
356template <class ForwardIterator>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500357 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000358 unique(ForwardIterator first, ForwardIterator last);
359
360template <class ForwardIterator, class BinaryPredicate>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500361 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000362 unique(ForwardIterator first, ForwardIterator last, BinaryPredicate pred);
363
364template <class InputIterator, class OutputIterator>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500365 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000366 unique_copy(InputIterator first, InputIterator last, OutputIterator result);
367
368template <class InputIterator, class OutputIterator, class BinaryPredicate>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500369 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000370 unique_copy(InputIterator first, InputIterator last, OutputIterator result, BinaryPredicate pred);
371
372template <class BidirectionalIterator>
Arthur O'Dwyere50e7472020-12-17 00:01:08 -0500373 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000374 reverse(BidirectionalIterator first, BidirectionalIterator last);
375
376template <class BidirectionalIterator, class OutputIterator>
Marshall Clow7c0fbd82018-01-22 21:43:04 +0000377 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000378 reverse_copy(BidirectionalIterator first, BidirectionalIterator last, OutputIterator result);
379
380template <class ForwardIterator>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500381 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000382 rotate(ForwardIterator first, ForwardIterator middle, ForwardIterator last);
383
384template <class ForwardIterator, class OutputIterator>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500385 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000386 rotate_copy(ForwardIterator first, ForwardIterator middle, ForwardIterator last, OutputIterator result);
387
388template <class RandomAccessIterator>
389 void
Marshall Clowfac06e52017-03-23 13:43:37 +0000390 random_shuffle(RandomAccessIterator first, RandomAccessIterator last); // deprecated in C++14, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000391
392template <class RandomAccessIterator, class RandomNumberGenerator>
393 void
Marshall Clow83f35392014-03-03 06:14:19 +0000394 random_shuffle(RandomAccessIterator first, RandomAccessIterator last,
Marshall Clowfac06e52017-03-23 13:43:37 +0000395 RandomNumberGenerator& rand); // deprecated in C++14, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000396
Eric Fiselier1208fcd2016-08-28 22:14:37 +0000397template<class PopulationIterator, class SampleIterator,
398 class Distance, class UniformRandomBitGenerator>
399 SampleIterator sample(PopulationIterator first, PopulationIterator last,
400 SampleIterator out, Distance n,
401 UniformRandomBitGenerator&& g); // C++17
402
Howard Hinnant578ac0f2010-05-26 17:49:34 +0000403template<class RandomAccessIterator, class UniformRandomNumberGenerator>
404 void shuffle(RandomAccessIterator first, RandomAccessIterator last,
Howard Hinnanta5e71782010-11-18 01:47:02 +0000405 UniformRandomNumberGenerator&& g);
Howard Hinnant578ac0f2010-05-26 17:49:34 +0000406
Arthur O'Dwyercea050d2020-12-26 01:39:03 -0500407template<class ForwardIterator>
408 constexpr ForwardIterator
409 shift_left(ForwardIterator first, ForwardIterator last,
410 typename iterator_traits<ForwardIterator>::difference_type n); // C++20
411
412template<class ForwardIterator>
413 constexpr ForwardIterator
414 shift_right(ForwardIterator first, ForwardIterator last,
415 typename iterator_traits<ForwardIterator>::difference_type n); // C++20
416
Howard Hinnantc51e1022010-05-11 19:42:16 +0000417template <class InputIterator, class Predicate>
Marshall Clow96d050a2018-01-15 16:16:32 +0000418 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000419 is_partitioned(InputIterator first, InputIterator last, Predicate pred);
420
421template <class ForwardIterator, class Predicate>
Arthur O'Dwyere50e7472020-12-17 00:01:08 -0500422 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000423 partition(ForwardIterator first, ForwardIterator last, Predicate pred);
424
425template <class InputIterator, class OutputIterator1,
426 class OutputIterator2, class Predicate>
Marshall Clow5492c8a2018-01-22 20:44:33 +0000427 constexpr pair<OutputIterator1, OutputIterator2> // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000428 partition_copy(InputIterator first, InputIterator last,
429 OutputIterator1 out_true, OutputIterator2 out_false,
430 Predicate pred);
431
432template <class ForwardIterator, class Predicate>
433 ForwardIterator
434 stable_partition(ForwardIterator first, ForwardIterator last, Predicate pred);
435
436template<class ForwardIterator, class Predicate>
Marshall Clowe00916c2018-01-16 02:34:41 +0000437 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000438 partition_point(ForwardIterator first, ForwardIterator last, Predicate pred);
439
440template <class ForwardIterator>
Marshall Clow96d050a2018-01-15 16:16:32 +0000441 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000442 is_sorted(ForwardIterator first, ForwardIterator last);
443
444template <class ForwardIterator, class Compare>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500445 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000446 is_sorted(ForwardIterator first, ForwardIterator last, Compare comp);
447
448template<class ForwardIterator>
Marshall Clow3c0558f2018-01-15 19:40:34 +0000449 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000450 is_sorted_until(ForwardIterator first, ForwardIterator last);
451
452template <class ForwardIterator, class Compare>
Marshall Clow3c0558f2018-01-15 19:40:34 +0000453 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000454 is_sorted_until(ForwardIterator first, ForwardIterator last, Compare comp);
455
456template <class RandomAccessIterator>
Arthur O'Dwyer1bb0f672020-12-20 15:21:42 -0500457 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000458 sort(RandomAccessIterator first, RandomAccessIterator last);
459
460template <class RandomAccessIterator, class Compare>
Arthur O'Dwyer1bb0f672020-12-20 15:21:42 -0500461 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000462 sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
463
464template <class RandomAccessIterator>
465 void
466 stable_sort(RandomAccessIterator first, RandomAccessIterator last);
467
468template <class RandomAccessIterator, class Compare>
469 void
470 stable_sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
471
472template <class RandomAccessIterator>
Arthur O'Dwyer2dfea5d2020-12-17 00:26:18 -0500473 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000474 partial_sort(RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last);
475
476template <class RandomAccessIterator, class Compare>
Arthur O'Dwyer2dfea5d2020-12-17 00:26:18 -0500477 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000478 partial_sort(RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last, Compare comp);
479
480template <class InputIterator, class RandomAccessIterator>
Arthur O'Dwyer2dfea5d2020-12-17 00:26:18 -0500481 constexpr RandomAccessIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000482 partial_sort_copy(InputIterator first, InputIterator last,
483 RandomAccessIterator result_first, RandomAccessIterator result_last);
484
485template <class InputIterator, class RandomAccessIterator, class Compare>
Arthur O'Dwyer2dfea5d2020-12-17 00:26:18 -0500486 constexpr RandomAccessIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000487 partial_sort_copy(InputIterator first, InputIterator last,
488 RandomAccessIterator result_first, RandomAccessIterator result_last, Compare comp);
489
490template <class RandomAccessIterator>
Arthur O'Dwyer4f5717b2021-02-04 18:12:52 -0500491 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000492 nth_element(RandomAccessIterator first, RandomAccessIterator nth, RandomAccessIterator last);
493
494template <class RandomAccessIterator, class Compare>
Arthur O'Dwyer4f5717b2021-02-04 18:12:52 -0500495 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000496 nth_element(RandomAccessIterator first, RandomAccessIterator nth, RandomAccessIterator last, Compare comp);
497
498template <class ForwardIterator, class T>
Marshall Clowe00916c2018-01-16 02:34:41 +0000499 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000500 lower_bound(ForwardIterator first, ForwardIterator last, const T& value);
501
502template <class ForwardIterator, class T, class Compare>
Marshall Clowe00916c2018-01-16 02:34:41 +0000503 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000504 lower_bound(ForwardIterator first, ForwardIterator last, const T& value, Compare comp);
505
506template <class ForwardIterator, class T>
Marshall Clowe00916c2018-01-16 02:34:41 +0000507 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000508 upper_bound(ForwardIterator first, ForwardIterator last, const T& value);
509
510template <class ForwardIterator, class T, class Compare>
Marshall Clowe00916c2018-01-16 02:34:41 +0000511 constexpr ForwardIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000512 upper_bound(ForwardIterator first, ForwardIterator last, const T& value, Compare comp);
513
514template <class ForwardIterator, class T>
Marshall Clowe00916c2018-01-16 02:34:41 +0000515 constexpr pair<ForwardIterator, ForwardIterator> // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000516 equal_range(ForwardIterator first, ForwardIterator last, const T& value);
517
518template <class ForwardIterator, class T, class Compare>
Marshall Clowe00916c2018-01-16 02:34:41 +0000519 constexpr pair<ForwardIterator, ForwardIterator> // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000520 equal_range(ForwardIterator first, ForwardIterator last, const T& value, Compare comp);
521
522template <class ForwardIterator, class T>
Marshall Clowe00916c2018-01-16 02:34:41 +0000523 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000524 binary_search(ForwardIterator first, ForwardIterator last, const T& value);
525
526template <class ForwardIterator, class T, class Compare>
Marshall Clowc0b7f972018-01-22 23:10:40 +0000527 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000528 binary_search(ForwardIterator first, ForwardIterator last, const T& value, 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 merge(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 merge(InputIterator1 first1, InputIterator1 last1,
538 InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
539
540template <class BidirectionalIterator>
541 void
542 inplace_merge(BidirectionalIterator first, BidirectionalIterator middle, BidirectionalIterator last);
543
544template <class BidirectionalIterator, class Compare>
545 void
546 inplace_merge(BidirectionalIterator first, BidirectionalIterator middle, BidirectionalIterator last, Compare comp);
547
548template <class InputIterator1, class InputIterator2>
Marshall Clowc0b7f972018-01-22 23:10:40 +0000549 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000550 includes(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2);
551
552template <class InputIterator1, class InputIterator2, class Compare>
Marshall Clowc0b7f972018-01-22 23:10:40 +0000553 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000554 includes(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, Compare comp);
555
556template <class InputIterator1, class InputIterator2, class OutputIterator>
Arthur O'Dwyer5afc5692020-12-04 13:47:12 -0500557 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000558 set_union(InputIterator1 first1, InputIterator1 last1,
559 InputIterator2 first2, InputIterator2 last2, OutputIterator result);
560
561template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
Arthur O'Dwyer5afc5692020-12-04 13:47:12 -0500562 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000563 set_union(InputIterator1 first1, InputIterator1 last1,
564 InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
565
566template <class InputIterator1, class InputIterator2, class OutputIterator>
Marshall Clowc0b7f972018-01-22 23:10:40 +0000567 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000568 set_intersection(InputIterator1 first1, InputIterator1 last1,
569 InputIterator2 first2, InputIterator2 last2, OutputIterator result);
570
571template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
Marshall Clowc0b7f972018-01-22 23:10:40 +0000572 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000573 set_intersection(InputIterator1 first1, InputIterator1 last1,
574 InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
575
576template <class InputIterator1, class InputIterator2, class OutputIterator>
Arthur O'Dwyer5afc5692020-12-04 13:47:12 -0500577 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000578 set_difference(InputIterator1 first1, InputIterator1 last1,
579 InputIterator2 first2, InputIterator2 last2, OutputIterator result);
580
581template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
Arthur O'Dwyer5afc5692020-12-04 13:47:12 -0500582 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000583 set_difference(InputIterator1 first1, InputIterator1 last1,
584 InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
585
586template <class InputIterator1, class InputIterator2, class OutputIterator>
Arthur O'Dwyer5afc5692020-12-04 13:47:12 -0500587 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000588 set_symmetric_difference(InputIterator1 first1, InputIterator1 last1,
589 InputIterator2 first2, InputIterator2 last2, OutputIterator result);
590
591template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
Arthur O'Dwyer5afc5692020-12-04 13:47:12 -0500592 constexpr OutputIterator // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000593 set_symmetric_difference(InputIterator1 first1, InputIterator1 last1,
594 InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
595
596template <class RandomAccessIterator>
Arthur O'Dwyer2dfea5d2020-12-17 00:26:18 -0500597 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000598 push_heap(RandomAccessIterator first, RandomAccessIterator last);
599
600template <class RandomAccessIterator, class Compare>
Arthur O'Dwyer2dfea5d2020-12-17 00:26:18 -0500601 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000602 push_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
603
604template <class RandomAccessIterator>
Arthur O'Dwyer2dfea5d2020-12-17 00:26:18 -0500605 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000606 pop_heap(RandomAccessIterator first, RandomAccessIterator last);
607
608template <class RandomAccessIterator, class Compare>
Arthur O'Dwyer2dfea5d2020-12-17 00:26:18 -0500609 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000610 pop_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
611
612template <class RandomAccessIterator>
Arthur O'Dwyer2dfea5d2020-12-17 00:26:18 -0500613 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000614 make_heap(RandomAccessIterator first, RandomAccessIterator last);
615
616template <class RandomAccessIterator, class Compare>
Arthur O'Dwyer2dfea5d2020-12-17 00:26:18 -0500617 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000618 make_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
619
620template <class RandomAccessIterator>
Arthur O'Dwyer2dfea5d2020-12-17 00:26:18 -0500621 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000622 sort_heap(RandomAccessIterator first, RandomAccessIterator last);
623
624template <class RandomAccessIterator, class Compare>
Arthur O'Dwyer2dfea5d2020-12-17 00:26:18 -0500625 constexpr void // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000626 sort_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
627
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000628template <class RandomAccessIterator>
Marshall Clow96d050a2018-01-15 16:16:32 +0000629 constexpr bool // constexpr in C++20
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000630 is_heap(RandomAccessIterator first, RandomAccessiterator last);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000631
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000632template <class RandomAccessIterator, class Compare>
Marshall Clow96d050a2018-01-15 16:16:32 +0000633 constexpr bool // constexpr in C++20
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000634 is_heap(RandomAccessIterator first, RandomAccessiterator last, Compare comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000635
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000636template <class RandomAccessIterator>
Marshall Clow96d050a2018-01-15 16:16:32 +0000637 constexpr RandomAccessIterator // constexpr in C++20
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000638 is_heap_until(RandomAccessIterator first, RandomAccessiterator last);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000639
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000640template <class RandomAccessIterator, class Compare>
Marshall Clow96d050a2018-01-15 16:16:32 +0000641 constexpr RandomAccessIterator // constexpr in C++20
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000642 is_heap_until(RandomAccessIterator first, RandomAccessiterator last, Compare comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000643
Howard Hinnantb120e7a2010-08-21 20:10:01 +0000644template <class ForwardIterator>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500645 constexpr ForwardIterator // constexpr in C++14
646 min_element(ForwardIterator first, ForwardIterator last);
Howard Hinnantb120e7a2010-08-21 20:10:01 +0000647
648template <class ForwardIterator, class Compare>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500649 constexpr ForwardIterator // constexpr in C++14
650 min_element(ForwardIterator first, ForwardIterator last, Compare comp);
Howard Hinnantb120e7a2010-08-21 20:10:01 +0000651
Howard Hinnantc51e1022010-05-11 19:42:16 +0000652template <class T>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500653 constexpr const T& // constexpr in C++14
654 min(const T& a, const T& b);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000655
656template <class T, class Compare>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500657 constexpr const T& // constexpr in C++14
658 min(const T& a, const T& b, Compare comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000659
Howard Hinnantb120e7a2010-08-21 20:10:01 +0000660template<class T>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500661 constexpr T // constexpr in C++14
662 min(initializer_list<T> t);
Howard Hinnantb120e7a2010-08-21 20:10:01 +0000663
664template<class T, class Compare>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500665 constexpr T // constexpr in C++14
666 min(initializer_list<T> t, Compare comp);
Howard Hinnantb120e7a2010-08-21 20:10:01 +0000667
Marshall Clow3e18d0e2016-03-07 22:43:49 +0000668template<class T>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500669 constexpr const T& clamp(const T& v, const T& lo, const T& hi); // C++17
Marshall Clow3e18d0e2016-03-07 22:43:49 +0000670
671template<class T, class Compare>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500672 constexpr const T& clamp(const T& v, const T& lo, const T& hi, Compare comp); // C++17
Marshall Clow3e18d0e2016-03-07 22:43:49 +0000673
Howard Hinnantb120e7a2010-08-21 20:10:01 +0000674template <class ForwardIterator>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500675 constexpr ForwardIterator // constexpr in C++14
676 max_element(ForwardIterator first, ForwardIterator last);
Howard Hinnantb120e7a2010-08-21 20:10:01 +0000677
678template <class ForwardIterator, class Compare>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500679 constexpr ForwardIterator // constexpr in C++14
680 max_element(ForwardIterator first, ForwardIterator last, Compare comp);
Howard Hinnantb120e7a2010-08-21 20:10:01 +0000681
Howard Hinnantc51e1022010-05-11 19:42:16 +0000682template <class T>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500683 constexpr const T& // constexpr in C++14
684 max(const T& a, const T& b);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000685
686template <class T, class Compare>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500687 constexpr const T& // constexpr in C++14
688 max(const T& a, const T& b, Compare comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000689
Howard Hinnantb120e7a2010-08-21 20:10:01 +0000690template<class T>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500691 constexpr T // constexpr in C++14
692 max(initializer_list<T> t);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000693
Howard Hinnantb120e7a2010-08-21 20:10:01 +0000694template<class T, class Compare>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500695 constexpr T // constexpr in C++14
696 max(initializer_list<T> t, Compare comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000697
Howard Hinnantb120e7a2010-08-21 20:10:01 +0000698template<class ForwardIterator>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500699 constexpr pair<ForwardIterator, ForwardIterator> // constexpr in C++14
700 minmax_element(ForwardIterator first, ForwardIterator last);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000701
Howard Hinnantb120e7a2010-08-21 20:10:01 +0000702template<class ForwardIterator, class Compare>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500703 constexpr pair<ForwardIterator, ForwardIterator> // constexpr in C++14
704 minmax_element(ForwardIterator first, ForwardIterator last, Compare comp);
Howard Hinnantb120e7a2010-08-21 20:10:01 +0000705
706template<class T>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500707 constexpr pair<const T&, const T&> // constexpr in C++14
708 minmax(const T& a, const T& b);
Howard Hinnantb120e7a2010-08-21 20:10:01 +0000709
710template<class T, class Compare>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500711 constexpr pair<const T&, const T&> // constexpr in C++14
712 minmax(const T& a, const T& b, Compare comp);
Howard Hinnantb120e7a2010-08-21 20:10:01 +0000713
714template<class T>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500715 constexpr pair<T, T> // constexpr in C++14
716 minmax(initializer_list<T> t);
Howard Hinnantb120e7a2010-08-21 20:10:01 +0000717
718template<class T, class Compare>
Arthur O'Dwyer20353a72020-12-02 20:02:18 -0500719 constexpr pair<T, T> // constexpr in C++14
720 minmax(initializer_list<T> t, Compare comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000721
722template <class InputIterator1, class InputIterator2>
Marshall Clow5492c8a2018-01-22 20:44:33 +0000723 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000724 lexicographical_compare(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2);
725
726template <class InputIterator1, class InputIterator2, class Compare>
Marshall Clow5492c8a2018-01-22 20:44:33 +0000727 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000728 lexicographical_compare(InputIterator1 first1, InputIterator1 last1,
729 InputIterator2 first2, InputIterator2 last2, Compare comp);
730
731template <class BidirectionalIterator>
Arthur O'Dwyere50e7472020-12-17 00:01:08 -0500732 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000733 next_permutation(BidirectionalIterator first, BidirectionalIterator last);
734
735template <class BidirectionalIterator, class Compare>
Arthur O'Dwyere50e7472020-12-17 00:01:08 -0500736 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000737 next_permutation(BidirectionalIterator first, BidirectionalIterator last, Compare comp);
738
739template <class BidirectionalIterator>
Arthur O'Dwyere50e7472020-12-17 00:01:08 -0500740 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000741 prev_permutation(BidirectionalIterator first, BidirectionalIterator last);
742
743template <class BidirectionalIterator, class Compare>
Arthur O'Dwyere50e7472020-12-17 00:01:08 -0500744 constexpr bool // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000745 prev_permutation(BidirectionalIterator first, BidirectionalIterator last, Compare comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000746} // std
747
748*/
749
Louis Dionneb4fce352022-03-25 12:55:36 -0400750#include <__assert> // all public C++ headers provide the assertion handler
Arthur O'Dwyer3693d7a2022-02-04 13:09:30 -0500751#include <__bits>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000752#include <__config>
Louis Dionnea60dd872021-06-17 11:30:11 -0400753#include <__debug>
Howard Hinnant60e5cf42012-07-26 17:09:09 +0000754#include <cstddef>
Arthur O'Dwyeref181602021-05-19 11:57:04 -0400755#include <cstring>
756#include <functional>
757#include <initializer_list>
758#include <iterator>
759#include <memory>
760#include <type_traits>
Marshall Clow0a1e7502018-09-12 19:41:40 +0000761#include <version>
Howard Hinnantea382952013-08-14 18:00:20 +0000762
Louis Dionnea60dd872021-06-17 11:30:11 -0400763#include <__algorithm/adjacent_find.h>
764#include <__algorithm/all_of.h>
765#include <__algorithm/any_of.h>
766#include <__algorithm/binary_search.h>
767#include <__algorithm/clamp.h>
768#include <__algorithm/comp.h>
769#include <__algorithm/comp_ref_type.h>
770#include <__algorithm/copy.h>
771#include <__algorithm/copy_backward.h>
772#include <__algorithm/copy_if.h>
773#include <__algorithm/copy_n.h>
774#include <__algorithm/count.h>
775#include <__algorithm/count_if.h>
776#include <__algorithm/equal.h>
777#include <__algorithm/equal_range.h>
Louis Dionnea60dd872021-06-17 11:30:11 -0400778#include <__algorithm/fill.h>
Arthur O'Dwyer65077c02022-01-07 09:45:05 -0500779#include <__algorithm/fill_n.h>
Louis Dionnea60dd872021-06-17 11:30:11 -0400780#include <__algorithm/find.h>
781#include <__algorithm/find_end.h>
782#include <__algorithm/find_first_of.h>
783#include <__algorithm/find_if.h>
784#include <__algorithm/find_if_not.h>
785#include <__algorithm/for_each.h>
786#include <__algorithm/for_each_n.h>
Louis Dionnea60dd872021-06-17 11:30:11 -0400787#include <__algorithm/generate.h>
Arthur O'Dwyer65077c02022-01-07 09:45:05 -0500788#include <__algorithm/generate_n.h>
Louis Dionnea60dd872021-06-17 11:30:11 -0400789#include <__algorithm/half_positive.h>
Nikolas Klauserdd5ad212022-02-21 23:07:02 +0100790#include <__algorithm/in_found_result.h>
Nikolas Klauser671b4752022-02-11 17:01:58 +0100791#include <__algorithm/in_fun_result.h>
Nikolas Klauser05e2cd82022-01-25 11:21:47 +0100792#include <__algorithm/in_in_out_result.h>
Nikolas Klauserf74be4e2022-01-14 02:55:51 +0100793#include <__algorithm/in_in_result.h>
Nikolas Klauser61ce8162022-02-03 02:17:03 +0100794#include <__algorithm/in_out_out_result.h>
Konstantin Varlamov74736812022-01-10 22:49:37 -0800795#include <__algorithm/in_out_result.h>
Louis Dionnea60dd872021-06-17 11:30:11 -0400796#include <__algorithm/includes.h>
797#include <__algorithm/inplace_merge.h>
798#include <__algorithm/is_heap.h>
799#include <__algorithm/is_heap_until.h>
800#include <__algorithm/is_partitioned.h>
801#include <__algorithm/is_permutation.h>
802#include <__algorithm/is_sorted.h>
803#include <__algorithm/is_sorted_until.h>
Christopher Di Bella41f26e82021-06-05 02:47:47 +0000804#include <__algorithm/iter_swap.h>
Louis Dionnea60dd872021-06-17 11:30:11 -0400805#include <__algorithm/lexicographical_compare.h>
806#include <__algorithm/lower_bound.h>
807#include <__algorithm/make_heap.h>
808#include <__algorithm/max.h>
809#include <__algorithm/max_element.h>
810#include <__algorithm/merge.h>
811#include <__algorithm/min.h>
812#include <__algorithm/min_element.h>
Nikolas Klauser2e263162022-02-21 22:48:36 +0100813#include <__algorithm/min_max_result.h>
Louis Dionnea60dd872021-06-17 11:30:11 -0400814#include <__algorithm/minmax.h>
815#include <__algorithm/minmax_element.h>
816#include <__algorithm/mismatch.h>
817#include <__algorithm/move.h>
818#include <__algorithm/move_backward.h>
819#include <__algorithm/next_permutation.h>
820#include <__algorithm/none_of.h>
821#include <__algorithm/nth_element.h>
822#include <__algorithm/partial_sort.h>
823#include <__algorithm/partial_sort_copy.h>
824#include <__algorithm/partition.h>
825#include <__algorithm/partition_copy.h>
826#include <__algorithm/partition_point.h>
827#include <__algorithm/pop_heap.h>
828#include <__algorithm/prev_permutation.h>
829#include <__algorithm/push_heap.h>
Nikolas Klauser37d076e2022-03-12 01:45:35 +0100830#include <__algorithm/ranges_find.h>
831#include <__algorithm/ranges_find_if.h>
832#include <__algorithm/ranges_find_if_not.h>
Nikolas Klauser573cd6f2022-04-03 09:17:01 +0200833#include <__algorithm/ranges_max.h>
Nikolas Klauserf2a69ea2022-03-07 17:01:52 +0100834#include <__algorithm/ranges_max_element.h>
Nikolas Klauser3559e452022-03-18 02:57:08 +0100835#include <__algorithm/ranges_min.h>
Nikolas Klauser0a62a172022-02-11 13:11:57 +0100836#include <__algorithm/ranges_min_element.h>
Nikolas Klauser12fc9bf2022-03-08 23:12:35 +0100837#include <__algorithm/ranges_mismatch.h>
Nikolas Klauser4ceab5f2022-02-10 13:33:03 +0100838#include <__algorithm/ranges_swap_ranges.h>
Louis Dionnea60dd872021-06-17 11:30:11 -0400839#include <__algorithm/remove.h>
840#include <__algorithm/remove_copy.h>
841#include <__algorithm/remove_copy_if.h>
842#include <__algorithm/remove_if.h>
843#include <__algorithm/replace.h>
844#include <__algorithm/replace_copy.h>
845#include <__algorithm/replace_copy_if.h>
846#include <__algorithm/replace_if.h>
847#include <__algorithm/reverse.h>
848#include <__algorithm/reverse_copy.h>
849#include <__algorithm/rotate.h>
850#include <__algorithm/rotate_copy.h>
851#include <__algorithm/sample.h>
852#include <__algorithm/search.h>
853#include <__algorithm/search_n.h>
854#include <__algorithm/set_difference.h>
855#include <__algorithm/set_intersection.h>
856#include <__algorithm/set_symmetric_difference.h>
857#include <__algorithm/set_union.h>
858#include <__algorithm/shift_left.h>
859#include <__algorithm/shift_right.h>
860#include <__algorithm/shuffle.h>
861#include <__algorithm/sift_down.h>
862#include <__algorithm/sort.h>
863#include <__algorithm/sort_heap.h>
864#include <__algorithm/stable_partition.h>
865#include <__algorithm/stable_sort.h>
Christopher Di Bella41f26e82021-06-05 02:47:47 +0000866#include <__algorithm/swap_ranges.h>
Louis Dionnea60dd872021-06-17 11:30:11 -0400867#include <__algorithm/transform.h>
Louis Dionnea60dd872021-06-17 11:30:11 -0400868#include <__algorithm/unique.h>
Arthur O'Dwyer65077c02022-01-07 09:45:05 -0500869#include <__algorithm/unique_copy.h>
Louis Dionnea60dd872021-06-17 11:30:11 -0400870#include <__algorithm/unwrap_iter.h>
871#include <__algorithm/upper_bound.h>
Eric Fiselier14b6de92014-08-10 23:53:08 +0000872
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000873#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Arthur O'Dwyer6eeaa002022-02-01 20:16:40 -0500874# pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000875#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000876
Louis Dionne59d0b3c2019-08-05 18:29:14 +0000877#if defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS) && _LIBCPP_STD_VER >= 17
Louis Dionned53d8c02019-08-06 21:11:24 +0000878# include <__pstl_algorithm>
Louis Dionne59d0b3c2019-08-05 18:29:14 +0000879#endif
880
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400881#endif // _LIBCPP_ALGORITHM