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