algorithm 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309
  1. // -*- C++ -*-
  2. //===----------------------------------------------------------------------===//
  3. //
  4. // 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
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #ifndef _LIBCPP_ALGORITHM
  10. #define _LIBCPP_ALGORITHM
  11. /*
  12. algorithm synopsis
  13. #include <initializer_list>
  14. namespace std
  15. {
  16. namespace ranges {
  17. // [algorithms.results], algorithm result types
  18. template <class I, class F>
  19. struct in_fun_result; // since C++20
  20. template <class I1, class I2>
  21. struct in_in_result; // since C++20
  22. template <class I, class O>
  23. struct in_out_result; // since C++20
  24. template <class I1, class I2, class O>
  25. struct in_in_out_result; // since C++20
  26. template <class I, class O1, class O2>
  27. struct in_out_out_result; // since C++20
  28. template <class I1, class I2>
  29. struct min_max_result; // since C++20
  30. template <class I>
  31. struct in_found_result; // since C++20
  32. template<forward_iterator I, sentinel_for<I> S, class Proj = identity,
  33. indirect_strict_weak_order<projected<I, Proj>> Comp = ranges::less> // since C++20
  34. constexpr I min_element(I first, S last, Comp comp = {}, Proj proj = {});
  35. template<forward_range R, class Proj = identity,
  36. indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less> // since C++20
  37. constexpr borrowed_iterator_t<R> min_element(R&& r, Comp comp = {}, Proj proj = {});
  38. template<forward_iterator I, sentinel_for<I> S, class Proj = identity,
  39. indirect_strict_weak_order<projected<I, Proj>> Comp = ranges::less>
  40. constexpr I ranges::max_element(I first, S last, Comp comp = {}, Proj proj = {}); // since C++20
  41. template<forward_range R, class Proj = identity,
  42. indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less>
  43. constexpr borrowed_iterator_t<R> ranges::max_element(R&& r, Comp comp = {}, Proj proj = {}); // since C++20
  44. template<class I1, class I2>
  45. using mismatch_result = in_in_result<I1, I2>;
  46. template <input_iterator I1, sentinel_for<_I1> S1, input_iterator I2, sentinel_for<_I2> S2,
  47. class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
  48. requires indirectly_comparable<I1, I2, Pred, Proj1, Proj2>
  49. constexpr mismatch_result<_I1, _I2>
  50. mismatch()(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}) // since C++20
  51. template <input_range R1, input_range R2,
  52. class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
  53. requires indirectly_comparable<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
  54. constexpr mismatch_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>>
  55. mismatch(R1&& r1, R2&& r2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}) // since C++20
  56. requires indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T*>
  57. constexpr I find(I first, S last, const T& value, Proj proj = {}); // since C++20
  58. template<input_range R, class T, class Proj = identity>
  59. requires indirect_binary_predicate<ranges::equal_to, projected<iterator_t<R>, Proj>, const T*>
  60. constexpr borrowed_iterator_t<R>
  61. find(R&& r, const T& value, Proj proj = {}); // since C++20
  62. template<input_iterator I, sentinel_for<I> S, class Proj = identity,
  63. indirect_unary_predicate<projected<I, Proj>> Pred>
  64. constexpr I find_if(I first, S last, Pred pred, Proj proj = {}); // since C++20
  65. template<input_range R, class Proj = identity,
  66. indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
  67. constexpr borrowed_iterator_t<R>
  68. find_if(R&& r, Pred pred, Proj proj = {}); // since C++20
  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_not(I first, S last, Pred pred, Proj proj = {}); // since C++20
  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_not(R&& r, Pred pred, Proj proj = {}); // since C++20
  76. template<class T, class Proj = identity,
  77. indirect_strict_weak_order<projected<const T*, Proj>> Comp = ranges::less>
  78. constexpr const T& min(const T& a, const T& b, Comp comp = {}, Proj proj = {}); // since C++20
  79. template<copyable T, class Proj = identity,
  80. indirect_strict_weak_order<projected<const T*, Proj>> Comp = ranges::less>
  81. constexpr T min(initializer_list<T> r, Comp comp = {}, Proj proj = {}); // since C++20
  82. template<input_range R, class Proj = identity,
  83. indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less>
  84. requires indirectly_copyable_storable<iterator_t<R>, range_value_t<R>*>
  85. constexpr range_value_t<R>
  86. min(R&& r, Comp comp = {}, Proj proj = {}); // since C++20
  87. template<class T, class Proj = identity,
  88. indirect_strict_weak_order<projected<const T*, Proj>> Comp = ranges::less>
  89. constexpr const T& max(const T& a, const T& b, Comp comp = {}, Proj proj = {}); // since C++20
  90. template<copyable T, class Proj = identity,
  91. indirect_strict_weak_order<projected<const T*, Proj>> Comp = ranges::less>
  92. constexpr T max(initializer_list<T> r, Comp comp = {}, Proj proj = {}); // since C++20
  93. template<input_range R, class Proj = identity,
  94. indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less>
  95. requires indirectly_copyable_storable<iterator_t<R>, range_value_t<R>*>
  96. constexpr range_value_t<R>
  97. max(R&& r, Comp comp = {}, Proj proj = {}); // since C++20
  98. template<class I, class O>
  99. using unary_transform_result = in_out_result<I, O>; // since C++20
  100. template<class I1, class I2, class O>
  101. using binary_transform_result = in_in_out_result<I1, I2, O>; // since C++20
  102. template<input_iterator I, sentinel_for<I> S, weakly_incrementable O,
  103. copy_constructible F, class Proj = identity>
  104. requires indirectly_writable<O, indirect_result_t<F&, projected<I, Proj>>>
  105. constexpr ranges::unary_transform_result<I, O>
  106. transform(I first1, S last1, O result, F op, Proj proj = {}); // since C++20
  107. template<input_range R, weakly_incrementable O, copy_constructible F,
  108. class Proj = identity>
  109. requires indirectly_writable<O, indirect_result_t<F&, projected<iterator_t<R>, Proj>>>
  110. constexpr ranges::unary_transform_result<borrowed_iterator_t<R>, O>
  111. transform(R&& r, O result, F op, Proj proj = {}); // since C++20
  112. template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2,
  113. weakly_incrementable O, copy_constructible F, class Proj1 = identity,
  114. class Proj2 = identity>
  115. requires indirectly_writable<O, indirect_result_t<F&, projected<I1, Proj1>,
  116. projected<I2, Proj2>>>
  117. constexpr ranges::binary_transform_result<I1, I2, O>
  118. transform(I1 first1, S1 last1, I2 first2, S2 last2, O result,
  119. F binary_op, Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
  120. template<input_range R1, input_range R2, weakly_incrementable O,
  121. copy_constructible F, class Proj1 = identity, class Proj2 = identity>
  122. requires indirectly_writable<O, indirect_result_t<F&, projected<iterator_t<R1>, Proj1>,
  123. projected<iterator_t<R2>, Proj2>>>
  124. constexpr ranges::binary_transform_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>, O>
  125. transform(R1&& r1, R2&& r2, O result,
  126. F binary_op, Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
  127. template<input_iterator I, sentinel_for<I> S, class T, class Proj = identity>
  128. requires indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T*>
  129. constexpr iter_difference_t<I>
  130. count(I first, S last, const T& value, Proj proj = {}); // since C++20
  131. template<input_range R, class T, class Proj = identity>
  132. requires indirect_binary_predicate<ranges::equal_to, projected<iterator_t<R>, Proj>, const T*>
  133. constexpr range_difference_t<R>
  134. count(R&& r, const T& value, Proj proj = {}); // since C++20
  135. template<input_iterator I, sentinel_for<I> S, class Proj = identity,
  136. indirect_unary_predicate<projected<I, Proj>> Pred>
  137. constexpr iter_difference_t<I>
  138. count_if(I first, S last, Pred pred, Proj proj = {}); // since C++20
  139. template<input_range R, class Proj = identity,
  140. indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
  141. constexpr range_difference_t<R>
  142. count_if(R&& r, Pred pred, Proj proj = {}); // since C++20
  143. template<class T>
  144. using minmax_result = min_max_result<T>;
  145. template<class T, class Proj = identity,
  146. indirect_strict_weak_order<projected<const T*, Proj>> Comp = ranges::less>
  147. constexpr ranges::minmax_result<const T&>
  148. minmax(const T& a, const T& b, Comp comp = {}, Proj proj = {}); // since C++20
  149. template<copyable T, class Proj = identity,
  150. indirect_strict_weak_order<projected<const T*, Proj>> Comp = ranges::less>
  151. constexpr ranges::minmax_result<T>
  152. minmax(initializer_list<T> r, Comp comp = {}, Proj proj = {}); // since C++20
  153. template<input_range R, class Proj = identity,
  154. indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less>
  155. requires indirectly_copyable_storable<iterator_t<R>, range_value_t<R>*>
  156. constexpr ranges::minmax_result<range_value_t<R>>
  157. minmax(R&& r, Comp comp = {}, Proj proj = {}); // since C++20
  158. template<class I>
  159. using minmax_element_result = min_max_result<I>;
  160. template<forward_iterator I, sentinel_for<I> S, class Proj = identity,
  161. indirect_strict_weak_order<projected<I, Proj>> Comp = ranges::less>
  162. constexpr ranges::minmax_element_result<I>
  163. minmax_element(I first, S last, Comp comp = {}, Proj proj = {}); // since C++20
  164. template<forward_range R, class Proj = identity,
  165. indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less>
  166. constexpr ranges::minmax_element_result<borrowed_iterator_t<R>>
  167. minmax_element(R&& r, Comp comp = {}, Proj proj = {}); // since C++20
  168. template<class I, class O>
  169. using copy_result = in_out_result<I, O>; // since C++20
  170. template<class I, class O>
  171. using copy_n_result = in_out_result<I, O>; // since C++20
  172. template<class I, class O>
  173. using copy_if_result = in_out_result<I, O>; // since C++20
  174. template<class I1, class I2>
  175. using copy_backward_result = in_out_result<I1, I2>; // since C++20
  176. template<input_iterator I, sentinel_for<I> S, weakly_incrementable O>
  177. requires indirectly_copyable<I, O>
  178. constexpr ranges::copy_result<I, O> ranges::copy(I first, S last, O result); // since C++20
  179. template<input_range R, weakly_incrementable O>
  180. requires indirectly_copyable<iterator_t<R>, O>
  181. constexpr ranges::copy_result<borrowed_iterator_t<R>, O> ranges::copy(R&& r, O result); // since C++20
  182. template<input_iterator I, weakly_incrementable O>
  183. requires indirectly_copyable<I, O>
  184. constexpr ranges::copy_n_result<I, O>
  185. ranges::copy_n(I first, iter_difference_t<I> n, O result); // since C++20
  186. template<input_iterator I, sentinel_for<I> S, weakly_incrementable O, class Proj = identity,
  187. indirect_unary_predicate<projected<I, Proj>> Pred>
  188. requires indirectly_copyable<I, O>
  189. constexpr ranges::copy_if_result<I, O>
  190. ranges::copy_if(I first, S last, O result, Pred pred, Proj proj = {}); // since C++20
  191. template<input_range R, weakly_incrementable O, class Proj = identity,
  192. indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
  193. requires indirectly_copyable<iterator_t<R>, O>
  194. constexpr ranges::copy_if_result<borrowed_iterator_t<R>, O>
  195. ranges::copy_if(R&& r, O result, Pred pred, Proj proj = {}); // since C++20
  196. template<bidirectional_iterator I1, sentinel_for<I1> S1, bidirectional_iterator I2>
  197. requires indirectly_copyable<I1, I2>
  198. constexpr ranges::copy_backward_result<I1, I2>
  199. ranges::copy_backward(I1 first, S1 last, I2 result); // since C++20
  200. template<bidirectional_range R, bidirectional_iterator I>
  201. requires indirectly_copyable<iterator_t<R>, I>
  202. constexpr ranges::copy_backward_result<borrowed_iterator_t<R>, I>
  203. ranges::copy_backward(R&& r, I result); // since C++20
  204. template<class I, class F>
  205. using for_each_result = in_fun_result<I, F>; // since C++20
  206. template<input_iterator I, sentinel_for<I> S, class Proj = identity,
  207. indirectly_unary_invocable<projected<I, Proj>> Fun>
  208. constexpr ranges::for_each_result<I, Fun>
  209. ranges::for_each(I first, S last, Fun f, Proj proj = {}); // since C++20
  210. template<input_range R, class Proj = identity,
  211. indirectly_unary_invocable<projected<iterator_t<R>, Proj>> Fun>
  212. constexpr ranges::for_each_result<borrowed_iterator_t<R>, Fun>
  213. ranges::for_each(R&& r, Fun f, Proj proj = {}); // since C++20
  214. template<input_iterator I, class Proj = identity,
  215. indirectly_unary_invocable<projected<I, Proj>> Fun>
  216. constexpr ranges::for_each_n_result<I, Fun>
  217. ranges::for_each_n(I first, iter_difference_t<I> n, Fun f, Proj proj = {}); // since C++20
  218. template<input_iterator I, sentinel_for<I> S, class Proj = identity,
  219. indirect_unary_predicate<projected<I, Proj>> Pred>
  220. constexpr bool ranges::is_partitioned(I first, S last, Pred pred, Proj proj = {}); // since C++20
  221. template<input_range R, class Proj = identity,
  222. indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
  223. constexpr bool ranges::is_partitioned(R&& r, Pred pred, Proj proj = {}); // since C++20
  224. template<bidirectional_iterator I, sentinel_for<I> S>
  225. requires permutable<I>
  226. constexpr I ranges::reverse(I first, S last); // since C++20
  227. template<bidirectional_range R>
  228. requires permutable<iterator_t<R>>
  229. constexpr borrowed_iterator_t<R> ranges::reverse(R&& r); // since C++20
  230. template<random_access_iterator I, sentinel_for<I> S, class Comp = ranges::less,
  231. class Proj = identity>
  232. requires sortable<I, Comp, Proj>
  233. constexpr I
  234. sort(I first, S last, Comp comp = {}, Proj proj = {}); // since C++20
  235. template<random_access_range R, class Comp = ranges::less, class Proj = identity>
  236. requires sortable<iterator_t<R>, Comp, Proj>
  237. constexpr borrowed_iterator_t<R>
  238. sort(R&& r, Comp comp = {}, Proj proj = {}); // since C++20
  239. template<class T, output_iterator<const T&> O, sentinel_for<O> S>
  240. constexpr O ranges::fill(O first, S last, const T& value); // since C++20
  241. template<class T, output_range<const T&> R>
  242. constexpr borrowed_iterator_t<R> ranges::fill(R&& r, const T& value); // since C++20
  243. template<class T, output_iterator<const T&> O>
  244. constexpr O ranges::fill_n(O first, iter_difference_t<O> n, const T& value); // since C++20
  245. template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2,
  246. class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
  247. requires indirectly_comparable<I1, I2, Pred, Proj1, Proj2>
  248. constexpr bool ranges::equal(I1 first1, S1 last1, I2 first2, S2 last2,
  249. Pred pred = {},
  250. Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
  251. template<input_range R1, input_range R2, class Pred = ranges::equal_to,
  252. class Proj1 = identity, class Proj2 = identity>
  253. requires indirectly_comparable<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
  254. constexpr bool ranges::equal(R1&& r1, R2&& r2, Pred pred = {},
  255. Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
  256. template<input_iterator I, sentinel_for<I> S, class Proj = identity,
  257. indirect_unary_predicate<projected<I, Proj>> Pred>
  258. constexpr bool ranges::all_of(I first, S last, Pred pred, Proj proj = {}); // since C++20
  259. template<input_range R, class Proj = identity,
  260. indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
  261. constexpr bool ranges::all_of(R&& r, Pred pred, Proj proj = {}); // since C++20
  262. template<input_iterator I, sentinel_for<I> S, class Proj = identity,
  263. indirect_unary_predicate<projected<I, Proj>> Pred>
  264. constexpr bool ranges::any_of(I first, S last, Pred pred, Proj proj = {}); // since C++20
  265. template<input_range R, class Proj = identity,
  266. indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
  267. constexpr bool ranges::any_of(R&& r, Pred pred, Proj proj = {}); // since C++20
  268. template<input_iterator I, sentinel_for<I> S, class Proj = identity,
  269. indirect_unary_predicate<projected<I, Proj>> Pred>
  270. constexpr bool ranges::none_of(I first, S last, Pred pred, Proj proj = {}); // since C++20
  271. template<input_range R, class Proj = identity,
  272. indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
  273. constexpr bool ranges::none_of(R&& r, Pred pred, Proj proj = {}); // since C++20
  274. template<forward_iterator I, sentinel_for<I> S, class Proj = identity,
  275. indirect_strict_weak_order<projected<I, Proj>> Comp = ranges::less>
  276. constexpr bool ranges::is_sorted(I first, S last, Comp comp = {}, Proj proj = {}); // since C++20
  277. template<forward_range R, class Proj = identity,
  278. indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less>
  279. constexpr bool ranges::is_sorted(R&& r, Comp comp = {}, Proj proj = {}); // since C++20
  280. template<forward_iterator I, sentinel_for<I> S, class Proj = identity,
  281. indirect_strict_weak_order<projected<I, Proj>> Comp = ranges::less>
  282. constexpr I ranges::is_sorted_until(I first, S last, Comp comp = {}, Proj proj = {}); // since C++20
  283. template<forward_range R, class Proj = identity,
  284. indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less>
  285. constexpr borrowed_iterator_t<R>
  286. ranges::is_sorted_until(R&& r, Comp comp = {}, Proj proj = {}); // since C++20
  287. template<forward_iterator I, sentinel_for<I> S, class T, class Proj = identity,
  288. indirect_strict_weak_order<const T*, projected<I, Proj>> Comp = ranges::less>
  289. constexpr I upper_bound(I first, S last, const T& value, Comp comp = {}, Proj proj = {}); // since C++20
  290. template<forward_range R, class T, class Proj = identity,
  291. indirect_strict_weak_order<const T*, projected<iterator_t<R>, Proj>> Comp =
  292. ranges::less>
  293. constexpr borrowed_iterator_t<R>
  294. upper_bound(R&& r, const T& value, Comp comp = {}, Proj proj = {}); // since C++20
  295. template<forward_iterator I, sentinel_for<I> S, class T, class Proj = identity,
  296. indirect_strict_weak_order<const T*, projected<I, Proj>> Comp = ranges::less>
  297. constexpr I lower_bound(I first, S last, const T& value, Comp comp = {},
  298. Proj proj = {}); // since C++20
  299. template<forward_range R, class T, class Proj = identity,
  300. indirect_strict_weak_order<const T*, projected<iterator_t<R>, Proj>> Comp =
  301. ranges::less>
  302. constexpr borrowed_iterator_t<R>
  303. lower_bound(R&& r, const T& value, Comp comp = {}, Proj proj = {}); // since C++20
  304. template<forward_iterator I, sentinel_for<I> S, class T, class Proj = identity,
  305. indirect_strict_weak_order<const T*, projected<I, Proj>> Comp = ranges::less>
  306. constexpr bool binary_search(I first, S last, const T& value, Comp comp = {},
  307. Proj proj = {}); // since C++20
  308. template<forward_range R, class T, class Proj = identity,
  309. indirect_strict_weak_order<const T*, projected<iterator_t<R>, Proj>> Comp =
  310. ranges::less>
  311. constexpr bool binary_search(R&& r, const T& value, Comp comp = {},
  312. Proj proj = {}); // since C++20
  313. template<input_iterator I1, sentinel_for<I1> S1, forward_iterator I2, sentinel_for<I2> S2,
  314. class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
  315. requires indirectly_comparable<I1, I2, Pred, Proj1, Proj2>
  316. constexpr I1 ranges::find_first_of(I1 first1, S1 last1, I2 first2, S2 last2,
  317. Pred pred = {},
  318. Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
  319. template<input_range R1, forward_range R2,
  320. class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
  321. requires indirectly_comparable<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
  322. constexpr borrowed_iterator_t<R1>
  323. ranges::find_first_of(R1&& r1, R2&& r2,
  324. Pred pred = {},
  325. Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
  326. template<forward_iterator I, sentinel_for<I> S, class Proj = identity,
  327. indirect_binary_predicate<projected<I, Proj>,
  328. projected<I, Proj>> Pred = ranges::equal_to>
  329. constexpr I ranges::adjacent_find(I first, S last, Pred pred = {}, Proj proj = {}); // since C+20
  330. template<forward_range R, class Proj = identity,
  331. indirect_binary_predicate<projected<iterator_t<R>, Proj>,
  332. projected<iterator_t<R>, Proj>> Pred = ranges::equal_to>
  333. constexpr borrowed_iterator_t<R> ranges::adjacent_find(R&& r, Pred pred = {}, Proj proj = {}); // since C++20
  334. template<input_iterator I, sentinel_for<I> S, class T1, class T2, class Proj = identity>
  335. requires indirectly_writable<I, const T2&> &&
  336. indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T1*>
  337. constexpr I
  338. ranges::replace(I first, S last, const T1& old_value, const T2& new_value, Proj proj = {}); // since C++20
  339. template<input_range R, class T1, class T2, class Proj = identity>
  340. requires indirectly_writable<iterator_t<R>, const T2&> &&
  341. indirect_binary_predicate<ranges::equal_to, projected<iterator_t<R>, Proj>, const T1*>
  342. constexpr borrowed_iterator_t<R>
  343. ranges::replace(R&& r, const T1& old_value, const T2& new_value, Proj proj = {}); // since C++20
  344. template<input_iterator I, sentinel_for<I> S, class T, class Proj = identity,
  345. indirect_unary_predicate<projected<I, Proj>> Pred>
  346. requires indirectly_writable<I, const T&>
  347. constexpr I ranges::replace_if(I first, S last, Pred pred, const T& new_value, Proj proj = {}); // since C++20
  348. template<input_range R, class T, class Proj = identity,
  349. indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
  350. requires indirectly_writable<iterator_t<R>, const T&>
  351. constexpr borrowed_iterator_t<R>
  352. ranges::replace_if(R&& r, Pred pred, const T& new_value, Proj proj = {}); // since C++20
  353. template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2,
  354. class Proj1 = identity, class Proj2 = identity,
  355. indirect_strict_weak_order<projected<I1, Proj1>,
  356. projected<I2, Proj2>> Comp = ranges::less>
  357. constexpr bool
  358. ranges::lexicographical_compare(I1 first1, S1 last1, I2 first2, S2 last2,
  359. Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
  360. template<input_range R1, input_range R2, class Proj1 = identity,
  361. class Proj2 = identity,
  362. indirect_strict_weak_order<projected<iterator_t<R1>, Proj1>,
  363. projected<iterator_t<R2>, Proj2>> Comp = ranges::less>
  364. constexpr bool
  365. ranges::lexicographical_compare(R1&& r1, R2&& r2, Comp comp = {},
  366. Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20
  367. template<bidirectional_iterator I1, sentinel_for<I1> S1, bidirectional_iterator I2>
  368. requires indirectly_movable<I1, I2>
  369. constexpr ranges::move_backward_result<I1, I2>
  370. ranges::move_backward(I1 first, S1 last, I2 result); // since C++20
  371. template<bidirectional_range R, bidirectional_iterator I>
  372. requires indirectly_movable<iterator_t<R>, I>
  373. constexpr ranges::move_backward_result<borrowed_iterator_t<R>, I>
  374. ranges::move_backward(R&& r, I result); // since C++20
  375. template<input_iterator I, sentinel_for<I> S, weakly_incrementable O>
  376. requires indirectly_movable<I, O>
  377. constexpr ranges::move_result<I, O>
  378. ranges::move(I first, S last, O result); // since C++20
  379. template<input_range R, weakly_incrementable O>
  380. requires indirectly_movable<iterator_t<R>, O>
  381. constexpr ranges::move_result<borrowed_iterator_t<R>, O>
  382. ranges::move(R&& r, O result); // since C++20
  383. }
  384. constexpr bool // constexpr in C++20
  385. all_of(InputIterator first, InputIterator last, Predicate pred);
  386. template <class InputIterator, class Predicate>
  387. constexpr bool // constexpr in C++20
  388. any_of(InputIterator first, InputIterator last, Predicate pred);
  389. template <class InputIterator, class Predicate>
  390. constexpr bool // constexpr in C++20
  391. none_of(InputIterator first, InputIterator last, Predicate pred);
  392. template <class InputIterator, class Function>
  393. constexpr Function // constexpr in C++20
  394. for_each(InputIterator first, InputIterator last, Function f);
  395. template<class InputIterator, class Size, class Function>
  396. constexpr InputIterator // constexpr in C++20
  397. for_each_n(InputIterator first, Size n, Function f); // C++17
  398. template <class InputIterator, class T>
  399. constexpr InputIterator // constexpr in C++20
  400. find(InputIterator first, InputIterator last, const T& value);
  401. template <class InputIterator, class Predicate>
  402. constexpr InputIterator // constexpr in C++20
  403. find_if(InputIterator first, InputIterator last, Predicate pred);
  404. template<class InputIterator, class Predicate>
  405. constexpr InputIterator // constexpr in C++20
  406. find_if_not(InputIterator first, InputIterator last, Predicate pred);
  407. template <class ForwardIterator1, class ForwardIterator2>
  408. constexpr ForwardIterator1 // constexpr in C++20
  409. find_end(ForwardIterator1 first1, ForwardIterator1 last1,
  410. ForwardIterator2 first2, ForwardIterator2 last2);
  411. template <class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
  412. constexpr ForwardIterator1 // constexpr in C++20
  413. find_end(ForwardIterator1 first1, ForwardIterator1 last1,
  414. ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred);
  415. template <class ForwardIterator1, class ForwardIterator2>
  416. constexpr ForwardIterator1 // constexpr in C++20
  417. find_first_of(ForwardIterator1 first1, ForwardIterator1 last1,
  418. ForwardIterator2 first2, ForwardIterator2 last2);
  419. template <class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
  420. constexpr ForwardIterator1 // constexpr in C++20
  421. find_first_of(ForwardIterator1 first1, ForwardIterator1 last1,
  422. ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred);
  423. template <class ForwardIterator>
  424. constexpr ForwardIterator // constexpr in C++20
  425. adjacent_find(ForwardIterator first, ForwardIterator last);
  426. template <class ForwardIterator, class BinaryPredicate>
  427. constexpr ForwardIterator // constexpr in C++20
  428. adjacent_find(ForwardIterator first, ForwardIterator last, BinaryPredicate pred);
  429. template <class InputIterator, class T>
  430. constexpr typename iterator_traits<InputIterator>::difference_type // constexpr in C++20
  431. count(InputIterator first, InputIterator last, const T& value);
  432. template <class InputIterator, class Predicate>
  433. constexpr typename iterator_traits<InputIterator>::difference_type // constexpr in C++20
  434. count_if(InputIterator first, InputIterator last, Predicate pred);
  435. template <class InputIterator1, class InputIterator2>
  436. constexpr pair<InputIterator1, InputIterator2> // constexpr in C++20
  437. mismatch(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2);
  438. template <class InputIterator1, class InputIterator2>
  439. constexpr pair<InputIterator1, InputIterator2> // constexpr in C++20
  440. mismatch(InputIterator1 first1, InputIterator1 last1,
  441. InputIterator2 first2, InputIterator2 last2); // **C++14**
  442. template <class InputIterator1, class InputIterator2, class BinaryPredicate>
  443. constexpr pair<InputIterator1, InputIterator2> // constexpr in C++20
  444. mismatch(InputIterator1 first1, InputIterator1 last1,
  445. InputIterator2 first2, BinaryPredicate pred);
  446. template <class InputIterator1, class InputIterator2, class BinaryPredicate>
  447. constexpr pair<InputIterator1, InputIterator2> // constexpr in C++20
  448. mismatch(InputIterator1 first1, InputIterator1 last1,
  449. InputIterator2 first2, InputIterator2 last2,
  450. BinaryPredicate pred); // **C++14**
  451. template <class InputIterator1, class InputIterator2>
  452. constexpr bool // constexpr in C++20
  453. equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2);
  454. template <class InputIterator1, class InputIterator2>
  455. constexpr bool // constexpr in C++20
  456. equal(InputIterator1 first1, InputIterator1 last1,
  457. InputIterator2 first2, InputIterator2 last2); // **C++14**
  458. template <class InputIterator1, class InputIterator2, class BinaryPredicate>
  459. constexpr bool // constexpr in C++20
  460. equal(InputIterator1 first1, InputIterator1 last1,
  461. InputIterator2 first2, BinaryPredicate pred);
  462. template <class InputIterator1, class InputIterator2, class BinaryPredicate>
  463. constexpr bool // constexpr in C++20
  464. equal(InputIterator1 first1, InputIterator1 last1,
  465. InputIterator2 first2, InputIterator2 last2,
  466. BinaryPredicate pred); // **C++14**
  467. template<class ForwardIterator1, class ForwardIterator2>
  468. constexpr bool // constexpr in C++20
  469. is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
  470. ForwardIterator2 first2);
  471. template<class ForwardIterator1, class ForwardIterator2>
  472. constexpr bool // constexpr in C++20
  473. is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
  474. ForwardIterator2 first2, ForwardIterator2 last2); // **C++14**
  475. template<class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
  476. constexpr bool // constexpr in C++20
  477. is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
  478. ForwardIterator2 first2, BinaryPredicate pred);
  479. template<class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
  480. constexpr bool // constexpr in C++20
  481. is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
  482. ForwardIterator2 first2, ForwardIterator2 last2,
  483. BinaryPredicate pred); // **C++14**
  484. template <class ForwardIterator1, class ForwardIterator2>
  485. constexpr ForwardIterator1 // constexpr in C++20
  486. search(ForwardIterator1 first1, ForwardIterator1 last1,
  487. ForwardIterator2 first2, ForwardIterator2 last2);
  488. template <class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
  489. constexpr ForwardIterator1 // constexpr in C++20
  490. search(ForwardIterator1 first1, ForwardIterator1 last1,
  491. ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred);
  492. template <class ForwardIterator, class Size, class T>
  493. constexpr ForwardIterator // constexpr in C++20
  494. search_n(ForwardIterator first, ForwardIterator last, Size count, const T& value);
  495. template <class ForwardIterator, class Size, class T, class BinaryPredicate>
  496. constexpr ForwardIterator // constexpr in C++20
  497. search_n(ForwardIterator first, ForwardIterator last,
  498. Size count, const T& value, BinaryPredicate pred);
  499. template <class InputIterator, class OutputIterator>
  500. constexpr OutputIterator // constexpr in C++20
  501. copy(InputIterator first, InputIterator last, OutputIterator result);
  502. template<class InputIterator, class OutputIterator, class Predicate>
  503. constexpr OutputIterator // constexpr in C++20
  504. copy_if(InputIterator first, InputIterator last,
  505. OutputIterator result, Predicate pred);
  506. template<class InputIterator, class Size, class OutputIterator>
  507. constexpr OutputIterator // constexpr in C++20
  508. copy_n(InputIterator first, Size n, OutputIterator result);
  509. template <class BidirectionalIterator1, class BidirectionalIterator2>
  510. constexpr BidirectionalIterator2 // constexpr in C++20
  511. copy_backward(BidirectionalIterator1 first, BidirectionalIterator1 last,
  512. BidirectionalIterator2 result);
  513. // [alg.move], move
  514. template<class InputIterator, class OutputIterator>
  515. constexpr OutputIterator move(InputIterator first, InputIterator last,
  516. OutputIterator result);
  517. template<class BidirectionalIterator1, class BidirectionalIterator2>
  518. constexpr BidirectionalIterator2
  519. move_backward(BidirectionalIterator1 first, BidirectionalIterator1 last,
  520. BidirectionalIterator2 result);
  521. template <class ForwardIterator1, class ForwardIterator2>
  522. constexpr ForwardIterator2 // constexpr in C++20
  523. swap_ranges(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2);
  524. namespace ranges {
  525. template<class I1, class I2>
  526. using swap_ranges_result = in_in_result<I1, I2>;
  527. template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2>
  528. requires indirectly_swappable<I1, I2>
  529. constexpr ranges::swap_ranges_result<I1, I2>
  530. swap_ranges(I1 first1, S1 last1, I2 first2, S2 last2);
  531. template<input_range R1, input_range R2>
  532. requires indirectly_swappable<iterator_t<R1>, iterator_t<R2>>
  533. constexpr ranges::swap_ranges_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>>
  534. swap_ranges(R1&& r1, R2&& r2);
  535. }
  536. template <class ForwardIterator1, class ForwardIterator2>
  537. constexpr void // constexpr in C++20
  538. iter_swap(ForwardIterator1 a, ForwardIterator2 b);
  539. template <class InputIterator, class OutputIterator, class UnaryOperation>
  540. constexpr OutputIterator // constexpr in C++20
  541. transform(InputIterator first, InputIterator last, OutputIterator result, UnaryOperation op);
  542. template <class InputIterator1, class InputIterator2, class OutputIterator, class BinaryOperation>
  543. constexpr OutputIterator // constexpr in C++20
  544. transform(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2,
  545. OutputIterator result, BinaryOperation binary_op);
  546. template <class ForwardIterator, class T>
  547. constexpr void // constexpr in C++20
  548. replace(ForwardIterator first, ForwardIterator last, const T& old_value, const T& new_value);
  549. template <class ForwardIterator, class Predicate, class T>
  550. constexpr void // constexpr in C++20
  551. replace_if(ForwardIterator first, ForwardIterator last, Predicate pred, const T& new_value);
  552. template <class InputIterator, class OutputIterator, class T>
  553. constexpr OutputIterator // constexpr in C++20
  554. replace_copy(InputIterator first, InputIterator last, OutputIterator result,
  555. const T& old_value, const T& new_value);
  556. template <class InputIterator, class OutputIterator, class Predicate, class T>
  557. constexpr OutputIterator // constexpr in C++20
  558. replace_copy_if(InputIterator first, InputIterator last, OutputIterator result, Predicate pred, const T& new_value);
  559. template <class ForwardIterator, class T>
  560. constexpr void // constexpr in C++20
  561. fill(ForwardIterator first, ForwardIterator last, const T& value);
  562. template <class OutputIterator, class Size, class T>
  563. constexpr OutputIterator // constexpr in C++20
  564. fill_n(OutputIterator first, Size n, const T& value);
  565. template <class ForwardIterator, class Generator>
  566. constexpr void // constexpr in C++20
  567. generate(ForwardIterator first, ForwardIterator last, Generator gen);
  568. template <class OutputIterator, class Size, class Generator>
  569. constexpr OutputIterator // constexpr in C++20
  570. generate_n(OutputIterator first, Size n, Generator gen);
  571. template <class ForwardIterator, class T>
  572. constexpr ForwardIterator // constexpr in C++20
  573. remove(ForwardIterator first, ForwardIterator last, const T& value);
  574. template <class ForwardIterator, class Predicate>
  575. constexpr ForwardIterator // constexpr in C++20
  576. remove_if(ForwardIterator first, ForwardIterator last, Predicate pred);
  577. template <class InputIterator, class OutputIterator, class T>
  578. constexpr OutputIterator // constexpr in C++20
  579. remove_copy(InputIterator first, InputIterator last, OutputIterator result, const T& value);
  580. template <class InputIterator, class OutputIterator, class Predicate>
  581. constexpr OutputIterator // constexpr in C++20
  582. remove_copy_if(InputIterator first, InputIterator last, OutputIterator result, Predicate pred);
  583. template <class ForwardIterator>
  584. constexpr ForwardIterator // constexpr in C++20
  585. unique(ForwardIterator first, ForwardIterator last);
  586. template <class ForwardIterator, class BinaryPredicate>
  587. constexpr ForwardIterator // constexpr in C++20
  588. unique(ForwardIterator first, ForwardIterator last, BinaryPredicate pred);
  589. template <class InputIterator, class OutputIterator>
  590. constexpr OutputIterator // constexpr in C++20
  591. unique_copy(InputIterator first, InputIterator last, OutputIterator result);
  592. template <class InputIterator, class OutputIterator, class BinaryPredicate>
  593. constexpr OutputIterator // constexpr in C++20
  594. unique_copy(InputIterator first, InputIterator last, OutputIterator result, BinaryPredicate pred);
  595. template <class BidirectionalIterator>
  596. constexpr void // constexpr in C++20
  597. reverse(BidirectionalIterator first, BidirectionalIterator last);
  598. template <class BidirectionalIterator, class OutputIterator>
  599. constexpr OutputIterator // constexpr in C++20
  600. reverse_copy(BidirectionalIterator first, BidirectionalIterator last, OutputIterator result);
  601. template <class ForwardIterator>
  602. constexpr ForwardIterator // constexpr in C++20
  603. rotate(ForwardIterator first, ForwardIterator middle, ForwardIterator last);
  604. template <class ForwardIterator, class OutputIterator>
  605. constexpr OutputIterator // constexpr in C++20
  606. rotate_copy(ForwardIterator first, ForwardIterator middle, ForwardIterator last, OutputIterator result);
  607. template <class RandomAccessIterator>
  608. void
  609. random_shuffle(RandomAccessIterator first, RandomAccessIterator last); // deprecated in C++14, removed in C++17
  610. template <class RandomAccessIterator, class RandomNumberGenerator>
  611. void
  612. random_shuffle(RandomAccessIterator first, RandomAccessIterator last,
  613. RandomNumberGenerator& rand); // deprecated in C++14, removed in C++17
  614. template<class PopulationIterator, class SampleIterator,
  615. class Distance, class UniformRandomBitGenerator>
  616. SampleIterator sample(PopulationIterator first, PopulationIterator last,
  617. SampleIterator out, Distance n,
  618. UniformRandomBitGenerator&& g); // C++17
  619. template<class RandomAccessIterator, class UniformRandomNumberGenerator>
  620. void shuffle(RandomAccessIterator first, RandomAccessIterator last,
  621. UniformRandomNumberGenerator&& g);
  622. template<class ForwardIterator>
  623. constexpr ForwardIterator
  624. shift_left(ForwardIterator first, ForwardIterator last,
  625. typename iterator_traits<ForwardIterator>::difference_type n); // C++20
  626. template<class ForwardIterator>
  627. constexpr ForwardIterator
  628. shift_right(ForwardIterator first, ForwardIterator last,
  629. typename iterator_traits<ForwardIterator>::difference_type n); // C++20
  630. template <class InputIterator, class Predicate>
  631. constexpr bool // constexpr in C++20
  632. is_partitioned(InputIterator first, InputIterator last, Predicate pred);
  633. template <class ForwardIterator, class Predicate>
  634. constexpr ForwardIterator // constexpr in C++20
  635. partition(ForwardIterator first, ForwardIterator last, Predicate pred);
  636. template <class InputIterator, class OutputIterator1,
  637. class OutputIterator2, class Predicate>
  638. constexpr pair<OutputIterator1, OutputIterator2> // constexpr in C++20
  639. partition_copy(InputIterator first, InputIterator last,
  640. OutputIterator1 out_true, OutputIterator2 out_false,
  641. Predicate pred);
  642. template <class ForwardIterator, class Predicate>
  643. ForwardIterator
  644. stable_partition(ForwardIterator first, ForwardIterator last, Predicate pred);
  645. template<class ForwardIterator, class Predicate>
  646. constexpr ForwardIterator // constexpr in C++20
  647. partition_point(ForwardIterator first, ForwardIterator last, Predicate pred);
  648. template <class ForwardIterator>
  649. constexpr bool // constexpr in C++20
  650. is_sorted(ForwardIterator first, ForwardIterator last);
  651. template <class ForwardIterator, class Compare>
  652. constexpr bool // constexpr in C++20
  653. is_sorted(ForwardIterator first, ForwardIterator last, Compare comp);
  654. template<class ForwardIterator>
  655. constexpr ForwardIterator // constexpr in C++20
  656. is_sorted_until(ForwardIterator first, ForwardIterator last);
  657. template <class ForwardIterator, class Compare>
  658. constexpr ForwardIterator // constexpr in C++20
  659. is_sorted_until(ForwardIterator first, ForwardIterator last, Compare comp);
  660. template <class RandomAccessIterator>
  661. constexpr void // constexpr in C++20
  662. sort(RandomAccessIterator first, RandomAccessIterator last);
  663. template <class RandomAccessIterator, class Compare>
  664. constexpr void // constexpr in C++20
  665. sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
  666. template <class RandomAccessIterator>
  667. void
  668. stable_sort(RandomAccessIterator first, RandomAccessIterator last);
  669. template <class RandomAccessIterator, class Compare>
  670. void
  671. stable_sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
  672. template <class RandomAccessIterator>
  673. constexpr void // constexpr in C++20
  674. partial_sort(RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last);
  675. template <class RandomAccessIterator, class Compare>
  676. constexpr void // constexpr in C++20
  677. partial_sort(RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last, Compare comp);
  678. template <class InputIterator, class RandomAccessIterator>
  679. constexpr RandomAccessIterator // constexpr in C++20
  680. partial_sort_copy(InputIterator first, InputIterator last,
  681. RandomAccessIterator result_first, RandomAccessIterator result_last);
  682. template <class InputIterator, class RandomAccessIterator, class Compare>
  683. constexpr RandomAccessIterator // constexpr in C++20
  684. partial_sort_copy(InputIterator first, InputIterator last,
  685. RandomAccessIterator result_first, RandomAccessIterator result_last, Compare comp);
  686. template <class RandomAccessIterator>
  687. constexpr void // constexpr in C++20
  688. nth_element(RandomAccessIterator first, RandomAccessIterator nth, RandomAccessIterator last);
  689. template <class RandomAccessIterator, class Compare>
  690. constexpr void // constexpr in C++20
  691. nth_element(RandomAccessIterator first, RandomAccessIterator nth, RandomAccessIterator last, Compare comp);
  692. template <class ForwardIterator, class T>
  693. constexpr ForwardIterator // constexpr in C++20
  694. lower_bound(ForwardIterator first, ForwardIterator last, const T& value);
  695. template <class ForwardIterator, class T, class Compare>
  696. constexpr ForwardIterator // constexpr in C++20
  697. lower_bound(ForwardIterator first, ForwardIterator last, const T& value, Compare comp);
  698. template <class ForwardIterator, class T>
  699. constexpr ForwardIterator // constexpr in C++20
  700. upper_bound(ForwardIterator first, ForwardIterator last, const T& value);
  701. template <class ForwardIterator, class T, class Compare>
  702. constexpr ForwardIterator // constexpr in C++20
  703. upper_bound(ForwardIterator first, ForwardIterator last, const T& value, Compare comp);
  704. template <class ForwardIterator, class T>
  705. constexpr pair<ForwardIterator, ForwardIterator> // constexpr in C++20
  706. equal_range(ForwardIterator first, ForwardIterator last, const T& value);
  707. template <class ForwardIterator, class T, class Compare>
  708. constexpr pair<ForwardIterator, ForwardIterator> // constexpr in C++20
  709. equal_range(ForwardIterator first, ForwardIterator last, const T& value, Compare comp);
  710. template <class ForwardIterator, class T>
  711. constexpr bool // constexpr in C++20
  712. binary_search(ForwardIterator first, ForwardIterator last, const T& value);
  713. template <class ForwardIterator, class T, class Compare>
  714. constexpr bool // constexpr in C++20
  715. binary_search(ForwardIterator first, ForwardIterator last, const T& value, Compare comp);
  716. template <class InputIterator1, class InputIterator2, class OutputIterator>
  717. constexpr OutputIterator // constexpr in C++20
  718. merge(InputIterator1 first1, InputIterator1 last1,
  719. InputIterator2 first2, InputIterator2 last2, OutputIterator result);
  720. template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
  721. constexpr OutputIterator // constexpr in C++20
  722. merge(InputIterator1 first1, InputIterator1 last1,
  723. InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
  724. template <class BidirectionalIterator>
  725. void
  726. inplace_merge(BidirectionalIterator first, BidirectionalIterator middle, BidirectionalIterator last);
  727. template <class BidirectionalIterator, class Compare>
  728. void
  729. inplace_merge(BidirectionalIterator first, BidirectionalIterator middle, BidirectionalIterator last, Compare comp);
  730. template <class InputIterator1, class InputIterator2>
  731. constexpr bool // constexpr in C++20
  732. includes(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2);
  733. template <class InputIterator1, class InputIterator2, class Compare>
  734. constexpr bool // constexpr in C++20
  735. includes(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, Compare comp);
  736. template <class InputIterator1, class InputIterator2, class OutputIterator>
  737. constexpr OutputIterator // constexpr in C++20
  738. set_union(InputIterator1 first1, InputIterator1 last1,
  739. InputIterator2 first2, InputIterator2 last2, OutputIterator result);
  740. template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
  741. constexpr OutputIterator // constexpr in C++20
  742. set_union(InputIterator1 first1, InputIterator1 last1,
  743. InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
  744. template <class InputIterator1, class InputIterator2, class OutputIterator>
  745. constexpr OutputIterator // constexpr in C++20
  746. set_intersection(InputIterator1 first1, InputIterator1 last1,
  747. InputIterator2 first2, InputIterator2 last2, OutputIterator result);
  748. template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
  749. constexpr OutputIterator // constexpr in C++20
  750. set_intersection(InputIterator1 first1, InputIterator1 last1,
  751. InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
  752. template <class InputIterator1, class InputIterator2, class OutputIterator>
  753. constexpr OutputIterator // constexpr in C++20
  754. set_difference(InputIterator1 first1, InputIterator1 last1,
  755. InputIterator2 first2, InputIterator2 last2, OutputIterator result);
  756. template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
  757. constexpr OutputIterator // constexpr in C++20
  758. set_difference(InputIterator1 first1, InputIterator1 last1,
  759. InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
  760. template <class InputIterator1, class InputIterator2, class OutputIterator>
  761. constexpr OutputIterator // constexpr in C++20
  762. set_symmetric_difference(InputIterator1 first1, InputIterator1 last1,
  763. InputIterator2 first2, InputIterator2 last2, OutputIterator result);
  764. template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
  765. constexpr OutputIterator // constexpr in C++20
  766. set_symmetric_difference(InputIterator1 first1, InputIterator1 last1,
  767. InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
  768. template <class RandomAccessIterator>
  769. constexpr void // constexpr in C++20
  770. push_heap(RandomAccessIterator first, RandomAccessIterator last);
  771. template <class RandomAccessIterator, class Compare>
  772. constexpr void // constexpr in C++20
  773. push_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
  774. template <class RandomAccessIterator>
  775. constexpr void // constexpr in C++20
  776. pop_heap(RandomAccessIterator first, RandomAccessIterator last);
  777. template <class RandomAccessIterator, class Compare>
  778. constexpr void // constexpr in C++20
  779. pop_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
  780. template <class RandomAccessIterator>
  781. constexpr void // constexpr in C++20
  782. make_heap(RandomAccessIterator first, RandomAccessIterator last);
  783. template <class RandomAccessIterator, class Compare>
  784. constexpr void // constexpr in C++20
  785. make_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
  786. template <class RandomAccessIterator>
  787. constexpr void // constexpr in C++20
  788. sort_heap(RandomAccessIterator first, RandomAccessIterator last);
  789. template <class RandomAccessIterator, class Compare>
  790. constexpr void // constexpr in C++20
  791. sort_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
  792. template <class RandomAccessIterator>
  793. constexpr bool // constexpr in C++20
  794. is_heap(RandomAccessIterator first, RandomAccessiterator last);
  795. template <class RandomAccessIterator, class Compare>
  796. constexpr bool // constexpr in C++20
  797. is_heap(RandomAccessIterator first, RandomAccessiterator last, Compare comp);
  798. template <class RandomAccessIterator>
  799. constexpr RandomAccessIterator // constexpr in C++20
  800. is_heap_until(RandomAccessIterator first, RandomAccessiterator last);
  801. template <class RandomAccessIterator, class Compare>
  802. constexpr RandomAccessIterator // constexpr in C++20
  803. is_heap_until(RandomAccessIterator first, RandomAccessiterator last, Compare comp);
  804. template <class ForwardIterator>
  805. constexpr ForwardIterator // constexpr in C++14
  806. min_element(ForwardIterator first, ForwardIterator last);
  807. template <class ForwardIterator, class Compare>
  808. constexpr ForwardIterator // constexpr in C++14
  809. min_element(ForwardIterator first, ForwardIterator last, Compare comp);
  810. template <class T>
  811. constexpr const T& // constexpr in C++14
  812. min(const T& a, const T& b);
  813. template <class T, class Compare>
  814. constexpr const T& // constexpr in C++14
  815. min(const T& a, const T& b, Compare comp);
  816. template<class T>
  817. constexpr T // constexpr in C++14
  818. min(initializer_list<T> t);
  819. template<class T, class Compare>
  820. constexpr T // constexpr in C++14
  821. min(initializer_list<T> t, Compare comp);
  822. template<class T>
  823. constexpr const T& clamp(const T& v, const T& lo, const T& hi); // C++17
  824. template<class T, class Compare>
  825. constexpr const T& clamp(const T& v, const T& lo, const T& hi, Compare comp); // C++17
  826. template <class ForwardIterator>
  827. constexpr ForwardIterator // constexpr in C++14
  828. max_element(ForwardIterator first, ForwardIterator last);
  829. template <class ForwardIterator, class Compare>
  830. constexpr ForwardIterator // constexpr in C++14
  831. max_element(ForwardIterator first, ForwardIterator last, Compare comp);
  832. template <class T>
  833. constexpr const T& // constexpr in C++14
  834. max(const T& a, const T& b);
  835. template <class T, class Compare>
  836. constexpr const T& // constexpr in C++14
  837. max(const T& a, const T& b, Compare comp);
  838. template<class T>
  839. constexpr T // constexpr in C++14
  840. max(initializer_list<T> t);
  841. template<class T, class Compare>
  842. constexpr T // constexpr in C++14
  843. max(initializer_list<T> t, Compare comp);
  844. template<class ForwardIterator>
  845. constexpr pair<ForwardIterator, ForwardIterator> // constexpr in C++14
  846. minmax_element(ForwardIterator first, ForwardIterator last);
  847. template<class ForwardIterator, class Compare>
  848. constexpr pair<ForwardIterator, ForwardIterator> // constexpr in C++14
  849. minmax_element(ForwardIterator first, ForwardIterator last, Compare comp);
  850. template<class T>
  851. constexpr pair<const T&, const T&> // constexpr in C++14
  852. minmax(const T& a, const T& b);
  853. template<class T, class Compare>
  854. constexpr pair<const T&, const T&> // constexpr in C++14
  855. minmax(const T& a, const T& b, Compare comp);
  856. template<class T>
  857. constexpr pair<T, T> // constexpr in C++14
  858. minmax(initializer_list<T> t);
  859. template<class T, class Compare>
  860. constexpr pair<T, T> // constexpr in C++14
  861. minmax(initializer_list<T> t, Compare comp);
  862. template <class InputIterator1, class InputIterator2>
  863. constexpr bool // constexpr in C++20
  864. lexicographical_compare(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2);
  865. template <class InputIterator1, class InputIterator2, class Compare>
  866. constexpr bool // constexpr in C++20
  867. lexicographical_compare(InputIterator1 first1, InputIterator1 last1,
  868. InputIterator2 first2, InputIterator2 last2, Compare comp);
  869. template <class BidirectionalIterator>
  870. constexpr bool // constexpr in C++20
  871. next_permutation(BidirectionalIterator first, BidirectionalIterator last);
  872. template <class BidirectionalIterator, class Compare>
  873. constexpr bool // constexpr in C++20
  874. next_permutation(BidirectionalIterator first, BidirectionalIterator last, Compare comp);
  875. template <class BidirectionalIterator>
  876. constexpr bool // constexpr in C++20
  877. prev_permutation(BidirectionalIterator first, BidirectionalIterator last);
  878. template <class BidirectionalIterator, class Compare>
  879. constexpr bool // constexpr in C++20
  880. prev_permutation(BidirectionalIterator first, BidirectionalIterator last, Compare comp);
  881. } // std
  882. */
  883. #include <__assert> // all public C++ headers provide the assertion handler
  884. #include <__bits>
  885. #include <__config>
  886. #include <__debug>
  887. #include <cstddef>
  888. #include <cstring>
  889. #include <memory>
  890. #include <type_traits>
  891. #include <version>
  892. #include <__algorithm/adjacent_find.h>
  893. #include <__algorithm/all_of.h>
  894. #include <__algorithm/any_of.h>
  895. #include <__algorithm/binary_search.h>
  896. #include <__algorithm/clamp.h>
  897. #include <__algorithm/comp.h>
  898. #include <__algorithm/comp_ref_type.h>
  899. #include <__algorithm/copy.h>
  900. #include <__algorithm/copy_backward.h>
  901. #include <__algorithm/copy_if.h>
  902. #include <__algorithm/copy_n.h>
  903. #include <__algorithm/count.h>
  904. #include <__algorithm/count_if.h>
  905. #include <__algorithm/equal.h>
  906. #include <__algorithm/equal_range.h>
  907. #include <__algorithm/fill.h>
  908. #include <__algorithm/fill_n.h>
  909. #include <__algorithm/find.h>
  910. #include <__algorithm/find_end.h>
  911. #include <__algorithm/find_first_of.h>
  912. #include <__algorithm/find_if.h>
  913. #include <__algorithm/find_if_not.h>
  914. #include <__algorithm/for_each.h>
  915. #include <__algorithm/for_each_n.h>
  916. #include <__algorithm/generate.h>
  917. #include <__algorithm/generate_n.h>
  918. #include <__algorithm/half_positive.h>
  919. #include <__algorithm/in_found_result.h>
  920. #include <__algorithm/in_fun_result.h>
  921. #include <__algorithm/in_in_out_result.h>
  922. #include <__algorithm/in_in_result.h>
  923. #include <__algorithm/in_out_out_result.h>
  924. #include <__algorithm/in_out_result.h>
  925. #include <__algorithm/includes.h>
  926. #include <__algorithm/inplace_merge.h>
  927. #include <__algorithm/is_heap.h>
  928. #include <__algorithm/is_heap_until.h>
  929. #include <__algorithm/is_partitioned.h>
  930. #include <__algorithm/is_permutation.h>
  931. #include <__algorithm/is_sorted.h>
  932. #include <__algorithm/is_sorted_until.h>
  933. #include <__algorithm/iter_swap.h>
  934. #include <__algorithm/lexicographical_compare.h>
  935. #include <__algorithm/lower_bound.h>
  936. #include <__algorithm/make_heap.h>
  937. #include <__algorithm/max.h>
  938. #include <__algorithm/max_element.h>
  939. #include <__algorithm/merge.h>
  940. #include <__algorithm/min.h>
  941. #include <__algorithm/min_element.h>
  942. #include <__algorithm/min_max_result.h>
  943. #include <__algorithm/minmax.h>
  944. #include <__algorithm/minmax_element.h>
  945. #include <__algorithm/mismatch.h>
  946. #include <__algorithm/move.h>
  947. #include <__algorithm/move_backward.h>
  948. #include <__algorithm/next_permutation.h>
  949. #include <__algorithm/none_of.h>
  950. #include <__algorithm/nth_element.h>
  951. #include <__algorithm/partial_sort.h>
  952. #include <__algorithm/partial_sort_copy.h>
  953. #include <__algorithm/partition.h>
  954. #include <__algorithm/partition_copy.h>
  955. #include <__algorithm/partition_point.h>
  956. #include <__algorithm/pop_heap.h>
  957. #include <__algorithm/prev_permutation.h>
  958. #include <__algorithm/push_heap.h>
  959. #include <__algorithm/ranges_adjacent_find.h>
  960. #include <__algorithm/ranges_all_of.h>
  961. #include <__algorithm/ranges_any_of.h>
  962. #include <__algorithm/ranges_binary_search.h>
  963. #include <__algorithm/ranges_copy.h>
  964. #include <__algorithm/ranges_copy_backward.h>
  965. #include <__algorithm/ranges_copy_if.h>
  966. #include <__algorithm/ranges_copy_n.h>
  967. #include <__algorithm/ranges_count.h>
  968. #include <__algorithm/ranges_count_if.h>
  969. #include <__algorithm/ranges_equal.h>
  970. #include <__algorithm/ranges_fill.h>
  971. #include <__algorithm/ranges_fill_n.h>
  972. #include <__algorithm/ranges_find.h>
  973. #include <__algorithm/ranges_find_first_of.h>
  974. #include <__algorithm/ranges_find_if.h>
  975. #include <__algorithm/ranges_find_if_not.h>
  976. #include <__algorithm/ranges_for_each.h>
  977. #include <__algorithm/ranges_for_each_n.h>
  978. #include <__algorithm/ranges_is_partitioned.h>
  979. #include <__algorithm/ranges_is_sorted.h>
  980. #include <__algorithm/ranges_is_sorted_until.h>
  981. #include <__algorithm/ranges_lexicographical_compare.h>
  982. #include <__algorithm/ranges_lower_bound.h>
  983. #include <__algorithm/ranges_max.h>
  984. #include <__algorithm/ranges_max_element.h>
  985. #include <__algorithm/ranges_min.h>
  986. #include <__algorithm/ranges_min_element.h>
  987. #include <__algorithm/ranges_minmax.h>
  988. #include <__algorithm/ranges_minmax_element.h>
  989. #include <__algorithm/ranges_mismatch.h>
  990. #include <__algorithm/ranges_move.h>
  991. #include <__algorithm/ranges_move_backward.h>
  992. #include <__algorithm/ranges_none_of.h>
  993. #include <__algorithm/ranges_replace.h>
  994. #include <__algorithm/ranges_replace_if.h>
  995. #include <__algorithm/ranges_reverse.h>
  996. #include <__algorithm/ranges_sort.h>
  997. #include <__algorithm/ranges_swap_ranges.h>
  998. #include <__algorithm/ranges_transform.h>
  999. #include <__algorithm/ranges_upper_bound.h>
  1000. #include <__algorithm/remove.h>
  1001. #include <__algorithm/remove_copy.h>
  1002. #include <__algorithm/remove_copy_if.h>
  1003. #include <__algorithm/remove_if.h>
  1004. #include <__algorithm/replace.h>
  1005. #include <__algorithm/replace_copy.h>
  1006. #include <__algorithm/replace_copy_if.h>
  1007. #include <__algorithm/replace_if.h>
  1008. #include <__algorithm/reverse.h>
  1009. #include <__algorithm/reverse_copy.h>
  1010. #include <__algorithm/rotate.h>
  1011. #include <__algorithm/rotate_copy.h>
  1012. #include <__algorithm/sample.h>
  1013. #include <__algorithm/search.h>
  1014. #include <__algorithm/search_n.h>
  1015. #include <__algorithm/set_difference.h>
  1016. #include <__algorithm/set_intersection.h>
  1017. #include <__algorithm/set_symmetric_difference.h>
  1018. #include <__algorithm/set_union.h>
  1019. #include <__algorithm/shift_left.h>
  1020. #include <__algorithm/shift_right.h>
  1021. #include <__algorithm/shuffle.h>
  1022. #include <__algorithm/sift_down.h>
  1023. #include <__algorithm/sort.h>
  1024. #include <__algorithm/sort_heap.h>
  1025. #include <__algorithm/stable_partition.h>
  1026. #include <__algorithm/stable_sort.h>
  1027. #include <__algorithm/swap_ranges.h>
  1028. #include <__algorithm/transform.h>
  1029. #include <__algorithm/unique.h>
  1030. #include <__algorithm/unique_copy.h>
  1031. #include <__algorithm/unwrap_iter.h>
  1032. #include <__algorithm/upper_bound.h>
  1033. #ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
  1034. # include <chrono>
  1035. # include <iterator>
  1036. # include <utility>
  1037. #endif
  1038. // standard-mandated includes
  1039. #include <initializer_list>
  1040. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  1041. # pragma GCC system_header
  1042. #endif
  1043. #if defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS) && _LIBCPP_STD_VER >= 17
  1044. #error # include <__pstl_algorithm>
  1045. #endif
  1046. #endif // _LIBCPP_ALGORITHM