From Jason Turner

[alg.nonmodifying]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpix419kw6/{from.md → to.md} +309 -42
tmp/tmpix419kw6/{from.md → to.md} RENAMED
@@ -85,10 +85,40 @@ Let E be:
85
  \[`first`, `last`), and `true` otherwise.
86
 
87
  *Complexity:* At most `last - first` applications of the predicate and
88
  any projection.
89
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
  ### For each <a id="alg.foreach">[[alg.foreach]]</a>
91
 
92
  ``` cpp
93
  template<class InputIterator, class Function>
94
  constexpr Function for_each(InputIterator first, InputIterator last, Function f);
@@ -103,11 +133,11 @@ requirements ([[cpp17.moveconstructible]]).
103
  *Effects:* Applies `f` to the result of dereferencing every iterator in
104
  the range \[`first`, `last`), starting from `first` and proceeding to
105
  `last - 1`.
106
 
107
  [*Note 2*: If the type of `first` meets the requirements of a mutable
108
- iterator, `f` may apply non-constant functions through the dereferenced
109
  iterator. — *end note*]
110
 
111
  *Returns:* `f`.
112
 
113
  *Complexity:* Applies `f` exactly `last - first` times.
@@ -126,22 +156,22 @@ requirements.
126
 
127
  *Effects:* Applies `f` to the result of dereferencing every iterator in
128
  the range \[`first`, `last`).
129
 
130
  [*Note 3*: If the type of `first` meets the requirements of a mutable
131
- iterator, `f` may apply non-constant functions through the dereferenced
132
  iterator. — *end note*]
133
 
134
  *Complexity:* Applies `f` exactly `last - first` times.
135
 
136
  *Remarks:* If `f` returns a result, the result is ignored.
137
  Implementations do not have the freedom granted under
138
  [[algorithms.parallel.exec]] to make arbitrary copies of elements from
139
  the input sequence.
140
 
141
  [*Note 4*: Does not return a copy of its `Function` parameter, since
142
- parallelization may not permit efficient state
143
  accumulation. — *end note*]
144
 
145
  ``` cpp
146
  template<input_iterator I, sentinel_for<I> S, class Proj = identity,
147
  indirectly_unary_invocable<projected<I, Proj>> Fun>
@@ -156,11 +186,11 @@ template<input_range R, class Proj = identity,
156
  *Effects:* Calls `invoke(f, invoke(proj, *i))` for every iterator `i` in
157
  the range \[`first`, `last`), starting from `first` and proceeding to
158
  `last - 1`.
159
 
160
  [*Note 5*: If the result of `invoke(proj, *i)` is a mutable reference,
161
- `f` may apply non-constant functions. — *end note*]
162
 
163
  *Returns:* `{last, std::move(f)}`.
164
 
165
  *Complexity:* Applies `f` and `proj` exactly `last - first` times.
166
 
@@ -173,25 +203,23 @@ the range \[`first`, `last`), starting from `first` and proceeding to
173
  template<class InputIterator, class Size, class Function>
174
  constexpr InputIterator for_each_n(InputIterator first, Size n, Function f);
175
  ```
176
 
177
  *Mandates:* The type `Size` is convertible to an integral
178
- type ([[conv.integral]], [[class.conv]]).
179
 
180
- *Preconditions:* `Function` meets the *Cpp17MoveConstructible*
181
- requirements.
182
 
183
  [*Note 7*: `Function` need not meet the requirements of
184
  *Cpp17CopyConstructible*. — *end note*]
185
 
186
- *Preconditions:* `n >= 0` is `true`.
187
-
188
  *Effects:* Applies `f` to the result of dereferencing every iterator in
189
  the range \[`first`, `first + n`) in order.
190
 
191
  [*Note 8*: If the type of `first` meets the requirements of a mutable
192
- iterator, `f` may apply non-constant functions through the dereferenced
193
  iterator. — *end note*]
194
 
195
  *Returns:* `first + n`.
196
 
197
  *Remarks:* If `f` returns a result, the result is ignored.
@@ -201,22 +229,20 @@ template<class ExecutionPolicy, class ForwardIterator, class Size, class Functio
201
  ForwardIterator for_each_n(ExecutionPolicy&& exec, ForwardIterator first, Size n,
202
  Function f);
203
  ```
204
 
205
  *Mandates:* The type `Size` is convertible to an integral
206
- type ([[conv.integral]], [[class.conv]]).
207
 
208
- *Preconditions:* `Function` meets the *Cpp17CopyConstructible*
209
- requirements.
210
-
211
- *Preconditions:* `n >= 0` is `true`.
212
 
213
  *Effects:* Applies `f` to the result of dereferencing every iterator in
214
  the range \[`first`, `first + n`).
215
 
216
  [*Note 9*: If the type of `first` meets the requirements of a mutable
217
- iterator, `f` may apply non-constant functions through the dereferenced
218
  iterator. — *end note*]
219
 
220
  *Returns:* `first + n`.
221
 
222
  *Remarks:* If `f` returns a result, the result is ignored.
@@ -235,11 +261,11 @@ template<input_iterator I, class Proj = identity,
235
 
236
  *Effects:* Calls `invoke(f, invoke(proj, *i))` for every iterator `i` in
237
  the range \[`first`, `first + n`) in order.
238
 
239
  [*Note 10*: If the result of `invoke(proj, *i)` is a mutable reference,
240
- `f` may apply non-constant functions. — *end note*]
241
 
242
  *Returns:* `{first + n, std::move(f)}`.
243
 
244
  *Remarks:* If `f` returns a result, the result is ignored.
245
 
@@ -307,10 +333,47 @@ Let E be:
307
  which E is `true`. Returns `last` if no such iterator is found.
308
 
309
  *Complexity:* At most `last - first` applications of the corresponding
310
  predicate and any projection.
311
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
312
  ### Find end <a id="alg.find.end">[[alg.find.end]]</a>
313
 
314
  ``` cpp
315
  template<class ForwardIterator1, class ForwardIterator2>
316
  constexpr ForwardIterator1
@@ -687,22 +750,28 @@ Let:
687
  - `invoke(pred, invoke(proj1, *i), invoke(proj2, *(first2 + (i - first1))))`
688
  for the overloads with parameter `proj1`.
689
 
690
  *Returns:* If `last1 - first1 != last2 - first2`, return `false`.
691
  Otherwise return `true` if E holds for every iterator `i` in the range
692
- \[`first1`, `last1`) Otherwise, returns `false`.
693
 
694
- *Complexity:* If the types of `first1`, `last1`, `first2`, and `last2`:
695
 
696
- - meet the *Cpp17RandomAccessIterator*
697
- requirements [[random.access.iterators]] for the overloads in
698
- namespace `std`;
699
- - pairwise model `sized_sentinel_for` [[iterator.concept.sizedsentinel]]
700
- for the overloads in namespace `ranges`,
 
 
 
 
 
 
701
 
702
- and `last1 - first1 != last2 - first2`, then no applications of the
703
- corresponding predicate and each projection; otherwise,
704
 
705
  - For the overloads with no `ExecutionPolicy`, at most
706
  min(`last1 - first1`, `last2 - first2`) applications of the
707
  corresponding predicate and any projections.
708
  - For the overloads with an `ExecutionPolicy`, 𝑂(min(`last1 - first1`,
@@ -726,34 +795,32 @@ template<class ForwardIterator1, class ForwardIterator2,
726
  constexpr bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
727
  ForwardIterator2 first2, ForwardIterator2 last2,
728
  BinaryPredicate pred);
729
  ```
730
 
 
 
 
 
731
  *Mandates:* `ForwardIterator1` and `ForwardIterator2` have the same
732
  value type.
733
 
734
  *Preconditions:* The comparison function is an equivalence relation.
735
 
736
- *Remarks:* If `last2` was not given in the argument list, it denotes
737
- `first2 + (last1 - first1)` below.
738
-
739
  *Returns:* If `last1 - first1 != last2 - first2`, return `false`.
740
  Otherwise return `true` if there exists a permutation of the elements in
741
- the range \[`first2`, `first2 + (last1 - first1)`), beginning with
742
- `ForwardIterator2 begin`, such that `equal(first1, last1, begin)`
743
- returns `true` or `equal(first1, last1, begin, pred)` returns `true`;
744
- otherwise, returns `false`.
745
 
746
  *Complexity:* No applications of the corresponding predicate if
747
  `ForwardIterator1` and `ForwardIterator2` meet the requirements of
748
  random access iterators and `last1 - first1 != last2 - first2`.
749
  Otherwise, exactly `last1 - first1` applications of the corresponding
750
- predicate if `equal(first1, last1, first2, last2)` would return `true`
751
- if `pred` was not given in the argument list or
752
- `equal(first1, last1, first2, last2, pred)` would return `true` if
753
- `pred` was given in the argument list; otherwise, at worst 𝑂(N^2), where
754
- N has the value `last1 - first1`.
755
 
756
  ``` cpp
757
  template<forward_iterator I1, sentinel_for<I1> S1, forward_iterator I2,
758
  sentinel_for<I2> S2, class Proj1 = identity, class Proj2 = identity,
759
  indirect_equivalence_relation<projected<I1, Proj1>,
@@ -776,13 +843,16 @@ that `ranges::equal(first1, last1, pfirst, plast, pred, proj1, proj2)`
776
  returns `true`; otherwise, returns `false`.
777
 
778
  *Complexity:* No applications of the corresponding predicate and
779
  projections if:
780
 
 
781
  - `S1` and `I1` model `sized_sentinel_for<S1, I1>`,
782
  - `S2` and `I2` model `sized_sentinel_for<S2, I2>`, and
783
- - `last1 - first1 != last2 - first2`.
 
 
784
 
785
  Otherwise, exactly `last1 - first1` applications of the corresponding
786
  predicate and projections if
787
  `ranges::equal(first1, last1, first2, last2, pred, proj1, proj2)` would
788
  return `true`; otherwise, at worst 𝑂(N^2), where N has the value
@@ -882,17 +952,17 @@ template<class ExecutionPolicy, class ForwardIterator, class Size, class T,
882
  Size count, const T& value,
883
  BinaryPredicate pred);
884
  ```
885
 
886
  *Mandates:* The type `Size` is convertible to an integral
887
- type ([[conv.integral]], [[class.conv]]).
888
 
889
  *Returns:* The first iterator `i` in the range \[`first`, `last-count`)
890
  such that for every non-negative integer `n` less than `count` the
891
  following corresponding conditions hold:
892
- `*(i + n) == value, pred(*(i + n),value) != false`. Returns `last` if no
893
- such iterator is found.
894
 
895
  *Complexity:* At most `last - first` applications of the corresponding
896
  predicate.
897
 
898
  ``` cpp
@@ -928,5 +998,202 @@ template<class ForwardIterator, class Searcher>
928
  *Effects:* Equivalent to: `return searcher(first, last).first;`
929
 
930
  *Remarks:* `Searcher` need not meet the *Cpp17CopyConstructible*
931
  requirements.
932
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
  \[`first`, `last`), and `true` otherwise.
86
 
87
  *Complexity:* At most `last - first` applications of the predicate and
88
  any projection.
89
 
90
+ ### Contains <a id="alg.contains">[[alg.contains]]</a>
91
+
92
+ ``` cpp
93
+ template<input_iterator I, sentinel_for<I> S, class T, class Proj = identity>
94
+ requires indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T*>
95
+ constexpr bool ranges::contains(I first, S last, const T& value, Proj proj = {});
96
+ template<input_range R, class T, class Proj = identity>
97
+ requires indirect_binary_predicate<ranges::equal_to, projected<iterator_t<R>, Proj>, const T*>
98
+ constexpr bool ranges::contains(R&& r, const T& value, Proj proj = {});
99
+ ```
100
+
101
+ *Returns:* `ranges::find(std::move(first), last, value, proj) != last`.
102
+
103
+ ``` cpp
104
+ template<forward_iterator I1, sentinel_for<I1> S1,
105
+ forward_iterator I2, sentinel_for<I2> S2,
106
+ class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
107
+ requires indirectly_comparable<I1, I2, Pred, Proj1, Proj2>
108
+ constexpr bool ranges::contains_subrange(I1 first1, S1 last1, I2 first2, S2 last2,
109
+ Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {});
110
+ template<forward_range R1, forward_range R2,
111
+ class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
112
+ requires indirectly_comparable<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
113
+ constexpr bool ranges::contains_subrange(R1&& r1, R2&& r2, Pred pred = {},
114
+ Proj1 proj1 = {}, Proj2 proj2 = {});
115
+ ```
116
+
117
+ *Returns:*
118
+ `first2 == last2 || !ranges::search(first1, last1, first2, last2, pred, proj1, proj2).empty()`.
119
+
120
  ### For each <a id="alg.foreach">[[alg.foreach]]</a>
121
 
122
  ``` cpp
123
  template<class InputIterator, class Function>
124
  constexpr Function for_each(InputIterator first, InputIterator last, Function f);
 
133
  *Effects:* Applies `f` to the result of dereferencing every iterator in
134
  the range \[`first`, `last`), starting from `first` and proceeding to
135
  `last - 1`.
136
 
137
  [*Note 2*: If the type of `first` meets the requirements of a mutable
138
+ iterator, `f` can apply non-constant functions through the dereferenced
139
  iterator. — *end note*]
140
 
141
  *Returns:* `f`.
142
 
143
  *Complexity:* Applies `f` exactly `last - first` times.
 
156
 
157
  *Effects:* Applies `f` to the result of dereferencing every iterator in
158
  the range \[`first`, `last`).
159
 
160
  [*Note 3*: If the type of `first` meets the requirements of a mutable
161
+ iterator, `f` can apply non-constant functions through the dereferenced
162
  iterator. — *end note*]
163
 
164
  *Complexity:* Applies `f` exactly `last - first` times.
165
 
166
  *Remarks:* If `f` returns a result, the result is ignored.
167
  Implementations do not have the freedom granted under
168
  [[algorithms.parallel.exec]] to make arbitrary copies of elements from
169
  the input sequence.
170
 
171
  [*Note 4*: Does not return a copy of its `Function` parameter, since
172
+ parallelization often does not permit efficient state
173
  accumulation. — *end note*]
174
 
175
  ``` cpp
176
  template<input_iterator I, sentinel_for<I> S, class Proj = identity,
177
  indirectly_unary_invocable<projected<I, Proj>> Fun>
 
186
  *Effects:* Calls `invoke(f, invoke(proj, *i))` for every iterator `i` in
187
  the range \[`first`, `last`), starting from `first` and proceeding to
188
  `last - 1`.
189
 
190
  [*Note 5*: If the result of `invoke(proj, *i)` is a mutable reference,
191
+ `f` can apply non-constant functions. — *end note*]
192
 
193
  *Returns:* `{last, std::move(f)}`.
194
 
195
  *Complexity:* Applies `f` and `proj` exactly `last - first` times.
196
 
 
203
  template<class InputIterator, class Size, class Function>
204
  constexpr InputIterator for_each_n(InputIterator first, Size n, Function f);
205
  ```
206
 
207
  *Mandates:* The type `Size` is convertible to an integral
208
+ type [[conv.integral]], [[class.conv]].
209
 
210
+ *Preconditions:* `n >= 0` is `true`. `Function` meets the
211
+ *Cpp17MoveConstructible* requirements.
212
 
213
  [*Note 7*: `Function` need not meet the requirements of
214
  *Cpp17CopyConstructible*. — *end note*]
215
 
 
 
216
  *Effects:* Applies `f` to the result of dereferencing every iterator in
217
  the range \[`first`, `first + n`) in order.
218
 
219
  [*Note 8*: If the type of `first` meets the requirements of a mutable
220
+ iterator, `f` can apply non-constant functions through the dereferenced
221
  iterator. — *end note*]
222
 
223
  *Returns:* `first + n`.
224
 
225
  *Remarks:* If `f` returns a result, the result is ignored.
 
229
  ForwardIterator for_each_n(ExecutionPolicy&& exec, ForwardIterator first, Size n,
230
  Function f);
231
  ```
232
 
233
  *Mandates:* The type `Size` is convertible to an integral
234
+ type [[conv.integral]], [[class.conv]].
235
 
236
+ *Preconditions:* `n >= 0` is `true`. `Function` meets the
237
+ *Cpp17CopyConstructible* requirements.
 
 
238
 
239
  *Effects:* Applies `f` to the result of dereferencing every iterator in
240
  the range \[`first`, `first + n`).
241
 
242
  [*Note 9*: If the type of `first` meets the requirements of a mutable
243
+ iterator, `f` can apply non-constant functions through the dereferenced
244
  iterator. — *end note*]
245
 
246
  *Returns:* `first + n`.
247
 
248
  *Remarks:* If `f` returns a result, the result is ignored.
 
261
 
262
  *Effects:* Calls `invoke(f, invoke(proj, *i))` for every iterator `i` in
263
  the range \[`first`, `first + n`) in order.
264
 
265
  [*Note 10*: If the result of `invoke(proj, *i)` is a mutable reference,
266
+ `f` can apply non-constant functions. — *end note*]
267
 
268
  *Returns:* `{first + n, std::move(f)}`.
269
 
270
  *Remarks:* If `f` returns a result, the result is ignored.
271
 
 
333
  which E is `true`. Returns `last` if no such iterator is found.
334
 
335
  *Complexity:* At most `last - first` applications of the corresponding
336
  predicate and any projection.
337
 
338
+ ### Find last <a id="alg.find.last">[[alg.find.last]]</a>
339
+
340
+ ``` cpp
341
+ template<forward_iterator I, sentinel_for<I> S, class T, class Proj = identity>
342
+ requires indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T*>
343
+ constexpr subrange<I> ranges::find_last(I first, S last, const T& value, Proj proj = {});
344
+ template<forward_range R, class T, class Proj = identity>
345
+ requires indirect_binary_predicate<ranges::equal_to, projected<iterator_t<R>, Proj>, const T*>
346
+ constexpr borrowed_subrange_t<R> ranges::find_last(R&& r, const T& value, Proj proj = {});
347
+ template<forward_iterator I, sentinel_for<I> S, class Proj = identity,
348
+ indirect_unary_predicate<projected<I, Proj>> Pred>
349
+ constexpr subrange<I> ranges::find_last_if(I first, S last, Pred pred, Proj proj = {});
350
+ template<forward_range R, class Proj = identity,
351
+ indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
352
+ constexpr borrowed_subrange_t<R> ranges::find_last_if(R&& r, Pred pred, Proj proj = {});
353
+ template<forward_iterator I, sentinel_for<I> S, class Proj = identity,
354
+ indirect_unary_predicate<projected<I, Proj>> Pred>
355
+ constexpr subrange<I> ranges::find_last_if_not(I first, S last, Pred pred, Proj proj = {});
356
+ template<forward_range R, class Proj = identity,
357
+ indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
358
+ constexpr borrowed_subrange_t<R> ranges::find_last_if_not(R&& r, Pred pred, Proj proj = {});
359
+ ```
360
+
361
+ Let E be:
362
+
363
+ - `bool(invoke(proj, *i) == value)` for `ranges::find_last`;
364
+ - `bool(invoke(pred, invoke(proj, *i)))` for `ranges::find_last_if`;
365
+ - `bool(!invoke(pred, invoke(proj, *i)))` for
366
+ `ranges::find_last_if_not`.
367
+
368
+ *Returns:* Let `i` be the last iterator in the range \[`first`, `last`)
369
+ for which E is `true`. Returns `{i, last}`, or `{last, last}` if no such
370
+ iterator is found.
371
+
372
+ *Complexity:* At most `last - first` applications of the corresponding
373
+ predicate and projection.
374
+
375
  ### Find end <a id="alg.find.end">[[alg.find.end]]</a>
376
 
377
  ``` cpp
378
  template<class ForwardIterator1, class ForwardIterator2>
379
  constexpr ForwardIterator1
 
750
  - `invoke(pred, invoke(proj1, *i), invoke(proj2, *(first2 + (i - first1))))`
751
  for the overloads with parameter `proj1`.
752
 
753
  *Returns:* If `last1 - first1 != last2 - first2`, return `false`.
754
  Otherwise return `true` if E holds for every iterator `i` in the range
755
+ \[`first1`, `last1`). Otherwise, returns `false`.
756
 
757
+ *Complexity:* If
758
 
759
+ - the types of `first1`, `last1`, `first2`, and `last2` meet the
760
+ *Cpp17RandomAccessIterator* requirements [[random.access.iterators]]
761
+ and `last1 - first1 != last2 - first2` for the overloads in namespace
762
+ `std`;
763
+ - the types of `first1`, `last1`, `first2`, and `last2` pairwise model
764
+ `sized_sentinel_for` [[iterator.concept.sizedsentinel]] and
765
+ `last1 - first1 != last2 - first2` for the first overload in namespace
766
+ `ranges`,
767
+ - `R1` and `R2` each model `sized_range` and
768
+ `ranges::distance(r1) != ranges::distance(r2)` for the second overload
769
+ in namespace `ranges`,
770
 
771
+ then no applications of the corresponding predicate and each projection;
772
+ otherwise,
773
 
774
  - For the overloads with no `ExecutionPolicy`, at most
775
  min(`last1 - first1`, `last2 - first2`) applications of the
776
  corresponding predicate and any projections.
777
  - For the overloads with an `ExecutionPolicy`, 𝑂(min(`last1 - first1`,
 
795
  constexpr bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
796
  ForwardIterator2 first2, ForwardIterator2 last2,
797
  BinaryPredicate pred);
798
  ```
799
 
800
+ Let `last2` be `first2 + (last1 - first1)` for the overloads with no
801
+ parameter named `last2`, and let `pred` be `equal_to{}` for the
802
+ overloads with no parameter `pred`.
803
+
804
  *Mandates:* `ForwardIterator1` and `ForwardIterator2` have the same
805
  value type.
806
 
807
  *Preconditions:* The comparison function is an equivalence relation.
808
 
 
 
 
809
  *Returns:* If `last1 - first1 != last2 - first2`, return `false`.
810
  Otherwise return `true` if there exists a permutation of the elements in
811
+ the range \[`first2`, `last2`), beginning with `ForwardIterator2 begin`,
812
+ such that `equal(first1, last1, begin, pred)` returns `true`; otherwise,
813
+ returns `false`.
 
814
 
815
  *Complexity:* No applications of the corresponding predicate if
816
  `ForwardIterator1` and `ForwardIterator2` meet the requirements of
817
  random access iterators and `last1 - first1 != last2 - first2`.
818
  Otherwise, exactly `last1 - first1` applications of the corresponding
819
+ predicate if `equal(first1, last1, first2, last2, pred)` would return
820
+ `true`; otherwise, at worst 𝑂(N^2), where N has the value
821
+ `last1 - first1`.
 
 
822
 
823
  ``` cpp
824
  template<forward_iterator I1, sentinel_for<I1> S1, forward_iterator I2,
825
  sentinel_for<I2> S2, class Proj1 = identity, class Proj2 = identity,
826
  indirect_equivalence_relation<projected<I1, Proj1>,
 
843
  returns `true`; otherwise, returns `false`.
844
 
845
  *Complexity:* No applications of the corresponding predicate and
846
  projections if:
847
 
848
+ - for the first overload,
849
  - `S1` and `I1` model `sized_sentinel_for<S1, I1>`,
850
  - `S2` and `I2` model `sized_sentinel_for<S2, I2>`, and
851
+ - `last1 - first1 != last2 - first2`;
852
+ - for the second overload, `R1` and `R2` each model `sized_range`, and
853
+ `ranges::distance(r1) != ranges::distance(r2)`.
854
 
855
  Otherwise, exactly `last1 - first1` applications of the corresponding
856
  predicate and projections if
857
  `ranges::equal(first1, last1, first2, last2, pred, proj1, proj2)` would
858
  return `true`; otherwise, at worst 𝑂(N^2), where N has the value
 
952
  Size count, const T& value,
953
  BinaryPredicate pred);
954
  ```
955
 
956
  *Mandates:* The type `Size` is convertible to an integral
957
+ type [[conv.integral]], [[class.conv]].
958
 
959
  *Returns:* The first iterator `i` in the range \[`first`, `last-count`)
960
  such that for every non-negative integer `n` less than `count` the
961
  following corresponding conditions hold:
962
+ `*(i + n) == value, pred(*(i + n), value) != false`. Returns `last` if
963
+ no such iterator is found.
964
 
965
  *Complexity:* At most `last - first` applications of the corresponding
966
  predicate.
967
 
968
  ``` cpp
 
998
  *Effects:* Equivalent to: `return searcher(first, last).first;`
999
 
1000
  *Remarks:* `Searcher` need not meet the *Cpp17CopyConstructible*
1001
  requirements.
1002
 
1003
+ ### Starts with <a id="alg.starts.with">[[alg.starts.with]]</a>
1004
+
1005
+ ``` cpp
1006
+ template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2,
1007
+ class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
1008
+ requires indirectly_comparable<I1, I2, Pred, Proj1, Proj2>
1009
+ constexpr bool ranges::starts_with(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {},
1010
+ Proj1 proj1 = {}, Proj2 proj2 = {});
1011
+ template<input_range R1, input_range R2, class Pred = ranges::equal_to, class Proj1 = identity,
1012
+ class Proj2 = identity>
1013
+ requires indirectly_comparable<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
1014
+ constexpr bool ranges::starts_with(R1&& r1, R2&& r2, Pred pred = {},
1015
+ Proj1 proj1 = {}, Proj2 proj2 = {});
1016
+ ```
1017
+
1018
+ *Returns:*
1019
+
1020
+ ``` cpp
1021
+ ranges::mismatch(std::move(first1), last1, std::move(first2), last2,
1022
+ pred, proj1, proj2).in2 == last2
1023
+ ```
1024
+
1025
+ ### Ends with <a id="alg.ends.with">[[alg.ends.with]]</a>
1026
+
1027
+ ``` cpp
1028
+ template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2,
1029
+ class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
1030
+ requires (forward_iterator<I1> || sized_sentinel_for<S1, I1>) &&
1031
+ (forward_iterator<I2> || sized_sentinel_for<S2, I2>) &&
1032
+ indirectly_comparable<I1, I2, Pred, Proj1, Proj2>
1033
+ constexpr bool ranges::ends_with(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {},
1034
+ Proj1 proj1 = {}, Proj2 proj2 = {});
1035
+ ```
1036
+
1037
+ Let `N1` be `last1 - first1` and `N2` be `last2 - first2`.
1038
+
1039
+ *Returns:* `false` if `N1` < `N2`, otherwise
1040
+
1041
+ ``` cpp
1042
+ ranges::equal(std::move(first1) + (N1 - N2), last1, std::move(first2), last2,
1043
+ pred, proj1, proj2)
1044
+ ```
1045
+
1046
+ ``` cpp
1047
+ template<input_range R1, input_range R2, class Pred = ranges::equal_to, class Proj1 = identity,
1048
+ class Proj2 = identity>
1049
+ requires (forward_range<R1> || sized_range<R1>) &&
1050
+ (forward_range<R2> || sized_range<R2>) &&
1051
+ indirectly_comparable<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
1052
+ constexpr bool ranges::ends_with(R1&& r1, R2&& r2, Pred pred = {},
1053
+ Proj1 proj1 = {}, Proj2 proj2 = {});
1054
+ ```
1055
+
1056
+ Let `N1` be `ranges::distance(r1)` and `N2` be `ranges::distance(r2)`.
1057
+
1058
+ *Returns:* `false` if `N1` < `N2`, otherwise
1059
+
1060
+ ``` cpp
1061
+ ranges::equal(ranges::drop_view(ranges::ref_view(r1), N1 - N2), r2, pred, proj1, proj2)
1062
+ ```
1063
+
1064
+ ### Fold <a id="alg.fold">[[alg.fold]]</a>
1065
+
1066
+ ``` cpp
1067
+ template<input_iterator I, sentinel_for<I> S, class T, indirectly-binary-left-foldable<T, I> F>
1068
+ constexpr auto ranges::fold_left(I first, S last, T init, F f);
1069
+ template<input_range R, class T, indirectly-binary-left-foldable<T, iterator_t<R>> F>
1070
+ constexpr auto ranges::fold_left(R&& r, T init, F f);
1071
+ ```
1072
+
1073
+ *Returns:*
1074
+
1075
+ ``` cpp
1076
+ ranges::fold_left_with_iter(std::move(first), last, std::move(init), f).value
1077
+ ```
1078
+
1079
+ ``` cpp
1080
+ template<input_iterator I, sentinel_for<I> S,
1081
+ indirectly-binary-left-foldable<iter_value_t<I>, I> F>
1082
+ requires constructible_from<iter_value_t<I>, iter_reference_t<I>>
1083
+ constexpr auto ranges::fold_left_first(I first, S last, F f);
1084
+ template<input_range R, indirectly-binary-left-foldable<range_value_t<R>, iterator_t<R>> F>
1085
+ requires constructible_from<range_value_t<R>, range_reference_t<R>>
1086
+ constexpr auto ranges::fold_left_first(R&& r, F f);
1087
+ ```
1088
+
1089
+ *Returns:*
1090
+
1091
+ ``` cpp
1092
+ ranges::fold_left_first_with_iter(std::move(first), last, f).value
1093
+ ```
1094
+
1095
+ ``` cpp
1096
+ template<bidirectional_iterator I, sentinel_for<I> S, class T,
1097
+ indirectly-binary-right-foldable<T, I> F>
1098
+ constexpr auto ranges::fold_right(I first, S last, T init, F f);
1099
+ template<bidirectional_range R, class T,
1100
+ indirectly-binary-right-foldable<T, iterator_t<R>> F>
1101
+ constexpr auto ranges::fold_right(R&& r, T init, F f);
1102
+ ```
1103
+
1104
+ *Effects:* Equivalent to:
1105
+
1106
+ ``` cpp
1107
+ using U = decay_t<invoke_result_t<F&, iter_reference_t<I>, T>>;
1108
+ if (first == last)
1109
+ return U(std::move(init));
1110
+ I tail = ranges::next(first, last);
1111
+ U accum = invoke(f, *--tail, std::move(init));
1112
+ while (first != tail)
1113
+ accum = invoke(f, *--tail, std::move(accum));
1114
+ return accum;
1115
+ ```
1116
+
1117
+ ``` cpp
1118
+ template<bidirectional_iterator I, sentinel_for<I> S,
1119
+ indirectly-binary-right-foldable<iter_value_t<I>, I> F>
1120
+ requires constructible_from<iter_value_t<I>, iter_reference_t<I>>
1121
+ constexpr auto ranges::fold_right_last(I first, S last, F f);
1122
+ template<bidirectional_range R,
1123
+ indirectly-binary-right-foldable<range_value_t<R>, iterator_t<R>> F>
1124
+ requires constructible_from<range_value_t<R>, range_reference_t<R>>
1125
+ constexpr auto ranges::fold_right_last(R&& r, F f);
1126
+ ```
1127
+
1128
+ Let `U` be
1129
+ `decltype(ranges::fold_right(first, last, iter_value_t<I>(*first), f))`.
1130
+
1131
+ *Effects:* Equivalent to:
1132
+
1133
+ ``` cpp
1134
+ if (first == last)
1135
+ return optional<U>();
1136
+ I tail = ranges::prev(ranges::next(first, std::move(last)));
1137
+ return optional<U>(in_place,
1138
+ ranges::fold_right(std::move(first), tail, iter_value_t<I>(*tail), std::move(f)));
1139
+ ```
1140
+
1141
+ ``` cpp
1142
+ template<input_iterator I, sentinel_for<I> S, class T,
1143
+ indirectly-binary-left-foldable<T, I> F>
1144
+ constexpr see below ranges::fold_left_with_iter(I first, S last, T init, F f);
1145
+ template<input_range R, class T, indirectly-binary-left-foldable<T, iterator_t<R>> F>
1146
+ constexpr see below ranges::fold_left_with_iter(R&& r, T init, F f);
1147
+ ```
1148
+
1149
+ Let `U` be `decay_t<invoke_result_t<F&, T, iter_reference_t<I>>>`.
1150
+
1151
+ *Effects:* Equivalent to:
1152
+
1153
+ ``` cpp
1154
+ if (first == last)
1155
+ return {std::move(first), U(std::move(init))};
1156
+ U accum = invoke(f, std::move(init), *first);
1157
+ for (++first; first != last; ++first)
1158
+ accum = invoke(f, std::move(accum), *first);
1159
+ return {std::move(first), std::move(accum)};
1160
+ ```
1161
+
1162
+ *Remarks:* The return type is `fold_left_with_iter_result<I, U>` for the
1163
+ first overload and
1164
+ `fold_left_with_iter_result<borrowed_iterator_t<R>, U>` for the second
1165
+ overload.
1166
+
1167
+ ``` cpp
1168
+ template<input_iterator I, sentinel_for<I> S,
1169
+ indirectly-binary-left-foldable<iter_value_t<I>, I> F>
1170
+ requires constructible_from<iter_value_t<I>, iter_reference_t<I>>
1171
+ constexpr see below ranges::fold_left_first_with_iter(I first, S last, F f);
1172
+ template<input_range R, indirectly-binary-left-foldable<range_value_t<R>, iterator_t<R>> F>
1173
+ requires constructible_from<range_value_t<R>, range_reference_t<R>>
1174
+ constexpr see below ranges::fold_left_first_with_iter(R&& r, F f);
1175
+ ```
1176
+
1177
+ Let `U` be
1178
+
1179
+ ``` cpp
1180
+ decltype(ranges::fold_left(std::move(first), last, iter_value_t<I>(*first), f))
1181
+ ```
1182
+
1183
+ *Effects:* Equivalent to:
1184
+
1185
+ ``` cpp
1186
+ if (first == last)
1187
+ return {std::move(first), optional<U>()};
1188
+ optional<U> init(in_place, *first);
1189
+ for (++first; first != last; ++first)
1190
+ *init = invoke(f, std::move(*init), *first);
1191
+ return {std::move(first), std::move(init)};
1192
+ ```
1193
+
1194
+ *Remarks:* The return type is
1195
+ `fold_left_first_with_iter_result<I, optional<U>>` for the first
1196
+ overload and
1197
+ `fold_left_first_with_iter_result<borrowed_iterator_t<R>, optional<U>>`
1198
+ for the second overload.
1199
+