From Jason Turner

[algorithms]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpjbelca48/{from.md → to.md} +205 -140
tmp/tmpjbelca48/{from.md → to.md} RENAMED
@@ -89,26 +89,58 @@ namespace std {
89
  <class InputIterator1, class InputIterator2, class BinaryPredicate>
90
  pair<InputIterator1, InputIterator2>
91
  mismatch(InputIterator1 first1, InputIterator1 last1,
92
  InputIterator2 first2, BinaryPredicate pred);
93
 
 
 
 
 
 
 
 
 
 
 
 
 
94
  template<class InputIterator1, class InputIterator2>
95
  bool equal(InputIterator1 first1, InputIterator1 last1,
96
  InputIterator2 first2);
97
  template
98
  <class InputIterator1, class InputIterator2, class BinaryPredicate>
99
  bool equal(InputIterator1 first1, InputIterator1 last1,
100
  InputIterator2 first2, BinaryPredicate pred);
101
 
 
 
 
 
 
 
 
 
 
 
102
  template<class ForwardIterator1, class ForwardIterator2>
103
  bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
104
  ForwardIterator2 first2);
105
  template<class ForwardIterator1, class ForwardIterator2,
106
  class BinaryPredicate>
107
  bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
108
  ForwardIterator2 first2, BinaryPredicate pred);
109
 
 
 
 
 
 
 
 
 
 
 
110
  template<class ForwardIterator1, class ForwardIterator2>
111
  ForwardIterator1 search(
112
  ForwardIterator1 first1, ForwardIterator1 last1,
113
  ForwardIterator2 first2, ForwardIterator2 last2);
114
  template<class ForwardIterator1, class ForwardIterator2,
@@ -120,11 +152,11 @@ namespace std {
120
  template<class ForwardIterator, class Size, class T>
121
  ForwardIterator search_n(ForwardIterator first, ForwardIterator last,
122
  Size count, const T& value);
123
  template
124
  <class ForwardIterator, class Size, class T, class BinaryPredicate>
125
- ForwardIterator1 search_n(ForwardIterator first, ForwardIterator last,
126
  Size count, const T& value,
127
  BinaryPredicate pred);
128
 
129
  // [alg.modifying.operations], modifying sequence operations:
130
  // [alg.copy], copy:
@@ -231,21 +263,24 @@ namespace std {
231
  template<class ForwardIterator, class OutputIterator>
232
  OutputIterator rotate_copy(
233
  ForwardIterator first, ForwardIterator middle,
234
  ForwardIterator last, OutputIterator result);
235
 
 
236
  template<class RandomAccessIterator>
237
  void random_shuffle(RandomAccessIterator first,
238
  RandomAccessIterator last);
239
  template<class RandomAccessIterator, class RandomNumberGenerator>
240
  void random_shuffle(RandomAccessIterator first,
241
  RandomAccessIterator last,
242
- RandomNumberGenerator&& rand);
 
 
243
  template<class RandomAccessIterator, class UniformRandomNumberGenerator>
244
  void shuffle(RandomAccessIterator first,
245
  RandomAccessIterator last,
246
- UniformRandomNumberGenerator&& rand);
247
 
248
  // [alg.partitions], partitions:
249
  template <class InputIterator, class Predicate>
250
  bool is_partitioned(InputIterator first, InputIterator last, Predicate pred);
251
 
@@ -459,33 +494,33 @@ namespace std {
459
  template<class RandomAccessIterator, class Compare>
460
  RandomAccessIterator is_heap_until(RandomAccessIterator first, RandomAccessIterator last,
461
  Compare comp);
462
 
463
  // [alg.min.max], minimum and maximum:
464
- template<class T> const T& min(const T& a, const T& b);
465
  template<class T, class Compare>
466
- const T& min(const T& a, const T& b, Compare comp);
467
  template<class T>
468
- T min(initializer_list<T> t);
469
  template<class T, class Compare>
470
- T min(initializer_list<T> t, Compare comp);
471
 
472
- template<class T> const T& max(const T& a, const T& b);
473
  template<class T, class Compare>
474
- const T& max(const T& a, const T& b, Compare comp);
475
  template<class T>
476
- T max(initializer_list<T> t);
477
  template<class T, class Compare>
478
- T max(initializer_list<T> t, Compare comp);
479
 
480
- template<class T> pair<const T&, const T&> minmax(const T& a, const T& b);
481
  template<class T, class Compare>
482
- pair<const T&, const T&> minmax(const T& a, const T& b, Compare comp);
483
  template<class T>
484
- pair<T, T> minmax(initializer_list<T> t);
485
  template<class T, class Compare>
486
- pair<T, T> minmax(initializer_list<T> t, Compare comp);
487
 
488
  template<class ForwardIterator>
489
  ForwardIterator min_element(ForwardIterator first, ForwardIterator last);
490
  template<class ForwardIterator, class Compare>
491
  ForwardIterator min_element(ForwardIterator first, ForwardIterator last,
@@ -537,35 +572,39 @@ the algorithms.
537
  For purposes of determining the existence of data races, algorithms
538
  shall not modify objects referenced through an iterator argument unless
539
  the specification requires such modification.
540
 
541
  Throughout this Clause, the names of template parameters are used to
542
- express type requirements. If an algorithm’s template parameter is
543
- `InputIterator`, `InputIterator1`, or `InputIterator2`, the actual
544
- template argument shall satisfy the requirements of an input iterator (
545
- [[input.iterators]]). If an algorithm’s template parameter is
546
- `OutputIterator`, `OutputIterator1`, or `OutputIterator2`, the actual
547
- template argument shall satisfy the requirements of an output iterator (
548
- [[output.iterators]]). If an algorithm’s template parameter is
549
- `ForwardIterator`, `ForwardIterator1`, or `ForwardIterator2`, the actual
550
- template argument shall satisfy the requirements of a forward iterator (
551
- [[forward.iterators]]). If an algorithm’s template parameter is
552
- `BidirectionalIterator`, `BidirectionalIterator1`, or
553
- `BidirectionalIterator2`, the actual template argument shall satisfy the
554
- requirements of a bidirectional iterator ([[bidirectional.iterators]]).
555
- If an algorithm’s template parameter is `RandomAccessIterator`,
556
- `RandomAccessIterator1`, or `RandomAccessIterator2`, the actual template
 
 
 
 
557
  argument shall satisfy the requirements of a random-access iterator (
558
  [[random.access.iterators]]).
559
 
560
  If an algorithm’s section says that a value pointed to by any iterator
561
  passed as an argument is modified, then that algorithm has an additional
562
  type requirement: The type of that argument shall satisfy the
563
  requirements of a mutable iterator ([[iterator.requirements]]). This
564
- requirement does not affect arguments that are declared as
565
- `OutputIterator`, `OutputIterator1`, or `OutputIterator2`, because
566
- output iterators must always be mutable.
567
 
568
  Both in-place and copying versions are provided for certain
569
  algorithms.[^1] When such a version is provided for *algorithm* it is
570
  called *algorithm`_copy`*. Algorithms that take predicates end with the
571
  suffix `_if` (which follows the suffix `_copy`).
@@ -724,11 +763,11 @@ template<class ForwardIterator1, class ForwardIterator2,
724
  ```
725
 
726
  *Effects:* Finds a subsequence of equal values in a sequence.
727
 
728
  *Returns:* The last iterator `i` in the range \[`first1`,
729
- `last1 - (last2 - first2)`) such that for any non-negative integer
730
  `n < (last2 - first2)`, the following corresponding conditions hold:
731
  `*(i + n) == *(first2 + n), pred(*(i + n), *(first2 + n)) != false`.
732
  Returns `last1` if \[`first2`, `last2`) is empty or if no such iterator
733
  is found.
734
 
@@ -813,24 +852,39 @@ template<class InputIterator1, class InputIterator2>
813
  template<class InputIterator1, class InputIterator2,
814
  class BinaryPredicate>
815
  pair<InputIterator1, InputIterator2>
816
  mismatch(InputIterator1 first1, InputIterator1 last1,
817
  InputIterator2 first2, BinaryPredicate pred);
 
 
 
 
 
 
 
 
 
 
 
 
818
  ```
819
 
 
 
 
820
  *Returns:* A pair of iterators `i` and `j` such that
821
  `j == first2 + (i - first1)` and `i` is the first iterator in the range
822
  \[`first1`, `last1`) for which the following corresponding conditions
823
  hold:
824
 
825
- ``` cpp
826
- !(*i == *(first2 + (i - first1)))
827
- pred(*i, *(first2 + (i - first1))) == false
828
- ```
829
 
830
- Returns the pair `last1` and `first2 + (last1 - first1)` if such an
831
- iterator `i` is not found.
 
832
 
833
  *Complexity:* At most `last1 - first1` applications of the corresponding
834
  predicate.
835
 
836
  ### Equal <a id="alg.equal">[[alg.equal]]</a>
@@ -842,19 +896,36 @@ template<class InputIterator1, class InputIterator2>
842
 
843
  template<class InputIterator1, class InputIterator2,
844
  class BinaryPredicate>
845
  bool equal(InputIterator1 first1, InputIterator1 last1,
846
  InputIterator2 first2, BinaryPredicate pred);
 
 
 
 
 
 
 
 
 
 
847
  ```
848
 
849
- *Returns:* `true` if for every iterator `i` in the range \[`first1`,
850
- `last1`) the following corresponding conditions hold:
 
 
 
 
851
  `*i == *(first2 + (i - first1)), pred(*i, *(first2 + (i - first1))) != false`.
852
  Otherwise, returns `false`.
853
 
854
- *Complexity:* At most `last1 - first1` applications of the corresponding
855
- predicate.
 
 
 
856
 
857
  ### Is permutation <a id="alg.is_permutation">[[alg.is_permutation]]</a>
858
 
859
  ``` cpp
860
  template<class ForwardIterator1, class ForwardIterator2>
@@ -862,27 +933,43 @@ template<class ForwardIterator1, class ForwardIterator2>
862
  ForwardIterator2 first2);
863
  template<class ForwardIterator1, class ForwardIterator2,
864
  class BinaryPredicate>
865
  bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
866
  ForwardIterator2 first2, BinaryPredicate pred);
 
 
 
 
 
 
 
 
867
  ```
868
 
869
- *Requires:* : `ForwardIterator1` and `ForwardIterator2` shall have the
870
  same value type. The comparison function shall be an equivalence
871
  relation.
872
 
873
- *Returns:* `true` if there exists a permutation of the elements in the
874
- range \[`first2`, `first2 + (last1 - first1)`), beginning with
 
 
 
 
875
  `ForwardIterator2 begin`, such that `equal(first1, last1, begin)`
876
  returns `true` or `equal(first1, last1, begin, pred)` returns `true`;
877
  otherwise, returns `false`.
878
 
879
- *Complexity:* Exactly `distance(first1, last1)` applications of the
880
- corresponding predicate if `equal(first1, last1, first2)` would return
881
- `true` or `equal(first1, last1, first2, pred)` would return `true`;
882
- otherwise, at worst 𝑂(N^2), where N has the value
883
- `distance(first1, last1)`.
 
 
 
 
884
 
885
  ### Search <a id="alg.search">[[alg.search]]</a>
886
 
887
  ``` cpp
888
  template<class ForwardIterator1, class ForwardIterator2>
@@ -899,11 +986,11 @@ template<class ForwardIterator1, class ForwardIterator2,
899
  ```
900
 
901
  *Effects:* Finds a subsequence of equal values in a sequence.
902
 
903
  *Returns:* The first iterator `i` in the range \[`first1`,
904
- `last1 - (last2-first2)`) such that for any non-negative integer `n`
905
  less than `last2 - first2` the following corresponding conditions hold:
906
  `*(i + n) == *(first2 + n), pred(*(i + n), *(first2 + n)) != false`.
907
  Returns `first1` if \[`first2`, `last2`) is empty, otherwise returns
908
  `last1` if no such iterator is found.
909
 
@@ -927,11 +1014,11 @@ template<class ForwardIterator, class Size, class T,
927
  type ([[conv.integral]], [[class.conv]]).
928
 
929
  *Effects:* Finds a subsequence of equal values in a sequence.
930
 
931
  *Returns:* The first iterator `i` in the range \[`first`, `last-count`)
932
- such that for any non-negative integer `n` less than `count` the
933
  following corresponding conditions hold:
934
  `*(i + n) == value, pred(*(i + n),value) != false`. Returns `last` if no
935
  such iterator is found.
936
 
937
  *Complexity:* At most `last - first` applications of the corresponding
@@ -981,14 +1068,16 @@ template<class InputIterator, class OutputIterator, class Predicate>
981
  `result + (last - first)`) shall not overlap.
982
 
983
  *Effects:* Copies all of the elements referred to by the iterator `i` in
984
  the range \[`first`, `last`) for which `pred(*i)` is `true`.
985
 
 
 
986
  *Complexity:* Exactly `last - first` applications of the corresponding
987
  predicate.
988
 
989
- *Remarks:* Stable.
990
 
991
  ``` cpp
992
  template<class BidirectionalIterator1, class BidirectionalIterator2>
993
  BidirectionalIterator2
994
  copy_backward(BidirectionalIterator1 first,
@@ -1236,19 +1325,19 @@ requirements (Table  [[moveassignable]]).
1236
  the range \[`first`, `last`) for which the following corresponding
1237
  conditions hold: `*i == value, pred(*i) != false`.
1238
 
1239
  *Returns:* The end of the resulting range.
1240
 
1241
- *Remarks:* Stable.
1242
 
1243
  *Complexity:* Exactly `last - first` applications of the corresponding
1244
  predicate.
1245
 
1246
  *Note:* each element in the range \[`ret`, `last`), where `ret` is the
1247
  returned value, has a valid but unspecified state, because the
1248
- algorithms can eliminate elements by swapping with or moving from
1249
- elements that were originally in that range.
1250
 
1251
  ``` cpp
1252
  template<class InputIterator, class OutputIterator, class T>
1253
  OutputIterator
1254
  remove_copy(InputIterator first, InputIterator last,
@@ -1260,22 +1349,22 @@ template<class InputIterator, class OutputIterator, class Predicate>
1260
  OutputIterator result, Predicate pred);
1261
  ```
1262
 
1263
  *Requires:* The ranges \[`first`, `last`) and \[`result`,
1264
  `result + (last - first)`) shall not overlap. The expression
1265
- `*result = *first` shall ve valid.
1266
 
1267
  *Effects:* Copies all the elements referred to by the iterator `i` in
1268
  the range \[`first`, `last`) for which the following corresponding
1269
  conditions do not hold: `*i == value, pred(*i) != false`.
1270
 
1271
  *Returns:* The end of the resulting range.
1272
 
1273
  *Complexity:* Exactly `last - first` applications of the corresponding
1274
  predicate.
1275
 
1276
- *Remarks:* Stable.
1277
 
1278
  ### Unique <a id="alg.unique">[[alg.unique]]</a>
1279
 
1280
  ``` cpp
1281
  template<class ForwardIterator>
@@ -1337,13 +1426,12 @@ applications of the corresponding predicate.
1337
  ``` cpp
1338
  template<class BidirectionalIterator>
1339
  void reverse(BidirectionalIterator first, BidirectionalIterator last);
1340
  ```
1341
 
1342
- *Effects:* For each non-negative integer `i <= (last - first)/2`,
1343
- applies `iter_swap` to all pairs of iterators
1344
- `first + i, (last - i) - 1`.
1345
 
1346
  *Requires:* `*first` shall be swappable ([[swappable.requirements]]).
1347
 
1348
  *Complexity:* Exactly `(last - first)/2` swaps.
1349
 
@@ -1353,13 +1441,13 @@ template<class BidirectionalIterator, class OutputIterator>
1353
  reverse_copy(BidirectionalIterator first,
1354
  BidirectionalIterator last, OutputIterator result);
1355
  ```
1356
 
1357
  *Effects:* Copies the range \[`first`, `last`) to the range \[`result`,
1358
- `result+(last-first)`) such that for any non-negative integer
1359
  `i < (last - first)` the following assignment takes place:
1360
- `*(result + (last - first) - i) = *(first + i)`.
1361
 
1362
  *Requires:* The ranges \[`first`, `last`) and \[`result`,
1363
  `result+(last-first)`) shall not overlap.
1364
 
1365
  *Returns:* `result + (last - first)`.
@@ -1382,12 +1470,12 @@ the element from the position `first + i` into position
1382
 
1383
  *Remarks:* This is a left rotate.
1384
 
1385
  *Requires:* \[`first`, `middle`) and \[`middle`, `last`) shall be valid
1386
  ranges. `ForwardIterator` shall satisfy the requirements of
1387
- ValueSwappable ([[swappable.requirements]]). The type of `*first` shall
1388
- satisfy the requirements of `MoveConstructible`
1389
  (Table  [[moveconstructible]]) and the requirements of `MoveAssignable`
1390
  (Table  [[moveassignable]]).
1391
 
1392
  *Complexity:* At most `last - first` swaps.
1393
 
@@ -1408,22 +1496,13 @@ template<class ForwardIterator, class OutputIterator>
1408
  *Requires:* The ranges \[`first`, `last`) and \[`result`,
1409
  `result + (last - first)`) shall not overlap.
1410
 
1411
  *Complexity:* Exactly `last - first` assignments.
1412
 
1413
- ### Random shuffle <a id="alg.random.shuffle">[[alg.random.shuffle]]</a>
1414
 
1415
  ``` cpp
1416
- template<class RandomAccessIterator>
1417
- void random_shuffle(RandomAccessIterator first,
1418
- RandomAccessIterator last);
1419
-
1420
- template<class RandomAccessIterator, class RandomNumberGenerator>
1421
- void random_shuffle(RandomAccessIterator first,
1422
- RandomAccessIterator last,
1423
- RandomNumberGenerator&& rand);
1424
-
1425
  template<class RandomAccessIterator, class UniformRandomNumberGenerator>
1426
  void shuffle(RandomAccessIterator first,
1427
  RandomAccessIterator last,
1428
  UniformRandomNumberGenerator&& g);
1429
  ```
@@ -1431,35 +1510,20 @@ template<class RandomAccessIterator, class UniformRandomNumberGenerator>
1431
  *Effects:* Permutes the elements in the range \[`first`, `last`) such
1432
  that each possible permutation of those elements has equal probability
1433
  of appearance.
1434
 
1435
  *Requires:* `RandomAccessIterator` shall satisfy the requirements of
1436
- `ValueSwappable` ([[swappable.requirements]]). The random number
1437
- generating function object `rand` shall have a return type that is
1438
- convertible to `iterator_traits<RandomAccessIterator>::difference_type`,
1439
- and the call `rand(n)` shall return a randomly chosen value in the
1440
- interval \[`0`, `n`), for `n > 0` of type
1441
- `iterator_traits<RandomAccessIterator>::difference_type`. The type
1442
  `UniformRandomNumberGenerator` shall meet the requirements of a uniform
1443
  random number generator ([[rand.req.urng]]) type whose return type is
1444
  convertible to `iterator_traits<RandomAccessIterator>::difference_type`.
1445
 
1446
  *Complexity:* Exactly `(last - first) - 1` swaps.
1447
 
1448
- *Remarks:* To the extent that the implementation of these functions
1449
- makes use of random numbers, the implementation shall use the following
1450
- sources of randomness:
1451
-
1452
- The underlying source of random numbers for the first form of the
1453
- function is *implementation-defined*. An implementation may use the
1454
- `rand` function from the standard C library.
1455
-
1456
- In the second form of the function, the function object `rand` shall
1457
- serve as the implementation’s source of randomness.
1458
-
1459
- In the third `shuffle` form of the function, the object `g` shall serve
1460
- as the implementation’s source of randomness.
1461
 
1462
  ### Partitions <a id="alg.partitions">[[alg.partitions]]</a>
1463
 
1464
  ``` cpp
1465
  template <class InputIterator, class Predicate>
@@ -1483,12 +1547,12 @@ template<class ForwardIterator, class Predicate>
1483
  ```
1484
 
1485
  *Effects:* Places all the elements in the range \[`first`, `last`) that
1486
  satisfy `pred` before all the elements that do not satisfy it.
1487
 
1488
- *Returns:* An iterator `i` such that for any iterator `j` in the range
1489
- \[`first`, `i`) `pred(*j) != false`, and for any iterator `k` in the
1490
  range \[`i`, `last`), `pred(*k) == false`.
1491
 
1492
  *Requires:* `ForwardIterator` shall satisfy the requirements of
1493
  `ValueSwappable` ([[swappable.requirements]]).
1494
 
@@ -1505,12 +1569,12 @@ template<class BidirectionalIterator, class Predicate>
1505
  ```
1506
 
1507
  *Effects:* Places all the elements in the range \[`first`, `last`) that
1508
  satisfy `pred` before all the elements that do not satisfy it.
1509
 
1510
- *Returns:* An iterator `i` such that for any iterator `j` in the range
1511
- \[`first`, `i`), `pred(*j) != false`, and for any iterator `k` in the
1512
  range \[`i`, `last`), `pred(*k) == false`. The relative order of the
1513
  elements in both groups is preserved.
1514
 
1515
  *Requires:* `BidirectionalIterator` shall satisfy the requirements of
1516
  `ValueSwappable` ([[swappable.requirements]]). The type of `*first`
@@ -1529,13 +1593,13 @@ template <class InputIterator, class OutputIterator1,
1529
  partition_copy(InputIterator first, InputIterator last,
1530
  OutputIterator1 out_true, OutputIterator2 out_false,
1531
  Predicate pred);
1532
  ```
1533
 
1534
- *Requires:* `InputIterator`’s value type shall be Assignable, and shall
1535
- be writable to the `out_true` and `out_false` `OutputIterator`s, and
1536
- shall be convertible to `Predicate`’s argument type. The input range
1537
  shall not overlap with either of the output ranges.
1538
 
1539
  *Effects:* For each iterator `i` in \[`first`, `last`), copies `*i` to
1540
  the output range beginning with `out_true` if `pred(*i)` is `true`, or
1541
  to the output range beginning with `out_false` otherwise.
@@ -1570,15 +1634,15 @@ a function object of type `Compare` and one that uses an `operator<`.
1570
 
1571
  `Compare`
1572
 
1573
  is a function object type ([[function.objects]]). The return value of
1574
  the function call operation applied to an object of type `Compare`, when
1575
- contextually converted to `bool` ([[conv]]), yields `true` if the first
1576
- argument of the call is less than the second, and `false` otherwise.
1577
- `Compare comp` is used throughout for algorithms assuming an ordering
1578
- relation. It is assumed that `comp` will not apply any non-constant
1579
- function through the dereferenced iterator.
1580
 
1581
  For all algorithms that take `Compare`, there is a version that uses
1582
  `operator<` instead. That is, `comp(*i, *j) != false` defaults to
1583
  `*i < *j != false`. For algorithms other than those described in 
1584
  [[alg.binary.search]] to work correctly, `comp` has to induce a strict
@@ -1597,12 +1661,12 @@ for a partial ordering. If we define `equiv(a, b)` as
1597
  - `equiv` is an equivalence relation
1598
  - `comp` induces a well-defined relation on the equivalence classes
1599
  determined by `equiv`
1600
  - The induced relation is a strict total ordering.
1601
 
1602
- A sequence is *sorted with respect to a comparator* `comp` if for any
1603
- iterator `i` pointing to the sequence and any non-negative integer `n`
1604
  such that `i + n` is a valid iterator pointing to an element of the
1605
  sequence, `comp(*(i + n), *i) == false`.
1606
 
1607
  A sequence \[`start`, `finish`) is *partitioned with respect to an
1608
  expression* `f(e)` if there exists an integer `n` such that for all
@@ -1659,11 +1723,11 @@ shall satisfy the requirements of `MoveConstructible`
1659
  (Table  [[moveassignable]]).
1660
 
1661
  *Complexity:* It does at most N log²(N) (where N` == last - first`)
1662
  comparisons; if enough extra memory is available, it is N log(N).
1663
 
1664
- *Remarks:* Stable.
1665
 
1666
  #### `partial_sort` <a id="partial.sort">[[partial.sort]]</a>
1667
 
1668
  ``` cpp
1669
  template<class RandomAccessIterator>
@@ -1771,13 +1835,13 @@ template<class RandomAccessIterator, class Compare>
1771
  RandomAccessIterator last, Compare comp);
1772
  ```
1773
 
1774
  After `nth_element` the element in the position pointed to by `nth` is
1775
  the element that would be in that position if the whole range were
1776
- sorted. Also for any iterator `i` in the range \[`first`, `nth`) and any
1777
- iterator `j` in the range \[`nth`, `last`) it holds that: `!(*i > *j)`
1778
- or `comp(*j, *i) == false`.
1779
 
1780
  *Requires:* `RandomAccessIterator` shall satisfy the requirements of
1781
  `ValueSwappable` ([[swappable.requirements]]). The type of `*first`
1782
  shall satisfy the requirements of `MoveConstructible`
1783
  (Table  [[moveconstructible]]) and of `MoveAssignable`
@@ -1813,15 +1877,15 @@ template<class ForwardIterator, class T, class Compare>
1813
 
1814
  *Requires:* The elements `e` of \[`first`, `last`) shall be partitioned
1815
  with respect to the expression `e < value` or `comp(e, value)`.
1816
 
1817
  *Returns:* The furthermost iterator `i` in the range \[`first`, `last`\]
1818
- such that for any iterator `j` in the range \[`first`, `i`) the
1819
  following corresponding conditions hold: `*j < value` or
1820
  `comp(*j, value) != false`.
1821
 
1822
- *Complexity:* At most log₂(last - first) + 𝑂(1) comparisons.
1823
 
1824
  #### `upper_bound` <a id="upper.bound">[[upper.bound]]</a>
1825
 
1826
  ``` cpp
1827
  template<class ForwardIterator, class T>
@@ -1837,15 +1901,15 @@ template<class ForwardIterator, class T, class Compare>
1837
 
1838
  *Requires:* The elements `e` of \[`first`, `last`) shall be partitioned
1839
  with respect to the expression `!(value < e)` or `!comp(value, e)`.
1840
 
1841
  *Returns:* The furthermost iterator `i` in the range \[`first`, `last`\]
1842
- such that for any iterator `j` in the range \[`first`, `i`) the
1843
  following corresponding conditions hold: `!(value < *j)` or
1844
  `comp(value, *j) == false`.
1845
 
1846
- *Complexity:* At most log₂(last - first) + 𝑂(1) comparisons.
1847
 
1848
  #### `equal_range` <a id="equal.range">[[equal.range]]</a>
1849
 
1850
  ``` cpp
1851
  template<class ForwardIterator, class T>
@@ -1878,11 +1942,11 @@ or
1878
  ``` cpp
1879
  make_pair(lower_bound(first, last, value, comp),
1880
  upper_bound(first, last, value, comp))
1881
  ```
1882
 
1883
- *Complexity:* At most 2 * log₂(last - first) + 𝑂(1) comparisons.
1884
 
1885
  #### `binary_search` <a id="binary.search">[[binary.search]]</a>
1886
 
1887
  ``` cpp
1888
  template<class ForwardIterator, class T>
@@ -1903,11 +1967,11 @@ implies `!comp(value, e)`.
1903
  *Returns:* `true` if there is an iterator `i` in the range \[`first`,
1904
  `last`) that satisfies the corresponding conditions:
1905
  `!(*i < value) && !(value < *i)` or
1906
  `comp(*i, value) == false && comp(value, *i) == false`.
1907
 
1908
- *Complexity:* At most `log2(last - first)` + 𝑂(1) comparisons.
1909
 
1910
  ### Merge <a id="alg.merge">[[alg.merge]]</a>
1911
 
1912
  ``` cpp
1913
  template<class InputIterator1, class InputIterator2,
@@ -1939,11 +2003,11 @@ range shall not overlap with either of the original ranges.
1939
  *Returns:* `result + (last1 - first1) + (last2 - first2)`.
1940
 
1941
  *Complexity:* At most `(last1 - first1) + (last2 - first2) - 1`
1942
  comparisons.
1943
 
1944
- *Remarks:* Stable.
1945
 
1946
  ``` cpp
1947
  template<class BidirectionalIterator>
1948
  void inplace_merge(BidirectionalIterator first,
1949
  BidirectionalIterator middle,
@@ -1973,11 +2037,11 @@ shall satisfy the requirements of `MoveConstructible`
1973
  *Complexity:* When enough additional memory is available,
1974
  `(last - first) - 1` comparisons. If no additional memory is available,
1975
  an algorithm with complexity N log(N) (where `N` is equal to
1976
  `last - first`) may be used.
1977
 
1978
- *Remarks:* Stable.
1979
 
1980
  ### Set operations on sorted structures <a id="alg.set.operations">[[alg.set.operations]]</a>
1981
 
1982
  This section defines all the basic set operations on sorted structures.
1983
  They also work with `multiset`s ([[multiset]]) containing multiple
@@ -2293,13 +2357,13 @@ returns the last iterator `i` in \[`first`, `last`\] for which the range
2293
  *Complexity:* Linear.
2294
 
2295
  ### Minimum and maximum <a id="alg.min.max">[[alg.min.max]]</a>
2296
 
2297
  ``` cpp
2298
- template<class T> const T& min(const T& a, const T& b);
2299
  template<class T, class Compare>
2300
- const T& min(const T& a, const T& b, Compare comp);
2301
  ```
2302
 
2303
  *Requires:* Type `T` is `LessThanComparable`
2304
  (Table  [[lessthancomparable]]).
2305
 
@@ -2307,13 +2371,13 @@ template<class T, class Compare>
2307
 
2308
  *Remarks:* Returns the first argument when the arguments are equivalent.
2309
 
2310
  ``` cpp
2311
  template<class T>
2312
- T min(initializer_list<T> t);
2313
  template<class T, class Compare>
2314
- T min(initializer_list<T> t, Compare comp);
2315
  ```
2316
 
2317
  *Requires:* `T` is `LessThanComparable` and `CopyConstructible` and
2318
  `t.size() > 0`.
2319
 
@@ -2321,13 +2385,13 @@ template<class T, class Compare>
2321
 
2322
  *Remarks:* Returns a copy of the leftmost argument when several
2323
  arguments are equivalent to the smallest. 
2324
 
2325
  ``` cpp
2326
- template<class T> const T& max(const T& a, const T& b);
2327
  template<class T, class Compare>
2328
- const T& max(const T& a, const T& b, Compare comp);
2329
  ```
2330
 
2331
  *Requires:* Type `T` is `LessThanComparable`
2332
  (Table  [[lessthancomparable]]).
2333
 
@@ -2335,13 +2399,13 @@ template<class T, class Compare>
2335
 
2336
  *Remarks:* Returns the first argument when the arguments are equivalent.
2337
 
2338
  ``` cpp
2339
  template<class T>
2340
- T max(initializer_list<T> t);
2341
  template<class T, class Compare>
2342
- T max(initializer_list<T> t, Compare comp);
2343
  ```
2344
 
2345
  *Requires:* `T` is `LessThanComparable` and `CopyConstructible` and
2346
  `t.size() > 0`.
2347
 
@@ -2349,13 +2413,13 @@ template<class T, class Compare>
2349
 
2350
  *Remarks:* Returns a copy of the leftmost argument when several
2351
  arguments are equivalent to the largest.
2352
 
2353
  ``` cpp
2354
- template<class T> pair<const T&, const T&> minmax(const T& a, const T& b);
2355
  template<class T, class Compare>
2356
- pair<const T&, const T&> minmax(const T& a, const T& b, Compare comp);
2357
  ```
2358
 
2359
  *Requires:* Type `T` shall be `LessThanComparable`
2360
  (Table  [[lessthancomparable]]).
2361
 
@@ -2367,13 +2431,13 @@ are equivalent.
2367
 
2368
  *Complexity:* Exactly one comparison.
2369
 
2370
  ``` cpp
2371
  template<class T>
2372
- pair<T, T> minmax(initializer_list<T> t);
2373
  template<class T, class Compare>
2374
- pair<T, T> minmax(initializer_list<T> t, Compare comp);
2375
  ```
2376
 
2377
  *Requires:* `T` is `LessThanComparable` and `CopyConstructible` and
2378
  `t.size() > 0`.
2379
 
@@ -2395,13 +2459,13 @@ template<class ForwardIterator, class Compare>
2395
  ForwardIterator min_element(ForwardIterator first, ForwardIterator last,
2396
  Compare comp);
2397
  ```
2398
 
2399
  *Returns:* The first iterator `i` in the range \[`first`, `last`) such
2400
- that for any iterator `j` in the range \[`first`, `last`) the following
2401
- corresponding conditions hold: `!(*j < *i)` or `comp(*j, *i) == false`.
2402
- Returns `last` if `first == last`.
2403
 
2404
  *Complexity:* Exactly `max((last - first) - 1, 0)` applications of the
2405
  corresponding comparisons.
2406
 
2407
  ``` cpp
@@ -2411,13 +2475,13 @@ template<class ForwardIterator, class Compare>
2411
  ForwardIterator max_element(ForwardIterator first, ForwardIterator last,
2412
  Compare comp);
2413
  ```
2414
 
2415
  *Returns:* The first iterator `i` in the range \[`first`, `last`) such
2416
- that for any iterator `j` in the range \[`first`, `last`) the following
2417
- corresponding conditions hold: `!(*i < *j)` or `comp(*i, *j) == false`.
2418
- Returns `last` if `first == last`.
2419
 
2420
  *Complexity:* Exactly `max((last - first) - 1, 0)` applications of the
2421
  corresponding comparisons.
2422
 
2423
  ``` cpp
@@ -2620,10 +2684,11 @@ ISO C 7.10.5.
2620
  [alg.sort]: #alg.sort
2621
  [alg.sorting]: #alg.sorting
2622
  [alg.swap]: #alg.swap
2623
  [alg.transform]: #alg.transform
2624
  [alg.unique]: #alg.unique
 
2625
  [algorithms]: #algorithms
2626
  [algorithms.general]: #algorithms.general
2627
  [bidirectional.iterators]: iterators.md#bidirectional.iterators
2628
  [binary.search]: #binary.search
2629
  [class.conv]: special.md#class.conv
 
89
  <class InputIterator1, class InputIterator2, class BinaryPredicate>
90
  pair<InputIterator1, InputIterator2>
91
  mismatch(InputIterator1 first1, InputIterator1 last1,
92
  InputIterator2 first2, BinaryPredicate pred);
93
 
94
+ template<class InputIterator1, class InputIterator2>
95
+ pair<InputIterator1, InputIterator2>
96
+ mismatch(InputIterator1 first1, InputIterator1 last1,
97
+ InputIterator2 first2, InputIterator2 last2);
98
+
99
+ template
100
+ <class InputIterator1, class InputIterator2, class BinaryPredicate>
101
+ pair<InputIterator1, InputIterator2>
102
+ mismatch(InputIterator1 first1, InputIterator1 last1,
103
+ InputIterator2 first2, InputIterator2 last2,
104
+ BinaryPredicate pred);
105
+
106
  template<class InputIterator1, class InputIterator2>
107
  bool equal(InputIterator1 first1, InputIterator1 last1,
108
  InputIterator2 first2);
109
  template
110
  <class InputIterator1, class InputIterator2, class BinaryPredicate>
111
  bool equal(InputIterator1 first1, InputIterator1 last1,
112
  InputIterator2 first2, BinaryPredicate pred);
113
 
114
+ template<class InputIterator1, class InputIterator2>
115
+ bool equal(InputIterator1 first1, InputIterator1 last1,
116
+ InputIterator2 first2, InputIterator2 last2);
117
+
118
+ template
119
+ <class InputIterator1, class InputIterator2, class BinaryPredicate>
120
+ bool equal(InputIterator1 first1, InputIterator1 last1,
121
+ InputIterator2 first2, InputIterator2 last2,
122
+ BinaryPredicate pred);
123
+
124
  template<class ForwardIterator1, class ForwardIterator2>
125
  bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
126
  ForwardIterator2 first2);
127
  template<class ForwardIterator1, class ForwardIterator2,
128
  class BinaryPredicate>
129
  bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
130
  ForwardIterator2 first2, BinaryPredicate pred);
131
 
132
+ template<class ForwardIterator1, class ForwardIterator2>
133
+ bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
134
+ ForwardIterator2 first2, ForwardIterator2 last2);
135
+
136
+ template<class ForwardIterator1, class ForwardIterator2,
137
+ class BinaryPredicate>
138
+ bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
139
+ ForwardIterator2 first2, ForwardIterator2 last2,
140
+ BinaryPredicate pred);
141
+
142
  template<class ForwardIterator1, class ForwardIterator2>
143
  ForwardIterator1 search(
144
  ForwardIterator1 first1, ForwardIterator1 last1,
145
  ForwardIterator2 first2, ForwardIterator2 last2);
146
  template<class ForwardIterator1, class ForwardIterator2,
 
152
  template<class ForwardIterator, class Size, class T>
153
  ForwardIterator search_n(ForwardIterator first, ForwardIterator last,
154
  Size count, const T& value);
155
  template
156
  <class ForwardIterator, class Size, class T, class BinaryPredicate>
157
+ ForwardIterator search_n(ForwardIterator first, ForwardIterator last,
158
  Size count, const T& value,
159
  BinaryPredicate pred);
160
 
161
  // [alg.modifying.operations], modifying sequence operations:
162
  // [alg.copy], copy:
 
263
  template<class ForwardIterator, class OutputIterator>
264
  OutputIterator rotate_copy(
265
  ForwardIterator first, ForwardIterator middle,
266
  ForwardIterator last, OutputIterator result);
267
 
268
+ // [depr.alg.random.shuffle], random_shuffle (deprecated):
269
  template<class RandomAccessIterator>
270
  void random_shuffle(RandomAccessIterator first,
271
  RandomAccessIterator last);
272
  template<class RandomAccessIterator, class RandomNumberGenerator>
273
  void random_shuffle(RandomAccessIterator first,
274
  RandomAccessIterator last,
275
+ RandomNumberGenerator&& rng);
276
+
277
+ // [alg.random.shuffle], shuffle:
278
  template<class RandomAccessIterator, class UniformRandomNumberGenerator>
279
  void shuffle(RandomAccessIterator first,
280
  RandomAccessIterator last,
281
+ UniformRandomNumberGenerator&& g);
282
 
283
  // [alg.partitions], partitions:
284
  template <class InputIterator, class Predicate>
285
  bool is_partitioned(InputIterator first, InputIterator last, Predicate pred);
286
 
 
494
  template<class RandomAccessIterator, class Compare>
495
  RandomAccessIterator is_heap_until(RandomAccessIterator first, RandomAccessIterator last,
496
  Compare comp);
497
 
498
  // [alg.min.max], minimum and maximum:
499
+ template<class T> constexpr const T& min(const T& a, const T& b);
500
  template<class T, class Compare>
501
+ constexpr const T& min(const T& a, const T& b, Compare comp);
502
  template<class T>
503
+ constexpr T min(initializer_list<T> t);
504
  template<class T, class Compare>
505
+ constexpr T min(initializer_list<T> t, Compare comp);
506
 
507
+ template<class T> constexpr const T& max(const T& a, const T& b);
508
  template<class T, class Compare>
509
+ constexpr const T& max(const T& a, const T& b, Compare comp);
510
  template<class T>
511
+ constexpr T max(initializer_list<T> t);
512
  template<class T, class Compare>
513
+ constexpr T max(initializer_list<T> t, Compare comp);
514
 
515
+ template<class T> constexpr pair<const T&, const T&> minmax(const T& a, const T& b);
516
  template<class T, class Compare>
517
+ constexpr pair<const T&, const T&> minmax(const T& a, const T& b, Compare comp);
518
  template<class T>
519
+ constexpr pair<T, T> minmax(initializer_list<T> t);
520
  template<class T, class Compare>
521
+ constexpr pair<T, T> minmax(initializer_list<T> t, Compare comp);
522
 
523
  template<class ForwardIterator>
524
  ForwardIterator min_element(ForwardIterator first, ForwardIterator last);
525
  template<class ForwardIterator, class Compare>
526
  ForwardIterator min_element(ForwardIterator first, ForwardIterator last,
 
572
  For purposes of determining the existence of data races, algorithms
573
  shall not modify objects referenced through an iterator argument unless
574
  the specification requires such modification.
575
 
576
  Throughout this Clause, the names of template parameters are used to
577
+ express type requirements.
578
+
579
+ - If an algorithm’s template parameter is named `InputIterator`,
580
+ `InputIterator1`, or `InputIterator2`, the template argument shall
581
+ satisfy the requirements of an input iterator ([[input.iterators]]).
582
+ - If an algorithm’s template parameter is named `OutputIterator`,
583
+ `OutputIterator1`, or `OutputIterator2`, the template argument shall
584
+ satisfy the requirements of an output iterator (
585
+ [[output.iterators]]).
586
+ - If an algorithm’s template parameter is named `ForwardIterator`,
587
+ `ForwardIterator1`, or `ForwardIterator2`, the template argument shall
588
+ satisfy the requirements of a forward iterator (
589
+ [[forward.iterators]]).
590
+ - If an algorithm’s template parameter is named `BidirectionalIterator`,
591
+ `BidirectionalIterator1`, or `BidirectionalIterator2`, the template
592
+ argument shall satisfy the requirements of a bidirectional iterator (
593
+ [[bidirectional.iterators]]).
594
+ - If an algorithm’s template parameter is named `RandomAccessIterator`,
595
+ `RandomAccessIterator1`, or `RandomAccessIterator2`, the template
596
  argument shall satisfy the requirements of a random-access iterator (
597
  [[random.access.iterators]]).
598
 
599
  If an algorithm’s section says that a value pointed to by any iterator
600
  passed as an argument is modified, then that algorithm has an additional
601
  type requirement: The type of that argument shall satisfy the
602
  requirements of a mutable iterator ([[iterator.requirements]]). This
603
+ requirement does not affect arguments that are named `OutputIterator`,
604
+ `OutputIterator1`, or `OutputIterator2`, because output iterators must
605
+ always be mutable.
606
 
607
  Both in-place and copying versions are provided for certain
608
  algorithms.[^1] When such a version is provided for *algorithm* it is
609
  called *algorithm`_copy`*. Algorithms that take predicates end with the
610
  suffix `_if` (which follows the suffix `_copy`).
 
763
  ```
764
 
765
  *Effects:* Finds a subsequence of equal values in a sequence.
766
 
767
  *Returns:* The last iterator `i` in the range \[`first1`,
768
+ `last1 - (last2 - first2)`) such that for every non-negative integer
769
  `n < (last2 - first2)`, the following corresponding conditions hold:
770
  `*(i + n) == *(first2 + n), pred(*(i + n), *(first2 + n)) != false`.
771
  Returns `last1` if \[`first2`, `last2`) is empty or if no such iterator
772
  is found.
773
 
 
852
  template<class InputIterator1, class InputIterator2,
853
  class BinaryPredicate>
854
  pair<InputIterator1, InputIterator2>
855
  mismatch(InputIterator1 first1, InputIterator1 last1,
856
  InputIterator2 first2, BinaryPredicate pred);
857
+
858
+ template<class InputIterator1, class InputIterator2>
859
+ pair<InputIterator1, InputIterator2>
860
+ mismatch(InputIterator1 first1, InputIterator1 last1,
861
+ InputIterator2 first2, InputIterator2 last2);
862
+
863
+ template <class InputIterator1, class InputIterator2,
864
+ class BinaryPredicate>
865
+ pair<InputIterator1, InputIterator2>
866
+ mismatch(InputIterator1 first1, InputIterator1 last1,
867
+ InputIterator2 first2, InputIterator2 last2,
868
+ BinaryPredicate pred);
869
  ```
870
 
871
+ *Remarks:* If `last2` was not given in the argument list, it denotes
872
+ `first2 + (last1 - first1)` below.
873
+
874
  *Returns:* A pair of iterators `i` and `j` such that
875
  `j == first2 + (i - first1)` and `i` is the first iterator in the range
876
  \[`first1`, `last1`) for which the following corresponding conditions
877
  hold:
878
 
879
+ - `j` is in the range `[first2, last2)`.
880
+ - `!(*i == *(first2 + (i - first1)))`
881
+ - `pred(*i, *(first2 + (i - first1))) == false`
 
882
 
883
+ Returns the pair `first1 + min(last1 - first1, last2 - first2)` and
884
+ `first2 + min(last1 - first1, last2 - first2)` if such an iterator `i`
885
+ is not found.
886
 
887
  *Complexity:* At most `last1 - first1` applications of the corresponding
888
  predicate.
889
 
890
  ### Equal <a id="alg.equal">[[alg.equal]]</a>
 
896
 
897
  template<class InputIterator1, class InputIterator2,
898
  class BinaryPredicate>
899
  bool equal(InputIterator1 first1, InputIterator1 last1,
900
  InputIterator2 first2, BinaryPredicate pred);
901
+
902
+ template<class InputIterator1, class InputIterator2>
903
+ bool equal(InputIterator1 first1, InputIterator1 last1,
904
+ InputIterator2 first2, InputIterator2 last2);
905
+
906
+ template<class InputIterator1, class InputIterator2,
907
+ class BinaryPredicate>
908
+ bool equal(InputIterator1 first1, InputIterator1 last1,
909
+ InputIterator2 first2, InputIterator2 last2,
910
+ BinaryPredicate pred);
911
  ```
912
 
913
+ *Remarks:* If `last2` was not given in the argument list, it denotes
914
+ `first2 + (last1 - first1)` below.
915
+
916
+ *Returns:* If `last1 - first1 != last2 - first2`, return `false`.
917
+ Otherwise return `true` if for every iterator `i` in the range
918
+ \[`first1`, `last1`) the following corresponding conditions hold:
919
  `*i == *(first2 + (i - first1)), pred(*i, *(first2 + (i - first1))) != false`.
920
  Otherwise, returns `false`.
921
 
922
+ *Complexity:* No applications of the corresponding predicate if
923
+ `InputIterator1` and `InputIterator2` meet the requirements of random
924
+ access iterators and `last1 - first1 != last2 - first2`. Otherwise, at
925
+ most `min(last1 - first1, last2 - first2)` applications of the
926
+ corresponding predicate.
927
 
928
  ### Is permutation <a id="alg.is_permutation">[[alg.is_permutation]]</a>
929
 
930
  ``` cpp
931
  template<class ForwardIterator1, class ForwardIterator2>
 
933
  ForwardIterator2 first2);
934
  template<class ForwardIterator1, class ForwardIterator2,
935
  class BinaryPredicate>
936
  bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
937
  ForwardIterator2 first2, BinaryPredicate pred);
938
+ template<class ForwardIterator1, class ForwardIterator2>
939
+ bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
940
+ ForwardIterator2 first2, ForwardIterator2 last2);
941
+ template<class ForwardIterator1, class ForwardIterator2,
942
+ class BinaryPredicate>
943
+ bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
944
+ ForwardIterator2 first2, ForwardIterator2 last2,
945
+ BinaryPredicate pred);
946
  ```
947
 
948
+ *Requires:* `ForwardIterator1` and `ForwardIterator2` shall have the
949
  same value type. The comparison function shall be an equivalence
950
  relation.
951
 
952
+ *Remarks:* If `last2` was not given in the argument list, it denotes
953
+ `first2 + (last1 - first1)` below.
954
+
955
+ *Returns:* If `last1 - first1 != last2 - first2`, return `false`.
956
+ Otherwise return `true` if there exists a permutation of the elements in
957
+ the range \[`first2`, `first2 + (last1 - first1)`), beginning with
958
  `ForwardIterator2 begin`, such that `equal(first1, last1, begin)`
959
  returns `true` or `equal(first1, last1, begin, pred)` returns `true`;
960
  otherwise, returns `false`.
961
 
962
+ *Complexity:* No applications of the corresponding predicate if
963
+ `ForwardIterator1` and `ForwardIterator2` meet the requirements of
964
+ random access iterators and `last1 - first1 != last2 - first2`.
965
+ Otherwise, exactly `distance(first1, last1)` applications of the
966
+ corresponding predicate if `equal(first1, last1, first2, last2)` would
967
+ return `true` if `pred` was not given in the argument list or
968
+ `equal(first1, last1, first2, last2, pred)` would return `true` if pred
969
+ was given in the argument list; otherwise, at worst 𝑂(N^2), where N has
970
+ the value `distance(first1, last1)`.
971
 
972
  ### Search <a id="alg.search">[[alg.search]]</a>
973
 
974
  ``` cpp
975
  template<class ForwardIterator1, class ForwardIterator2>
 
986
  ```
987
 
988
  *Effects:* Finds a subsequence of equal values in a sequence.
989
 
990
  *Returns:* The first iterator `i` in the range \[`first1`,
991
+ `last1 - (last2-first2)`) such that for every non-negative integer `n`
992
  less than `last2 - first2` the following corresponding conditions hold:
993
  `*(i + n) == *(first2 + n), pred(*(i + n), *(first2 + n)) != false`.
994
  Returns `first1` if \[`first2`, `last2`) is empty, otherwise returns
995
  `last1` if no such iterator is found.
996
 
 
1014
  type ([[conv.integral]], [[class.conv]]).
1015
 
1016
  *Effects:* Finds a subsequence of equal values in a sequence.
1017
 
1018
  *Returns:* The first iterator `i` in the range \[`first`, `last-count`)
1019
+ such that for every non-negative integer `n` less than `count` the
1020
  following corresponding conditions hold:
1021
  `*(i + n) == value, pred(*(i + n),value) != false`. Returns `last` if no
1022
  such iterator is found.
1023
 
1024
  *Complexity:* At most `last - first` applications of the corresponding
 
1068
  `result + (last - first)`) shall not overlap.
1069
 
1070
  *Effects:* Copies all of the elements referred to by the iterator `i` in
1071
  the range \[`first`, `last`) for which `pred(*i)` is `true`.
1072
 
1073
+ *Returns:* The end of the resulting range.
1074
+
1075
  *Complexity:* Exactly `last - first` applications of the corresponding
1076
  predicate.
1077
 
1078
+ *Remarks:* Stable ([[algorithm.stable]]).
1079
 
1080
  ``` cpp
1081
  template<class BidirectionalIterator1, class BidirectionalIterator2>
1082
  BidirectionalIterator2
1083
  copy_backward(BidirectionalIterator1 first,
 
1325
  the range \[`first`, `last`) for which the following corresponding
1326
  conditions hold: `*i == value, pred(*i) != false`.
1327
 
1328
  *Returns:* The end of the resulting range.
1329
 
1330
+ *Remarks:* Stable ([[algorithm.stable]]).
1331
 
1332
  *Complexity:* Exactly `last - first` applications of the corresponding
1333
  predicate.
1334
 
1335
  *Note:* each element in the range \[`ret`, `last`), where `ret` is the
1336
  returned value, has a valid but unspecified state, because the
1337
+ algorithms can eliminate elements by moving from elements that were
1338
+ originally in that range.
1339
 
1340
  ``` cpp
1341
  template<class InputIterator, class OutputIterator, class T>
1342
  OutputIterator
1343
  remove_copy(InputIterator first, InputIterator last,
 
1349
  OutputIterator result, Predicate pred);
1350
  ```
1351
 
1352
  *Requires:* The ranges \[`first`, `last`) and \[`result`,
1353
  `result + (last - first)`) shall not overlap. The expression
1354
+ `*result = *first` shall be valid.
1355
 
1356
  *Effects:* Copies all the elements referred to by the iterator `i` in
1357
  the range \[`first`, `last`) for which the following corresponding
1358
  conditions do not hold: `*i == value, pred(*i) != false`.
1359
 
1360
  *Returns:* The end of the resulting range.
1361
 
1362
  *Complexity:* Exactly `last - first` applications of the corresponding
1363
  predicate.
1364
 
1365
+ *Remarks:* Stable ([[algorithm.stable]]).
1366
 
1367
  ### Unique <a id="alg.unique">[[alg.unique]]</a>
1368
 
1369
  ``` cpp
1370
  template<class ForwardIterator>
 
1426
  ``` cpp
1427
  template<class BidirectionalIterator>
1428
  void reverse(BidirectionalIterator first, BidirectionalIterator last);
1429
  ```
1430
 
1431
+ *Effects:* For each non-negative integer `i < (last - first)/2`, applies
1432
+ `iter_swap` to all pairs of iterators `first + i, (last - i) - 1`.
 
1433
 
1434
  *Requires:* `*first` shall be swappable ([[swappable.requirements]]).
1435
 
1436
  *Complexity:* Exactly `(last - first)/2` swaps.
1437
 
 
1441
  reverse_copy(BidirectionalIterator first,
1442
  BidirectionalIterator last, OutputIterator result);
1443
  ```
1444
 
1445
  *Effects:* Copies the range \[`first`, `last`) to the range \[`result`,
1446
+ `result+(last-first)`) such that for every non-negative integer
1447
  `i < (last - first)` the following assignment takes place:
1448
+ `*(result + (last - first) - 1 - i) = *(first + i)`.
1449
 
1450
  *Requires:* The ranges \[`first`, `last`) and \[`result`,
1451
  `result+(last-first)`) shall not overlap.
1452
 
1453
  *Returns:* `result + (last - first)`.
 
1470
 
1471
  *Remarks:* This is a left rotate.
1472
 
1473
  *Requires:* \[`first`, `middle`) and \[`middle`, `last`) shall be valid
1474
  ranges. `ForwardIterator` shall satisfy the requirements of
1475
+ `ValueSwappable` ([[swappable.requirements]]). The type of `*first`
1476
+ shall satisfy the requirements of `MoveConstructible`
1477
  (Table  [[moveconstructible]]) and the requirements of `MoveAssignable`
1478
  (Table  [[moveassignable]]).
1479
 
1480
  *Complexity:* At most `last - first` swaps.
1481
 
 
1496
  *Requires:* The ranges \[`first`, `last`) and \[`result`,
1497
  `result + (last - first)`) shall not overlap.
1498
 
1499
  *Complexity:* Exactly `last - first` assignments.
1500
 
1501
+ ### Shuffle <a id="alg.random.shuffle">[[alg.random.shuffle]]</a>
1502
 
1503
  ``` cpp
 
 
 
 
 
 
 
 
 
1504
  template<class RandomAccessIterator, class UniformRandomNumberGenerator>
1505
  void shuffle(RandomAccessIterator first,
1506
  RandomAccessIterator last,
1507
  UniformRandomNumberGenerator&& g);
1508
  ```
 
1510
  *Effects:* Permutes the elements in the range \[`first`, `last`) such
1511
  that each possible permutation of those elements has equal probability
1512
  of appearance.
1513
 
1514
  *Requires:* `RandomAccessIterator` shall satisfy the requirements of
1515
+ `ValueSwappable` ([[swappable.requirements]]). The type
 
 
 
 
 
1516
  `UniformRandomNumberGenerator` shall meet the requirements of a uniform
1517
  random number generator ([[rand.req.urng]]) type whose return type is
1518
  convertible to `iterator_traits<RandomAccessIterator>::difference_type`.
1519
 
1520
  *Complexity:* Exactly `(last - first) - 1` swaps.
1521
 
1522
+ *Remarks:* To the extent that the implementation of this function makes
1523
+ use of random numbers, the object `g` shall serve as the
1524
+ implementation’s source of randomness.
 
 
 
 
 
 
 
 
 
 
1525
 
1526
  ### Partitions <a id="alg.partitions">[[alg.partitions]]</a>
1527
 
1528
  ``` cpp
1529
  template <class InputIterator, class Predicate>
 
1547
  ```
1548
 
1549
  *Effects:* Places all the elements in the range \[`first`, `last`) that
1550
  satisfy `pred` before all the elements that do not satisfy it.
1551
 
1552
+ *Returns:* An iterator `i` such that for every iterator `j` in the range
1553
+ \[`first`, `i`) `pred(*j) != false`, and for every iterator `k` in the
1554
  range \[`i`, `last`), `pred(*k) == false`.
1555
 
1556
  *Requires:* `ForwardIterator` shall satisfy the requirements of
1557
  `ValueSwappable` ([[swappable.requirements]]).
1558
 
 
1569
  ```
1570
 
1571
  *Effects:* Places all the elements in the range \[`first`, `last`) that
1572
  satisfy `pred` before all the elements that do not satisfy it.
1573
 
1574
+ *Returns:* An iterator `i` such that for every iterator `j` in the range
1575
+ \[`first`, `i`), `pred(*j) != false`, and for every iterator `k` in the
1576
  range \[`i`, `last`), `pred(*k) == false`. The relative order of the
1577
  elements in both groups is preserved.
1578
 
1579
  *Requires:* `BidirectionalIterator` shall satisfy the requirements of
1580
  `ValueSwappable` ([[swappable.requirements]]). The type of `*first`
 
1593
  partition_copy(InputIterator first, InputIterator last,
1594
  OutputIterator1 out_true, OutputIterator2 out_false,
1595
  Predicate pred);
1596
  ```
1597
 
1598
+ *Requires:* `InputIterator`’s value type shall be `CopyAssignable`, and
1599
+ shall be writable to the `out_true` and `out_false` `OutputIterator`s,
1600
+ and shall be convertible to `Predicate`’s argument type. The input range
1601
  shall not overlap with either of the output ranges.
1602
 
1603
  *Effects:* For each iterator `i` in \[`first`, `last`), copies `*i` to
1604
  the output range beginning with `out_true` if `pred(*i)` is `true`, or
1605
  to the output range beginning with `out_false` otherwise.
 
1634
 
1635
  `Compare`
1636
 
1637
  is a function object type ([[function.objects]]). The return value of
1638
  the function call operation applied to an object of type `Compare`, when
1639
+ contextually converted to `bool` (Clause  [[conv]]), yields `true` if
1640
+ the first argument of the call is less than the second, and `false`
1641
+ otherwise. `Compare comp` is used throughout for algorithms assuming an
1642
+ ordering relation. It is assumed that `comp` will not apply any
1643
+ non-constant function through the dereferenced iterator.
1644
 
1645
  For all algorithms that take `Compare`, there is a version that uses
1646
  `operator<` instead. That is, `comp(*i, *j) != false` defaults to
1647
  `*i < *j != false`. For algorithms other than those described in 
1648
  [[alg.binary.search]] to work correctly, `comp` has to induce a strict
 
1661
  - `equiv` is an equivalence relation
1662
  - `comp` induces a well-defined relation on the equivalence classes
1663
  determined by `equiv`
1664
  - The induced relation is a strict total ordering.
1665
 
1666
+ A sequence is *sorted with respect to a comparator* `comp` if for every
1667
+ iterator `i` pointing to the sequence and every non-negative integer `n`
1668
  such that `i + n` is a valid iterator pointing to an element of the
1669
  sequence, `comp(*(i + n), *i) == false`.
1670
 
1671
  A sequence \[`start`, `finish`) is *partitioned with respect to an
1672
  expression* `f(e)` if there exists an integer `n` such that for all
 
1723
  (Table  [[moveassignable]]).
1724
 
1725
  *Complexity:* It does at most N log²(N) (where N` == last - first`)
1726
  comparisons; if enough extra memory is available, it is N log(N).
1727
 
1728
+ *Remarks:* Stable ([[algorithm.stable]]).
1729
 
1730
  #### `partial_sort` <a id="partial.sort">[[partial.sort]]</a>
1731
 
1732
  ``` cpp
1733
  template<class RandomAccessIterator>
 
1835
  RandomAccessIterator last, Compare comp);
1836
  ```
1837
 
1838
  After `nth_element` the element in the position pointed to by `nth` is
1839
  the element that would be in that position if the whole range were
1840
+ sorted, unless `nth == last`. Also for every iterator `i` in the range
1841
+ \[`first`, `nth`) and every iterator `j` in the range \[`nth`, `last`)
1842
+ it holds that: `!(*j < *i)` or `comp(*j, *i) == false`.
1843
 
1844
  *Requires:* `RandomAccessIterator` shall satisfy the requirements of
1845
  `ValueSwappable` ([[swappable.requirements]]). The type of `*first`
1846
  shall satisfy the requirements of `MoveConstructible`
1847
  (Table  [[moveconstructible]]) and of `MoveAssignable`
 
1877
 
1878
  *Requires:* The elements `e` of \[`first`, `last`) shall be partitioned
1879
  with respect to the expression `e < value` or `comp(e, value)`.
1880
 
1881
  *Returns:* The furthermost iterator `i` in the range \[`first`, `last`\]
1882
+ such that for every iterator `j` in the range \[`first`, `i`) the
1883
  following corresponding conditions hold: `*j < value` or
1884
  `comp(*j, value) != false`.
1885
 
1886
+ *Complexity:* At most log₂(`last - first`) + 𝑂(1) comparisons.
1887
 
1888
  #### `upper_bound` <a id="upper.bound">[[upper.bound]]</a>
1889
 
1890
  ``` cpp
1891
  template<class ForwardIterator, class T>
 
1901
 
1902
  *Requires:* The elements `e` of \[`first`, `last`) shall be partitioned
1903
  with respect to the expression `!(value < e)` or `!comp(value, e)`.
1904
 
1905
  *Returns:* The furthermost iterator `i` in the range \[`first`, `last`\]
1906
+ such that for every iterator `j` in the range \[`first`, `i`) the
1907
  following corresponding conditions hold: `!(value < *j)` or
1908
  `comp(value, *j) == false`.
1909
 
1910
+ *Complexity:* At most log₂(`last - first`) + 𝑂(1) comparisons.
1911
 
1912
  #### `equal_range` <a id="equal.range">[[equal.range]]</a>
1913
 
1914
  ``` cpp
1915
  template<class ForwardIterator, class T>
 
1942
  ``` cpp
1943
  make_pair(lower_bound(first, last, value, comp),
1944
  upper_bound(first, last, value, comp))
1945
  ```
1946
 
1947
+ *Complexity:* At most 2 * log₂(`last - first`) + 𝑂(1) comparisons.
1948
 
1949
  #### `binary_search` <a id="binary.search">[[binary.search]]</a>
1950
 
1951
  ``` cpp
1952
  template<class ForwardIterator, class T>
 
1967
  *Returns:* `true` if there is an iterator `i` in the range \[`first`,
1968
  `last`) that satisfies the corresponding conditions:
1969
  `!(*i < value) && !(value < *i)` or
1970
  `comp(*i, value) == false && comp(value, *i) == false`.
1971
 
1972
+ *Complexity:* At most log₂(`last - first`) + 𝑂(1) comparisons.
1973
 
1974
  ### Merge <a id="alg.merge">[[alg.merge]]</a>
1975
 
1976
  ``` cpp
1977
  template<class InputIterator1, class InputIterator2,
 
2003
  *Returns:* `result + (last1 - first1) + (last2 - first2)`.
2004
 
2005
  *Complexity:* At most `(last1 - first1) + (last2 - first2) - 1`
2006
  comparisons.
2007
 
2008
+ *Remarks:* Stable ([[algorithm.stable]]).
2009
 
2010
  ``` cpp
2011
  template<class BidirectionalIterator>
2012
  void inplace_merge(BidirectionalIterator first,
2013
  BidirectionalIterator middle,
 
2037
  *Complexity:* When enough additional memory is available,
2038
  `(last - first) - 1` comparisons. If no additional memory is available,
2039
  an algorithm with complexity N log(N) (where `N` is equal to
2040
  `last - first`) may be used.
2041
 
2042
+ *Remarks:* Stable ([[algorithm.stable]]).
2043
 
2044
  ### Set operations on sorted structures <a id="alg.set.operations">[[alg.set.operations]]</a>
2045
 
2046
  This section defines all the basic set operations on sorted structures.
2047
  They also work with `multiset`s ([[multiset]]) containing multiple
 
2357
  *Complexity:* Linear.
2358
 
2359
  ### Minimum and maximum <a id="alg.min.max">[[alg.min.max]]</a>
2360
 
2361
  ``` cpp
2362
+ template<class T> constexpr const T& min(const T& a, const T& b);
2363
  template<class T, class Compare>
2364
+ constexpr const T& min(const T& a, const T& b, Compare comp);
2365
  ```
2366
 
2367
  *Requires:* Type `T` is `LessThanComparable`
2368
  (Table  [[lessthancomparable]]).
2369
 
 
2371
 
2372
  *Remarks:* Returns the first argument when the arguments are equivalent.
2373
 
2374
  ``` cpp
2375
  template<class T>
2376
+ constexpr T min(initializer_list<T> t);
2377
  template<class T, class Compare>
2378
+ constexpr T min(initializer_list<T> t, Compare comp);
2379
  ```
2380
 
2381
  *Requires:* `T` is `LessThanComparable` and `CopyConstructible` and
2382
  `t.size() > 0`.
2383
 
 
2385
 
2386
  *Remarks:* Returns a copy of the leftmost argument when several
2387
  arguments are equivalent to the smallest. 
2388
 
2389
  ``` cpp
2390
+ template<class T> constexpr const T& max(const T& a, const T& b);
2391
  template<class T, class Compare>
2392
+ constexpr const T& max(const T& a, const T& b, Compare comp);
2393
  ```
2394
 
2395
  *Requires:* Type `T` is `LessThanComparable`
2396
  (Table  [[lessthancomparable]]).
2397
 
 
2399
 
2400
  *Remarks:* Returns the first argument when the arguments are equivalent.
2401
 
2402
  ``` cpp
2403
  template<class T>
2404
+ constexpr T max(initializer_list<T> t);
2405
  template<class T, class Compare>
2406
+ constexpr T max(initializer_list<T> t, Compare comp);
2407
  ```
2408
 
2409
  *Requires:* `T` is `LessThanComparable` and `CopyConstructible` and
2410
  `t.size() > 0`.
2411
 
 
2413
 
2414
  *Remarks:* Returns a copy of the leftmost argument when several
2415
  arguments are equivalent to the largest.
2416
 
2417
  ``` cpp
2418
+ template<class T> constexpr pair<const T&, const T&> minmax(const T& a, const T& b);
2419
  template<class T, class Compare>
2420
+ constexpr pair<const T&, const T&> minmax(const T& a, const T& b, Compare comp);
2421
  ```
2422
 
2423
  *Requires:* Type `T` shall be `LessThanComparable`
2424
  (Table  [[lessthancomparable]]).
2425
 
 
2431
 
2432
  *Complexity:* Exactly one comparison.
2433
 
2434
  ``` cpp
2435
  template<class T>
2436
+ constexpr pair<T, T> minmax(initializer_list<T> t);
2437
  template<class T, class Compare>
2438
+ constexpr pair<T, T> minmax(initializer_list<T> t, Compare comp);
2439
  ```
2440
 
2441
  *Requires:* `T` is `LessThanComparable` and `CopyConstructible` and
2442
  `t.size() > 0`.
2443
 
 
2459
  ForwardIterator min_element(ForwardIterator first, ForwardIterator last,
2460
  Compare comp);
2461
  ```
2462
 
2463
  *Returns:* The first iterator `i` in the range \[`first`, `last`) such
2464
+ that for every iterator `j` in the range \[`first`, `last`) the
2465
+ following corresponding conditions hold: `!(*j < *i)` or
2466
+ `comp(*j, *i) == false`. Returns `last` if `first == last`.
2467
 
2468
  *Complexity:* Exactly `max((last - first) - 1, 0)` applications of the
2469
  corresponding comparisons.
2470
 
2471
  ``` cpp
 
2475
  ForwardIterator max_element(ForwardIterator first, ForwardIterator last,
2476
  Compare comp);
2477
  ```
2478
 
2479
  *Returns:* The first iterator `i` in the range \[`first`, `last`) such
2480
+ that for every iterator `j` in the range \[`first`, `last`) the
2481
+ following corresponding conditions hold: `!(*i < *j)` or
2482
+ `comp(*i, *j) == false`. Returns `last` if `first == last`.
2483
 
2484
  *Complexity:* Exactly `max((last - first) - 1, 0)` applications of the
2485
  corresponding comparisons.
2486
 
2487
  ``` cpp
 
2684
  [alg.sort]: #alg.sort
2685
  [alg.sorting]: #alg.sorting
2686
  [alg.swap]: #alg.swap
2687
  [alg.transform]: #alg.transform
2688
  [alg.unique]: #alg.unique
2689
+ [algorithm.stable]: library.md#algorithm.stable
2690
  [algorithms]: #algorithms
2691
  [algorithms.general]: #algorithms.general
2692
  [bidirectional.iterators]: iterators.md#bidirectional.iterators
2693
  [binary.search]: #binary.search
2694
  [class.conv]: special.md#class.conv