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 10#ifndef _LIBCPP_ALGORITHM 11#define _LIBCPP_ALGORITHM 12 13/* 14 algorithm synopsis 15 16#include <initializer_list> 17 18namespace std 19{ 20 21namespace ranges { 22 template <class I, class F> 23 struct in_fun_result; // since C++20 24 25 template <class I1, class I2> 26 struct in_in_result; // since C++20 27 28 template <class I1, class I2, class O> 29 struct in_in_out_result; // since C++20 30 31 template <class I, class O1, class O2> 32 struct in_out_out_result; // since C++20 33 34 template <class I1, class I2> 35 struct min_max_result; // since C++20 36 37 template <class I> 38 struct in_found_result; // since C++20 39 40 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 = {}); 47} 48 49template <class InputIterator, class Predicate> 50 constexpr bool // constexpr in C++20 51 all_of(InputIterator first, InputIterator last, Predicate pred); 52 53template <class InputIterator, class Predicate> 54 constexpr bool // constexpr in C++20 55 any_of(InputIterator first, InputIterator last, Predicate pred); 56 57template <class InputIterator, class Predicate> 58 constexpr bool // constexpr in C++20 59 none_of(InputIterator first, InputIterator last, Predicate pred); 60 61template <class InputIterator, class Function> 62 constexpr Function // constexpr in C++20 63 for_each(InputIterator first, InputIterator last, Function f); 64 65template<class InputIterator, class Size, class Function> 66 constexpr InputIterator // constexpr in C++20 67 for_each_n(InputIterator first, Size n, Function f); // C++17 68 69template <class InputIterator, class T> 70 constexpr InputIterator // constexpr in C++20 71 find(InputIterator first, InputIterator last, const T& value); 72 73template <class InputIterator, class Predicate> 74 constexpr InputIterator // constexpr in C++20 75 find_if(InputIterator first, InputIterator last, Predicate pred); 76 77template<class InputIterator, class Predicate> 78 constexpr InputIterator // constexpr in C++20 79 find_if_not(InputIterator first, InputIterator last, Predicate pred); 80 81template <class ForwardIterator1, class ForwardIterator2> 82 constexpr ForwardIterator1 // constexpr in C++20 83 find_end(ForwardIterator1 first1, ForwardIterator1 last1, 84 ForwardIterator2 first2, ForwardIterator2 last2); 85 86template <class ForwardIterator1, class ForwardIterator2, class BinaryPredicate> 87 constexpr ForwardIterator1 // constexpr in C++20 88 find_end(ForwardIterator1 first1, ForwardIterator1 last1, 89 ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred); 90 91template <class ForwardIterator1, class ForwardIterator2> 92 constexpr ForwardIterator1 // constexpr in C++20 93 find_first_of(ForwardIterator1 first1, ForwardIterator1 last1, 94 ForwardIterator2 first2, ForwardIterator2 last2); 95 96template <class ForwardIterator1, class ForwardIterator2, class BinaryPredicate> 97 constexpr ForwardIterator1 // constexpr in C++20 98 find_first_of(ForwardIterator1 first1, ForwardIterator1 last1, 99 ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred); 100 101template <class ForwardIterator> 102 constexpr ForwardIterator // constexpr in C++20 103 adjacent_find(ForwardIterator first, ForwardIterator last); 104 105template <class ForwardIterator, class BinaryPredicate> 106 constexpr ForwardIterator // constexpr in C++20 107 adjacent_find(ForwardIterator first, ForwardIterator last, BinaryPredicate pred); 108 109template <class InputIterator, class T> 110 constexpr typename iterator_traits<InputIterator>::difference_type // constexpr in C++20 111 count(InputIterator first, InputIterator last, const T& value); 112 113template <class InputIterator, class Predicate> 114 constexpr typename iterator_traits<InputIterator>::difference_type // constexpr in C++20 115 count_if(InputIterator first, InputIterator last, Predicate pred); 116 117template <class InputIterator1, class InputIterator2> 118 constexpr pair<InputIterator1, InputIterator2> // constexpr in C++20 119 mismatch(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2); 120 121template <class InputIterator1, class InputIterator2> 122 constexpr pair<InputIterator1, InputIterator2> // constexpr in C++20 123 mismatch(InputIterator1 first1, InputIterator1 last1, 124 InputIterator2 first2, InputIterator2 last2); // **C++14** 125 126template <class InputIterator1, class InputIterator2, class BinaryPredicate> 127 constexpr pair<InputIterator1, InputIterator2> // constexpr in C++20 128 mismatch(InputIterator1 first1, InputIterator1 last1, 129 InputIterator2 first2, BinaryPredicate pred); 130 131template <class InputIterator1, class InputIterator2, class BinaryPredicate> 132 constexpr pair<InputIterator1, InputIterator2> // constexpr in C++20 133 mismatch(InputIterator1 first1, InputIterator1 last1, 134 InputIterator2 first2, InputIterator2 last2, 135 BinaryPredicate pred); // **C++14** 136 137template <class InputIterator1, class InputIterator2> 138 constexpr bool // constexpr in C++20 139 equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2); 140 141template <class InputIterator1, class InputIterator2> 142 constexpr bool // constexpr in C++20 143 equal(InputIterator1 first1, InputIterator1 last1, 144 InputIterator2 first2, InputIterator2 last2); // **C++14** 145 146template <class InputIterator1, class InputIterator2, class BinaryPredicate> 147 constexpr bool // constexpr in C++20 148 equal(InputIterator1 first1, InputIterator1 last1, 149 InputIterator2 first2, BinaryPredicate pred); 150 151template <class InputIterator1, class InputIterator2, class BinaryPredicate> 152 constexpr bool // constexpr in C++20 153 equal(InputIterator1 first1, InputIterator1 last1, 154 InputIterator2 first2, InputIterator2 last2, 155 BinaryPredicate pred); // **C++14** 156 157template<class ForwardIterator1, class ForwardIterator2> 158 constexpr bool // constexpr in C++20 159 is_permutation(ForwardIterator1 first1, ForwardIterator1 last1, 160 ForwardIterator2 first2); 161 162template<class ForwardIterator1, class ForwardIterator2> 163 constexpr bool // constexpr in C++20 164 is_permutation(ForwardIterator1 first1, ForwardIterator1 last1, 165 ForwardIterator2 first2, ForwardIterator2 last2); // **C++14** 166 167template<class ForwardIterator1, class ForwardIterator2, class BinaryPredicate> 168 constexpr bool // constexpr in C++20 169 is_permutation(ForwardIterator1 first1, ForwardIterator1 last1, 170 ForwardIterator2 first2, BinaryPredicate pred); 171 172template<class ForwardIterator1, class ForwardIterator2, class BinaryPredicate> 173 constexpr bool // constexpr in C++20 174 is_permutation(ForwardIterator1 first1, ForwardIterator1 last1, 175 ForwardIterator2 first2, ForwardIterator2 last2, 176 BinaryPredicate pred); // **C++14** 177 178template <class ForwardIterator1, class ForwardIterator2> 179 constexpr ForwardIterator1 // constexpr in C++20 180 search(ForwardIterator1 first1, ForwardIterator1 last1, 181 ForwardIterator2 first2, ForwardIterator2 last2); 182 183template <class ForwardIterator1, class ForwardIterator2, class BinaryPredicate> 184 constexpr ForwardIterator1 // constexpr in C++20 185 search(ForwardIterator1 first1, ForwardIterator1 last1, 186 ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred); 187 188template <class ForwardIterator, class Size, class T> 189 constexpr ForwardIterator // constexpr in C++20 190 search_n(ForwardIterator first, ForwardIterator last, Size count, const T& value); 191 192template <class ForwardIterator, class Size, class T, class BinaryPredicate> 193 constexpr ForwardIterator // constexpr in C++20 194 search_n(ForwardIterator first, ForwardIterator last, 195 Size count, const T& value, BinaryPredicate pred); 196 197template <class InputIterator, class OutputIterator> 198 constexpr OutputIterator // constexpr in C++20 199 copy(InputIterator first, InputIterator last, OutputIterator result); 200 201template<class InputIterator, class OutputIterator, class Predicate> 202 constexpr OutputIterator // constexpr in C++20 203 copy_if(InputIterator first, InputIterator last, 204 OutputIterator result, Predicate pred); 205 206template<class InputIterator, class Size, class OutputIterator> 207 constexpr OutputIterator // constexpr in C++20 208 copy_n(InputIterator first, Size n, OutputIterator result); 209 210template <class BidirectionalIterator1, class BidirectionalIterator2> 211 constexpr BidirectionalIterator2 // constexpr in C++20 212 copy_backward(BidirectionalIterator1 first, BidirectionalIterator1 last, 213 BidirectionalIterator2 result); 214 215template <class ForwardIterator1, class ForwardIterator2> 216 constexpr ForwardIterator2 // constexpr in C++20 217 swap_ranges(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2); 218 219template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2> 220 requires indirectly_swappable<I1, I2> 221 constexpr ranges::swap_ranges_result<I1, I2> 222 ranges::swap_ranges(I1 first1, S1 last1, I2 first2, S2 last2); 223 224template<input_range R1, input_range R2> 225 requires indirectly_swappable<iterator_t<R1>, iterator_t<R2>> 226 constexpr ranges::swap_ranges_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>> 227 ranges::swap_ranges(R1&& r1, R2&& r2); 228 229template <class ForwardIterator1, class ForwardIterator2> 230 constexpr void // constexpr in C++20 231 iter_swap(ForwardIterator1 a, ForwardIterator2 b); 232 233template <class InputIterator, class OutputIterator, class UnaryOperation> 234 constexpr OutputIterator // constexpr in C++20 235 transform(InputIterator first, InputIterator last, OutputIterator result, UnaryOperation op); 236 237template <class InputIterator1, class InputIterator2, class OutputIterator, class BinaryOperation> 238 constexpr OutputIterator // constexpr in C++20 239 transform(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, 240 OutputIterator result, BinaryOperation binary_op); 241 242template <class ForwardIterator, class T> 243 constexpr void // constexpr in C++20 244 replace(ForwardIterator first, ForwardIterator last, const T& old_value, const T& new_value); 245 246template <class ForwardIterator, class Predicate, class T> 247 constexpr void // constexpr in C++20 248 replace_if(ForwardIterator first, ForwardIterator last, Predicate pred, const T& new_value); 249 250template <class InputIterator, class OutputIterator, class T> 251 constexpr OutputIterator // constexpr in C++20 252 replace_copy(InputIterator first, InputIterator last, OutputIterator result, 253 const T& old_value, const T& new_value); 254 255template <class InputIterator, class OutputIterator, class Predicate, class T> 256 constexpr OutputIterator // constexpr in C++20 257 replace_copy_if(InputIterator first, InputIterator last, OutputIterator result, Predicate pred, const T& new_value); 258 259template <class ForwardIterator, class T> 260 constexpr void // constexpr in C++20 261 fill(ForwardIterator first, ForwardIterator last, const T& value); 262 263template <class OutputIterator, class Size, class T> 264 constexpr OutputIterator // constexpr in C++20 265 fill_n(OutputIterator first, Size n, const T& value); 266 267template <class ForwardIterator, class Generator> 268 constexpr void // constexpr in C++20 269 generate(ForwardIterator first, ForwardIterator last, Generator gen); 270 271template <class OutputIterator, class Size, class Generator> 272 constexpr OutputIterator // constexpr in C++20 273 generate_n(OutputIterator first, Size n, Generator gen); 274 275template <class ForwardIterator, class T> 276 constexpr ForwardIterator // constexpr in C++20 277 remove(ForwardIterator first, ForwardIterator last, const T& value); 278 279template <class ForwardIterator, class Predicate> 280 constexpr ForwardIterator // constexpr in C++20 281 remove_if(ForwardIterator first, ForwardIterator last, Predicate pred); 282 283template <class InputIterator, class OutputIterator, class T> 284 constexpr OutputIterator // constexpr in C++20 285 remove_copy(InputIterator first, InputIterator last, OutputIterator result, const T& value); 286 287template <class InputIterator, class OutputIterator, class Predicate> 288 constexpr OutputIterator // constexpr in C++20 289 remove_copy_if(InputIterator first, InputIterator last, OutputIterator result, Predicate pred); 290 291template <class ForwardIterator> 292 constexpr ForwardIterator // constexpr in C++20 293 unique(ForwardIterator first, ForwardIterator last); 294 295template <class ForwardIterator, class BinaryPredicate> 296 constexpr ForwardIterator // constexpr in C++20 297 unique(ForwardIterator first, ForwardIterator last, BinaryPredicate pred); 298 299template <class InputIterator, class OutputIterator> 300 constexpr OutputIterator // constexpr in C++20 301 unique_copy(InputIterator first, InputIterator last, OutputIterator result); 302 303template <class InputIterator, class OutputIterator, class BinaryPredicate> 304 constexpr OutputIterator // constexpr in C++20 305 unique_copy(InputIterator first, InputIterator last, OutputIterator result, BinaryPredicate pred); 306 307template <class BidirectionalIterator> 308 constexpr void // constexpr in C++20 309 reverse(BidirectionalIterator first, BidirectionalIterator last); 310 311template <class BidirectionalIterator, class OutputIterator> 312 constexpr OutputIterator // constexpr in C++20 313 reverse_copy(BidirectionalIterator first, BidirectionalIterator last, OutputIterator result); 314 315template <class ForwardIterator> 316 constexpr ForwardIterator // constexpr in C++20 317 rotate(ForwardIterator first, ForwardIterator middle, ForwardIterator last); 318 319template <class ForwardIterator, class OutputIterator> 320 constexpr OutputIterator // constexpr in C++20 321 rotate_copy(ForwardIterator first, ForwardIterator middle, ForwardIterator last, OutputIterator result); 322 323template <class RandomAccessIterator> 324 void 325 random_shuffle(RandomAccessIterator first, RandomAccessIterator last); // deprecated in C++14, removed in C++17 326 327template <class RandomAccessIterator, class RandomNumberGenerator> 328 void 329 random_shuffle(RandomAccessIterator first, RandomAccessIterator last, 330 RandomNumberGenerator& rand); // deprecated in C++14, removed in C++17 331 332template<class PopulationIterator, class SampleIterator, 333 class Distance, class UniformRandomBitGenerator> 334 SampleIterator sample(PopulationIterator first, PopulationIterator last, 335 SampleIterator out, Distance n, 336 UniformRandomBitGenerator&& g); // C++17 337 338template<class RandomAccessIterator, class UniformRandomNumberGenerator> 339 void shuffle(RandomAccessIterator first, RandomAccessIterator last, 340 UniformRandomNumberGenerator&& g); 341 342template<class ForwardIterator> 343 constexpr ForwardIterator 344 shift_left(ForwardIterator first, ForwardIterator last, 345 typename iterator_traits<ForwardIterator>::difference_type n); // C++20 346 347template<class ForwardIterator> 348 constexpr ForwardIterator 349 shift_right(ForwardIterator first, ForwardIterator last, 350 typename iterator_traits<ForwardIterator>::difference_type n); // C++20 351 352template <class InputIterator, class Predicate> 353 constexpr bool // constexpr in C++20 354 is_partitioned(InputIterator first, InputIterator last, Predicate pred); 355 356template <class ForwardIterator, class Predicate> 357 constexpr ForwardIterator // constexpr in C++20 358 partition(ForwardIterator first, ForwardIterator last, Predicate pred); 359 360template <class InputIterator, class OutputIterator1, 361 class OutputIterator2, class Predicate> 362 constexpr pair<OutputIterator1, OutputIterator2> // constexpr in C++20 363 partition_copy(InputIterator first, InputIterator last, 364 OutputIterator1 out_true, OutputIterator2 out_false, 365 Predicate pred); 366 367template <class ForwardIterator, class Predicate> 368 ForwardIterator 369 stable_partition(ForwardIterator first, ForwardIterator last, Predicate pred); 370 371template<class ForwardIterator, class Predicate> 372 constexpr ForwardIterator // constexpr in C++20 373 partition_point(ForwardIterator first, ForwardIterator last, Predicate pred); 374 375template <class ForwardIterator> 376 constexpr bool // constexpr in C++20 377 is_sorted(ForwardIterator first, ForwardIterator last); 378 379template <class ForwardIterator, class Compare> 380 constexpr bool // constexpr in C++20 381 is_sorted(ForwardIterator first, ForwardIterator last, Compare comp); 382 383template<class ForwardIterator> 384 constexpr ForwardIterator // constexpr in C++20 385 is_sorted_until(ForwardIterator first, ForwardIterator last); 386 387template <class ForwardIterator, class Compare> 388 constexpr ForwardIterator // constexpr in C++20 389 is_sorted_until(ForwardIterator first, ForwardIterator last, Compare comp); 390 391template <class RandomAccessIterator> 392 constexpr void // constexpr in C++20 393 sort(RandomAccessIterator first, RandomAccessIterator last); 394 395template <class RandomAccessIterator, class Compare> 396 constexpr void // constexpr in C++20 397 sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp); 398 399template <class RandomAccessIterator> 400 void 401 stable_sort(RandomAccessIterator first, RandomAccessIterator last); 402 403template <class RandomAccessIterator, class Compare> 404 void 405 stable_sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp); 406 407template <class RandomAccessIterator> 408 constexpr void // constexpr in C++20 409 partial_sort(RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last); 410 411template <class RandomAccessIterator, class Compare> 412 constexpr void // constexpr in C++20 413 partial_sort(RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last, Compare comp); 414 415template <class InputIterator, class RandomAccessIterator> 416 constexpr RandomAccessIterator // constexpr in C++20 417 partial_sort_copy(InputIterator first, InputIterator last, 418 RandomAccessIterator result_first, RandomAccessIterator result_last); 419 420template <class InputIterator, class RandomAccessIterator, class Compare> 421 constexpr RandomAccessIterator // constexpr in C++20 422 partial_sort_copy(InputIterator first, InputIterator last, 423 RandomAccessIterator result_first, RandomAccessIterator result_last, Compare comp); 424 425template <class RandomAccessIterator> 426 constexpr void // constexpr in C++20 427 nth_element(RandomAccessIterator first, RandomAccessIterator nth, RandomAccessIterator last); 428 429template <class RandomAccessIterator, class Compare> 430 constexpr void // constexpr in C++20 431 nth_element(RandomAccessIterator first, RandomAccessIterator nth, RandomAccessIterator last, Compare comp); 432 433template <class ForwardIterator, class T> 434 constexpr ForwardIterator // constexpr in C++20 435 lower_bound(ForwardIterator first, ForwardIterator last, const T& value); 436 437template <class ForwardIterator, class T, class Compare> 438 constexpr ForwardIterator // constexpr in C++20 439 lower_bound(ForwardIterator first, ForwardIterator last, const T& value, Compare comp); 440 441template <class ForwardIterator, class T> 442 constexpr ForwardIterator // constexpr in C++20 443 upper_bound(ForwardIterator first, ForwardIterator last, const T& value); 444 445template <class ForwardIterator, class T, class Compare> 446 constexpr ForwardIterator // constexpr in C++20 447 upper_bound(ForwardIterator first, ForwardIterator last, const T& value, Compare comp); 448 449template <class ForwardIterator, class T> 450 constexpr pair<ForwardIterator, ForwardIterator> // constexpr in C++20 451 equal_range(ForwardIterator first, ForwardIterator last, const T& value); 452 453template <class ForwardIterator, class T, class Compare> 454 constexpr pair<ForwardIterator, ForwardIterator> // constexpr in C++20 455 equal_range(ForwardIterator first, ForwardIterator last, const T& value, Compare comp); 456 457template <class ForwardIterator, class T> 458 constexpr bool // constexpr in C++20 459 binary_search(ForwardIterator first, ForwardIterator last, const T& value); 460 461template <class ForwardIterator, class T, class Compare> 462 constexpr bool // constexpr in C++20 463 binary_search(ForwardIterator first, ForwardIterator last, const T& value, Compare comp); 464 465template <class InputIterator1, class InputIterator2, class OutputIterator> 466 constexpr OutputIterator // constexpr in C++20 467 merge(InputIterator1 first1, InputIterator1 last1, 468 InputIterator2 first2, InputIterator2 last2, OutputIterator result); 469 470template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare> 471 constexpr OutputIterator // constexpr in C++20 472 merge(InputIterator1 first1, InputIterator1 last1, 473 InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp); 474 475template <class BidirectionalIterator> 476 void 477 inplace_merge(BidirectionalIterator first, BidirectionalIterator middle, BidirectionalIterator last); 478 479template <class BidirectionalIterator, class Compare> 480 void 481 inplace_merge(BidirectionalIterator first, BidirectionalIterator middle, BidirectionalIterator last, Compare comp); 482 483template <class InputIterator1, class InputIterator2> 484 constexpr bool // constexpr in C++20 485 includes(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2); 486 487template <class InputIterator1, class InputIterator2, class Compare> 488 constexpr bool // constexpr in C++20 489 includes(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, Compare comp); 490 491template <class InputIterator1, class InputIterator2, class OutputIterator> 492 constexpr OutputIterator // constexpr in C++20 493 set_union(InputIterator1 first1, InputIterator1 last1, 494 InputIterator2 first2, InputIterator2 last2, OutputIterator result); 495 496template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare> 497 constexpr OutputIterator // constexpr in C++20 498 set_union(InputIterator1 first1, InputIterator1 last1, 499 InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp); 500 501template <class InputIterator1, class InputIterator2, class OutputIterator> 502 constexpr OutputIterator // constexpr in C++20 503 set_intersection(InputIterator1 first1, InputIterator1 last1, 504 InputIterator2 first2, InputIterator2 last2, OutputIterator result); 505 506template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare> 507 constexpr OutputIterator // constexpr in C++20 508 set_intersection(InputIterator1 first1, InputIterator1 last1, 509 InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp); 510 511template <class InputIterator1, class InputIterator2, class OutputIterator> 512 constexpr OutputIterator // constexpr in C++20 513 set_difference(InputIterator1 first1, InputIterator1 last1, 514 InputIterator2 first2, InputIterator2 last2, OutputIterator result); 515 516template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare> 517 constexpr OutputIterator // constexpr in C++20 518 set_difference(InputIterator1 first1, InputIterator1 last1, 519 InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp); 520 521template <class InputIterator1, class InputIterator2, class OutputIterator> 522 constexpr OutputIterator // constexpr in C++20 523 set_symmetric_difference(InputIterator1 first1, InputIterator1 last1, 524 InputIterator2 first2, InputIterator2 last2, OutputIterator result); 525 526template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare> 527 constexpr OutputIterator // constexpr in C++20 528 set_symmetric_difference(InputIterator1 first1, InputIterator1 last1, 529 InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp); 530 531template <class RandomAccessIterator> 532 constexpr void // constexpr in C++20 533 push_heap(RandomAccessIterator first, RandomAccessIterator last); 534 535template <class RandomAccessIterator, class Compare> 536 constexpr void // constexpr in C++20 537 push_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp); 538 539template <class RandomAccessIterator> 540 constexpr void // constexpr in C++20 541 pop_heap(RandomAccessIterator first, RandomAccessIterator last); 542 543template <class RandomAccessIterator, class Compare> 544 constexpr void // constexpr in C++20 545 pop_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp); 546 547template <class RandomAccessIterator> 548 constexpr void // constexpr in C++20 549 make_heap(RandomAccessIterator first, RandomAccessIterator last); 550 551template <class RandomAccessIterator, class Compare> 552 constexpr void // constexpr in C++20 553 make_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp); 554 555template <class RandomAccessIterator> 556 constexpr void // constexpr in C++20 557 sort_heap(RandomAccessIterator first, RandomAccessIterator last); 558 559template <class RandomAccessIterator, class Compare> 560 constexpr void // constexpr in C++20 561 sort_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp); 562 563template <class RandomAccessIterator> 564 constexpr bool // constexpr in C++20 565 is_heap(RandomAccessIterator first, RandomAccessiterator last); 566 567template <class RandomAccessIterator, class Compare> 568 constexpr bool // constexpr in C++20 569 is_heap(RandomAccessIterator first, RandomAccessiterator last, Compare comp); 570 571template <class RandomAccessIterator> 572 constexpr RandomAccessIterator // constexpr in C++20 573 is_heap_until(RandomAccessIterator first, RandomAccessiterator last); 574 575template <class RandomAccessIterator, class Compare> 576 constexpr RandomAccessIterator // constexpr in C++20 577 is_heap_until(RandomAccessIterator first, RandomAccessiterator last, Compare comp); 578 579template <class ForwardIterator> 580 constexpr ForwardIterator // constexpr in C++14 581 min_element(ForwardIterator first, ForwardIterator last); 582 583template <class ForwardIterator, class Compare> 584 constexpr ForwardIterator // constexpr in C++14 585 min_element(ForwardIterator first, ForwardIterator last, Compare comp); 586 587template <class T> 588 constexpr const T& // constexpr in C++14 589 min(const T& a, const T& b); 590 591template <class T, class Compare> 592 constexpr const T& // constexpr in C++14 593 min(const T& a, const T& b, Compare comp); 594 595template<class T> 596 constexpr T // constexpr in C++14 597 min(initializer_list<T> t); 598 599template<class T, class Compare> 600 constexpr T // constexpr in C++14 601 min(initializer_list<T> t, Compare comp); 602 603template<class T> 604 constexpr const T& clamp(const T& v, const T& lo, const T& hi); // C++17 605 606template<class T, class Compare> 607 constexpr const T& clamp(const T& v, const T& lo, const T& hi, Compare comp); // C++17 608 609template <class ForwardIterator> 610 constexpr ForwardIterator // constexpr in C++14 611 max_element(ForwardIterator first, ForwardIterator last); 612 613template <class ForwardIterator, class Compare> 614 constexpr ForwardIterator // constexpr in C++14 615 max_element(ForwardIterator first, ForwardIterator last, Compare comp); 616 617template <class T> 618 constexpr const T& // constexpr in C++14 619 max(const T& a, const T& b); 620 621template <class T, class Compare> 622 constexpr const T& // constexpr in C++14 623 max(const T& a, const T& b, Compare comp); 624 625template<class T> 626 constexpr T // constexpr in C++14 627 max(initializer_list<T> t); 628 629template<class T, class Compare> 630 constexpr T // constexpr in C++14 631 max(initializer_list<T> t, Compare comp); 632 633template<class ForwardIterator> 634 constexpr pair<ForwardIterator, ForwardIterator> // constexpr in C++14 635 minmax_element(ForwardIterator first, ForwardIterator last); 636 637template<class ForwardIterator, class Compare> 638 constexpr pair<ForwardIterator, ForwardIterator> // constexpr in C++14 639 minmax_element(ForwardIterator first, ForwardIterator last, Compare comp); 640 641template<class T> 642 constexpr pair<const T&, const T&> // constexpr in C++14 643 minmax(const T& a, const T& b); 644 645template<class T, class Compare> 646 constexpr pair<const T&, const T&> // constexpr in C++14 647 minmax(const T& a, const T& b, Compare comp); 648 649template<class T> 650 constexpr pair<T, T> // constexpr in C++14 651 minmax(initializer_list<T> t); 652 653template<class T, class Compare> 654 constexpr pair<T, T> // constexpr in C++14 655 minmax(initializer_list<T> t, Compare comp); 656 657template <class InputIterator1, class InputIterator2> 658 constexpr bool // constexpr in C++20 659 lexicographical_compare(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2); 660 661template <class InputIterator1, class InputIterator2, class Compare> 662 constexpr bool // constexpr in C++20 663 lexicographical_compare(InputIterator1 first1, InputIterator1 last1, 664 InputIterator2 first2, InputIterator2 last2, Compare comp); 665 666template <class BidirectionalIterator> 667 constexpr bool // constexpr in C++20 668 next_permutation(BidirectionalIterator first, BidirectionalIterator last); 669 670template <class BidirectionalIterator, class Compare> 671 constexpr bool // constexpr in C++20 672 next_permutation(BidirectionalIterator first, BidirectionalIterator last, Compare comp); 673 674template <class BidirectionalIterator> 675 constexpr bool // constexpr in C++20 676 prev_permutation(BidirectionalIterator first, BidirectionalIterator last); 677 678template <class BidirectionalIterator, class Compare> 679 constexpr bool // constexpr in C++20 680 prev_permutation(BidirectionalIterator first, BidirectionalIterator last, Compare comp); 681} // std 682 683*/ 684 685#include <__bits> 686#include <__config> 687#include <__debug> 688#include <cstddef> 689#include <cstring> 690#include <functional> 691#include <initializer_list> 692#include <iterator> 693#include <memory> 694#include <type_traits> 695#include <version> 696 697#include <utility> // TODO: Remove this 698 699#include <__algorithm/adjacent_find.h> 700#include <__algorithm/all_of.h> 701#include <__algorithm/any_of.h> 702#include <__algorithm/binary_search.h> 703#include <__algorithm/clamp.h> 704#include <__algorithm/comp.h> 705#include <__algorithm/comp_ref_type.h> 706#include <__algorithm/copy.h> 707#include <__algorithm/copy_backward.h> 708#include <__algorithm/copy_if.h> 709#include <__algorithm/copy_n.h> 710#include <__algorithm/count.h> 711#include <__algorithm/count_if.h> 712#include <__algorithm/equal.h> 713#include <__algorithm/equal_range.h> 714#include <__algorithm/fill.h> 715#include <__algorithm/fill_n.h> 716#include <__algorithm/find.h> 717#include <__algorithm/find_end.h> 718#include <__algorithm/find_first_of.h> 719#include <__algorithm/find_if.h> 720#include <__algorithm/find_if_not.h> 721#include <__algorithm/for_each.h> 722#include <__algorithm/for_each_n.h> 723#include <__algorithm/generate.h> 724#include <__algorithm/generate_n.h> 725#include <__algorithm/half_positive.h> 726#include <__algorithm/in_found_result.h> 727#include <__algorithm/in_fun_result.h> 728#include <__algorithm/in_in_out_result.h> 729#include <__algorithm/in_in_result.h> 730#include <__algorithm/in_out_out_result.h> 731#include <__algorithm/in_out_result.h> 732#include <__algorithm/includes.h> 733#include <__algorithm/inplace_merge.h> 734#include <__algorithm/is_heap.h> 735#include <__algorithm/is_heap_until.h> 736#include <__algorithm/is_partitioned.h> 737#include <__algorithm/is_permutation.h> 738#include <__algorithm/is_sorted.h> 739#include <__algorithm/is_sorted_until.h> 740#include <__algorithm/iter_swap.h> 741#include <__algorithm/lexicographical_compare.h> 742#include <__algorithm/lower_bound.h> 743#include <__algorithm/make_heap.h> 744#include <__algorithm/max.h> 745#include <__algorithm/max_element.h> 746#include <__algorithm/merge.h> 747#include <__algorithm/min.h> 748#include <__algorithm/min_element.h> 749#include <__algorithm/min_max_result.h> 750#include <__algorithm/minmax.h> 751#include <__algorithm/minmax_element.h> 752#include <__algorithm/mismatch.h> 753#include <__algorithm/move.h> 754#include <__algorithm/move_backward.h> 755#include <__algorithm/next_permutation.h> 756#include <__algorithm/none_of.h> 757#include <__algorithm/nth_element.h> 758#include <__algorithm/partial_sort.h> 759#include <__algorithm/partial_sort_copy.h> 760#include <__algorithm/partition.h> 761#include <__algorithm/partition_copy.h> 762#include <__algorithm/partition_point.h> 763#include <__algorithm/pop_heap.h> 764#include <__algorithm/prev_permutation.h> 765#include <__algorithm/push_heap.h> 766#include <__algorithm/ranges_min_element.h> 767#include <__algorithm/ranges_swap_ranges.h> 768#include <__algorithm/remove.h> 769#include <__algorithm/remove_copy.h> 770#include <__algorithm/remove_copy_if.h> 771#include <__algorithm/remove_if.h> 772#include <__algorithm/replace.h> 773#include <__algorithm/replace_copy.h> 774#include <__algorithm/replace_copy_if.h> 775#include <__algorithm/replace_if.h> 776#include <__algorithm/reverse.h> 777#include <__algorithm/reverse_copy.h> 778#include <__algorithm/rotate.h> 779#include <__algorithm/rotate_copy.h> 780#include <__algorithm/sample.h> 781#include <__algorithm/search.h> 782#include <__algorithm/search_n.h> 783#include <__algorithm/set_difference.h> 784#include <__algorithm/set_intersection.h> 785#include <__algorithm/set_symmetric_difference.h> 786#include <__algorithm/set_union.h> 787#include <__algorithm/shift_left.h> 788#include <__algorithm/shift_right.h> 789#include <__algorithm/shuffle.h> 790#include <__algorithm/sift_down.h> 791#include <__algorithm/sort.h> 792#include <__algorithm/sort_heap.h> 793#include <__algorithm/stable_partition.h> 794#include <__algorithm/stable_sort.h> 795#include <__algorithm/swap_ranges.h> 796#include <__algorithm/transform.h> 797#include <__algorithm/unique.h> 798#include <__algorithm/unique_copy.h> 799#include <__algorithm/unwrap_iter.h> 800#include <__algorithm/upper_bound.h> 801 802#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 803# pragma GCC system_header 804#endif 805 806#if defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS) && _LIBCPP_STD_VER >= 17 807# include <__pstl_algorithm> 808#endif 809 810#endif // _LIBCPP_ALGORITHM 811