From Jason Turner

[alg.modifying.operations]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmplzs9879w/{from.md → to.md} +308 -187
tmp/tmplzs9879w/{from.md → to.md} RENAMED
@@ -6,25 +6,47 @@
6
  template<class InputIterator, class OutputIterator>
7
  OutputIterator copy(InputIterator first, InputIterator last,
8
  OutputIterator result);
9
  ```
10
 
 
 
11
  *Effects:* Copies elements in the range \[`first`, `last`) into the
12
  range \[`result`, `result + (last - first)`) starting from `first` and
13
  proceeding to `last`. For each non-negative integer
14
  `n < (last - first)`, performs `*(result + n) = *(first + n)`.
15
 
16
  *Returns:* `result + (last - first)`.
17
 
18
- *Requires:* `result` shall not be in the range \[`first`, `last`).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
  *Complexity:* Exactly `last - first` assignments.
21
 
22
  ``` cpp
23
  template<class InputIterator, class Size, class OutputIterator>
24
  OutputIterator copy_n(InputIterator first, Size n,
25
  OutputIterator result);
 
 
 
 
26
  ```
27
 
28
  *Effects:* For each non-negative integer i < n, performs
29
  `*(result + i) = *(first + i)`.
30
 
@@ -34,15 +56,24 @@ template<class InputIterator, class Size, class OutputIterator>
34
 
35
  ``` cpp
36
  template<class InputIterator, class OutputIterator, class Predicate>
37
  OutputIterator copy_if(InputIterator first, InputIterator last,
38
  OutputIterator result, Predicate pred);
 
 
 
 
39
  ```
40
 
41
  *Requires:* The ranges \[`first`, `last`) and \[`result`,
42
  `result + (last - first)`) shall not overlap.
43
 
 
 
 
 
 
44
  *Effects:* Copies all of the elements referred to by the iterator `i` in
45
  the range \[`first`, `last`) for which `pred(*i)` is `true`.
46
 
47
  *Returns:* The end of the resulting range.
48
 
@@ -57,135 +88,182 @@ template<class BidirectionalIterator1, class BidirectionalIterator2>
57
  copy_backward(BidirectionalIterator1 first,
58
  BidirectionalIterator1 last,
59
  BidirectionalIterator2 result);
60
  ```
61
 
 
 
62
  *Effects:* Copies elements in the range \[`first`, `last`) into the
63
  range \[`result - (last-first)`, `result`) starting from `last - 1` and
64
  proceeding to `first`.[^2] For each positive integer
65
  `n <= (last - first)`, performs `*(result - n) = *(last - n)`.
66
 
67
- *Requires:* `result` shall not be in the range (`first`, `last`).
68
-
69
  *Returns:* `result - (last - first)`.
70
 
71
  *Complexity:* Exactly `last - first` assignments.
72
 
73
  ### Move <a id="alg.move">[[alg.move]]</a>
74
 
75
  ``` cpp
76
  template<class InputIterator, class OutputIterator>
77
- OutputIterator move(InputIterator first, InputIterator last,
78
- OutputIterator result);
79
  ```
80
 
 
 
81
  *Effects:* Moves elements in the range \[`first`, `last`) into the range
82
  \[`result`, `result + (last - first)`) starting from first and
83
  proceeding to last. For each non-negative integer `n < (last-first)`,
84
  performs `*(result + n)` `= std::move(*(first + n))`.
85
 
86
  *Returns:* `result + (last - first)`.
87
 
88
- *Requires:* `result` shall not be in the range \[`first`, `last`).
89
-
90
  *Complexity:* Exactly `last - first` move assignments.
91
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
  ``` cpp
93
  template<class BidirectionalIterator1, class BidirectionalIterator2>
94
  BidirectionalIterator2
95
  move_backward(BidirectionalIterator1 first,
96
  BidirectionalIterator1 last,
97
  BidirectionalIterator2 result);
98
  ```
99
 
 
 
100
  *Effects:* Moves elements in the range \[`first`, `last`) into the range
101
  \[`result - (last-first)`, `result`) starting from `last - 1` and
102
  proceeding to first.[^3] For each positive integer
103
  `n <= (last - first)`, performs
104
  `*(result - n) = std::move(*(last - n))`.
105
 
106
- *Requires:* `result` shall not be in the range (`first`, `last`).
107
-
108
  *Returns:* `result - (last - first)`.
109
 
110
  *Complexity:* Exactly `last - first` assignments.
111
 
112
- ### swap <a id="alg.swap">[[alg.swap]]</a>
113
 
114
  ``` cpp
115
  template<class ForwardIterator1, class ForwardIterator2>
116
  ForwardIterator2
117
  swap_ranges(ForwardIterator1 first1, ForwardIterator1 last1,
118
  ForwardIterator2 first2);
 
 
 
 
 
119
  ```
120
 
121
- *Effects:* For each non-negative integer `n < (last1 - first1)`
122
- performs: `swap(*(first1 + n), *(first2 + n))`.
123
-
124
  *Requires:* The two ranges \[`first1`, `last1`) and \[`first2`,
125
  `first2 + (last1 - first1)`) shall not overlap. `*(first1 + n)` shall be
126
  swappable with ([[swappable.requirements]]) `*(first2 + n)`.
127
 
 
 
 
128
  *Returns:* `first2 + (last1 - first1)`.
129
 
130
  *Complexity:* Exactly `last1 - first1` swaps.
131
 
132
  ``` cpp
133
  template<class ForwardIterator1, class ForwardIterator2>
134
  void iter_swap(ForwardIterator1 a, ForwardIterator2 b);
135
  ```
136
 
137
- *Effects:* `swap(*a, *b)`.
138
-
139
  *Requires:* `a` and `b` shall be dereferenceable. `*a` shall be
140
  swappable with ([[swappable.requirements]]) `*b`.
141
 
 
 
142
  ### Transform <a id="alg.transform">[[alg.transform]]</a>
143
 
144
  ``` cpp
145
  template<class InputIterator, class OutputIterator,
146
  class UnaryOperation>
147
  OutputIterator
148
  transform(InputIterator first, InputIterator last,
149
  OutputIterator result, UnaryOperation op);
 
 
 
 
 
 
150
 
151
  template<class InputIterator1, class InputIterator2,
152
  class OutputIterator, class BinaryOperation>
153
  OutputIterator
154
  transform(InputIterator1 first1, InputIterator1 last1,
155
  InputIterator2 first2, OutputIterator result,
156
  BinaryOperation binary_op);
 
 
 
 
 
 
 
157
  ```
158
 
 
 
 
 
 
 
 
159
  *Effects:* Assigns through every iterator `i` in the range \[`result`,
160
  `result + (last1 - first1)`) a new corresponding value equal to
161
- `op(*(first1 + (i - result))` or
162
  `binary_op(*(first1 + (i - result)), *(first2 + (i - result)))`.
163
 
164
- *Requires:* `op` and `binary_op` shall not invalidate iterators or
165
- subranges, or modify elements in the ranges \[`first1`, `last1`\],
166
- \[`first2`, `first2 + (last1 - first1)`\], and \[`result`,
167
- `result + (last1 - first1)`\].[^4]
168
-
169
  *Returns:* `result + (last1 - first1)`.
170
 
171
  *Complexity:* Exactly `last1 - first1` applications of `op` or
172
- `binary_op`.
 
173
 
174
  *Remarks:* `result` may be equal to `first` in case of unary transform,
175
  or to `first1` or `first2` in case of binary transform.
176
 
177
  ### Replace <a id="alg.replace">[[alg.replace]]</a>
178
 
179
  ``` cpp
180
  template<class ForwardIterator, class T>
181
  void replace(ForwardIterator first, ForwardIterator last,
182
  const T& old_value, const T& new_value);
 
 
 
 
183
 
184
  template<class ForwardIterator, class Predicate, class T>
185
  void replace_if(ForwardIterator first, ForwardIterator last,
186
  Predicate pred, const T& new_value);
 
 
 
 
187
  ```
188
 
189
  *Requires:* The expression `*first = new_value` shall be valid.
190
 
191
  *Effects:* Substitutes elements referred by the iterator `i` in the
@@ -199,21 +277,35 @@ predicate.
199
  template<class InputIterator, class OutputIterator, class T>
200
  OutputIterator
201
  replace_copy(InputIterator first, InputIterator last,
202
  OutputIterator result,
203
  const T& old_value, const T& new_value);
 
 
 
 
 
 
204
 
205
  template<class InputIterator, class OutputIterator, class Predicate, class T>
206
  OutputIterator
207
  replace_copy_if(InputIterator first, InputIterator last,
208
  OutputIterator result,
209
  Predicate pred, const T& new_value);
 
 
 
 
 
 
 
210
  ```
211
 
212
  *Requires:* The results of the expressions `*first` and `new_value`
213
- shall be writable to the `result` output iterator. The ranges \[`first`,
214
- `last`) and \[`result`, `result + (last - first)`) shall not overlap.
 
215
 
216
  *Effects:* Assigns to every iterator `i` in the range \[`result`,
217
  `result + (last - first)`) either `new_value` or
218
  `*(first + (i - result))` depending on whether the following
219
  corresponding conditions hold:
@@ -231,23 +323,30 @@ predicate.
231
  ### Fill <a id="alg.fill">[[alg.fill]]</a>
232
 
233
  ``` cpp
234
  template<class ForwardIterator, class T>
235
  void fill(ForwardIterator first, ForwardIterator last, const T& value);
 
 
 
236
 
237
  template<class OutputIterator, class Size, class T>
238
  OutputIterator fill_n(OutputIterator first, Size n, const T& value);
 
 
 
239
  ```
240
 
241
- *Requires:* The expression `value` shall be writable to the output
242
- iterator. The type `Size` shall be convertible to an integral
 
243
  type ([[conv.integral]], [[class.conv]]).
244
 
245
- *Effects:* The first algorithm assigns `value` through all the iterators
246
- in the range \[`first`, `last`). The second algorithm assigns `value`
247
- through all the iterators in the range \[`first`, `first + n`) if `n` is
248
- positive, otherwise it does nothing.
249
 
250
  *Returns:* `fill_n` returns `first + n` for non-negative values of `n`
251
  and `first` for negative values.
252
 
253
  *Complexity:* Exactly `last - first`, `n`, or 0 assignments,
@@ -257,25 +356,32 @@ respectively.
257
 
258
  ``` cpp
259
  template<class ForwardIterator, class Generator>
260
  void generate(ForwardIterator first, ForwardIterator last,
261
  Generator gen);
 
 
 
 
262
 
263
  template<class OutputIterator, class Size, class Generator>
264
  OutputIterator generate_n(OutputIterator first, Size n, Generator gen);
 
 
 
265
  ```
266
 
267
- *Effects:* The first algorithm invokes the function object `gen` and
268
- assigns the return value of `gen` through all the iterators in the range
269
- \[`first`, `last`). The second algorithm invokes the function object
270
- `gen` and assigns the return value of `gen` through all the iterators in
271
- the range \[`first`, `first + n`) if `n` is positive, otherwise it does
272
- nothing.
273
-
274
  *Requires:* `gen` takes no arguments, `Size` shall be convertible to an
275
  integral type ([[conv.integral]], [[class.conv]]).
276
 
 
 
 
 
 
 
 
277
  *Returns:* `generate_n` returns `first + n` for non-negative values of
278
  `n` and `first` for negative values.
279
 
280
  *Complexity:* Exactly `last - first`, `n`, or 0 invocations of `gen` and
281
  assignments, respectively.
@@ -284,18 +390,26 @@ assignments, respectively.
284
 
285
  ``` cpp
286
  template<class ForwardIterator, class T>
287
  ForwardIterator remove(ForwardIterator first, ForwardIterator last,
288
  const T& value);
 
 
 
 
289
 
290
  template<class ForwardIterator, class Predicate>
291
  ForwardIterator remove_if(ForwardIterator first, ForwardIterator last,
292
  Predicate pred);
 
 
 
 
293
  ```
294
 
295
  *Requires:* The type of `*first` shall satisfy the `MoveAssignable`
296
- requirements (Table  [[moveassignable]]).
297
 
298
  *Effects:* Eliminates all the elements referred to by iterator `i` in
299
  the range \[`first`, `last`) for which the following corresponding
300
  conditions hold: `*i == value, pred(*i) != false`.
301
 
@@ -304,31 +418,46 @@ conditions hold: `*i == value, pred(*i) != false`.
304
  *Remarks:* Stable ([[algorithm.stable]]).
305
 
306
  *Complexity:* Exactly `last - first` applications of the corresponding
307
  predicate.
308
 
309
- *Note:* each element in the range \[`ret`, `last`), where `ret` is the
310
- returned value, has a valid but unspecified state, because the
311
  algorithms can eliminate elements by moving from elements that were
312
- originally in that range.
313
 
314
  ``` cpp
315
  template<class InputIterator, class OutputIterator, class T>
316
  OutputIterator
317
  remove_copy(InputIterator first, InputIterator last,
318
  OutputIterator result, const T& value);
 
 
 
 
 
319
 
320
  template<class InputIterator, class OutputIterator, class Predicate>
321
  OutputIterator
322
  remove_copy_if(InputIterator first, InputIterator last,
323
  OutputIterator result, Predicate pred);
 
 
 
 
 
324
  ```
325
 
326
  *Requires:* The ranges \[`first`, `last`) and \[`result`,
327
  `result + (last - first)`) shall not overlap. The expression
328
  `*result = *first` shall be valid.
329
 
 
 
 
 
 
330
  *Effects:* Copies all the elements referred to by the iterator `i` in
331
  the range \[`first`, `last`) for which the following corresponding
332
  conditions do not hold: `*i == value, pred(*i) != false`.
333
 
334
  *Returns:* The end of the resulting range.
@@ -341,51 +470,78 @@ predicate.
341
  ### Unique <a id="alg.unique">[[alg.unique]]</a>
342
 
343
  ``` cpp
344
  template<class ForwardIterator>
345
  ForwardIterator unique(ForwardIterator first, ForwardIterator last);
 
 
 
346
 
347
  template<class ForwardIterator, class BinaryPredicate>
348
  ForwardIterator unique(ForwardIterator first, ForwardIterator last,
349
  BinaryPredicate pred);
 
 
 
 
350
  ```
351
 
 
 
 
 
352
  *Effects:* For a nonempty range, eliminates all but the first element
353
  from every consecutive group of equivalent elements referred to by the
354
  iterator `i` in the range \[`first + 1`, `last`) for which the following
355
  conditions hold: `*(i - 1) == *i` or `pred(*(i - 1), *i) != false`.
356
 
357
- *Requires:* The comparison function shall be an equivalence relation.
358
- The type of `*first` shall satisfy the `MoveAssignable` requirements
359
- (Table  [[moveassignable]]).
360
-
361
  *Returns:* The end of the resulting range.
362
 
363
  *Complexity:* For nonempty ranges, exactly `(last - first) - 1`
364
  applications of the corresponding predicate.
365
 
366
  ``` cpp
367
  template<class InputIterator, class OutputIterator>
368
  OutputIterator
369
  unique_copy(InputIterator first, InputIterator last,
370
  OutputIterator result);
 
 
 
 
 
371
 
372
  template<class InputIterator, class OutputIterator,
373
  class BinaryPredicate>
374
  OutputIterator
375
  unique_copy(InputIterator first, InputIterator last,
376
  OutputIterator result, BinaryPredicate pred);
 
 
 
 
 
 
377
  ```
378
 
379
- *Requires:* The comparison function shall be an equivalence relation.
380
- The ranges \[`first`, `last`) and \[`result`, `result+(last-first)`)
381
- shall not overlap. The expression `*result = *first` shall be valid. If
382
- neither `InputIterator` nor `OutputIterator` meets the requirements of
383
- forward iterator then the value type of `InputIterator` shall be
384
- `CopyConstructible` (Table  [[copyconstructible]]) and `CopyAssignable`
385
- (Table  [[copyassignable]]). Otherwise `CopyConstructible` is not
386
- required.
 
 
 
 
 
 
 
 
 
387
 
388
  *Effects:* Copies only the first element from every consecutive group of
389
  equal elements referred to by the iterator `i` in the range \[`first`,
390
  `last`) for which the following corresponding conditions hold:
391
  `*i == *(i - 1)` or `pred(*i, *(i - 1)) != false`.
@@ -398,206 +554,171 @@ applications of the corresponding predicate.
398
  ### Reverse <a id="alg.reverse">[[alg.reverse]]</a>
399
 
400
  ``` cpp
401
  template<class BidirectionalIterator>
402
  void reverse(BidirectionalIterator first, BidirectionalIterator last);
 
 
 
403
  ```
404
 
405
- *Effects:* For each non-negative integer `i < (last - first)/2`, applies
406
- `iter_swap` to all pairs of iterators `first + i, (last - i) - 1`.
407
-
408
  *Requires:* `*first` shall be swappable ([[swappable.requirements]]).
409
 
 
 
 
 
 
 
 
410
  *Complexity:* Exactly `(last - first)/2` swaps.
411
 
412
  ``` cpp
413
  template<class BidirectionalIterator, class OutputIterator>
414
  OutputIterator
415
- reverse_copy(BidirectionalIterator first,
416
- BidirectionalIterator last, OutputIterator result);
 
 
 
 
 
417
  ```
418
 
 
 
 
419
  *Effects:* Copies the range \[`first`, `last`) to the range \[`result`,
420
  `result + (last - first)`) such that for every non-negative integer
421
  `i < (last - first)` the following assignment takes place:
422
  `*(result + (last - first) - 1 - i) = *(first + i)`.
423
 
424
- *Requires:* The ranges \[`first`, `last`) and \[`result`,
425
- `result+(last-first)`) shall not overlap.
426
-
427
  *Returns:* `result + (last - first)`.
428
 
429
  *Complexity:* Exactly `last - first` assignments.
430
 
431
  ### Rotate <a id="alg.rotate">[[alg.rotate]]</a>
432
 
433
  ``` cpp
434
  template<class ForwardIterator>
435
- ForwardIterator rotate(ForwardIterator first, ForwardIterator middle,
436
- ForwardIterator last);
 
 
 
 
437
  ```
438
 
 
 
 
 
 
 
 
439
  *Effects:* For each non-negative integer `i < (last - first)`, places
440
  the element from the position `first + i` into position
441
  `first + (i + (last - middle)) % (last - first)`.
442
 
443
  *Returns:* `first + (last - middle)`.
444
 
445
  *Remarks:* This is a left rotate.
446
 
447
- *Requires:* \[`first`, `middle`) and \[`middle`, `last`) shall be valid
448
- ranges. `ForwardIterator` shall satisfy the requirements of
449
- `ValueSwappable` ([[swappable.requirements]]). The type of `*first`
450
- shall satisfy the requirements of `MoveConstructible`
451
- (Table  [[moveconstructible]]) and the requirements of `MoveAssignable`
452
- (Table  [[moveassignable]]).
453
-
454
  *Complexity:* At most `last - first` swaps.
455
 
456
  ``` cpp
457
  template<class ForwardIterator, class OutputIterator>
458
  OutputIterator
459
- rotate_copy(ForwardIterator first, ForwardIterator middle,
460
- ForwardIterator last, OutputIterator result);
 
 
 
 
 
461
  ```
462
 
 
 
 
463
  *Effects:* Copies the range \[`first`, `last`) to the range \[`result`,
464
  `result + (last - first)`) such that for each non-negative integer
465
  `i < (last - first)` the following assignment takes place:
466
  `*(result + i) = *(first + (i + (middle - first)) % (last - first))`.
467
 
468
  *Returns:* `result + (last - first)`.
469
 
470
- *Requires:* The ranges \[`first`, `last`) and \[`result`,
471
- `result + (last - first)`) shall not overlap.
472
-
473
  *Complexity:* Exactly `last - first` assignments.
474
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
475
  ### Shuffle <a id="alg.random.shuffle">[[alg.random.shuffle]]</a>
476
 
477
  ``` cpp
478
- template<class RandomAccessIterator, class UniformRandomNumberGenerator>
479
  void shuffle(RandomAccessIterator first,
480
  RandomAccessIterator last,
481
- UniformRandomNumberGenerator&& g);
482
  ```
483
 
 
 
 
 
 
 
 
484
  *Effects:* Permutes the elements in the range \[`first`, `last`) such
485
  that each possible permutation of those elements has equal probability
486
  of appearance.
487
 
488
- *Requires:* `RandomAccessIterator` shall satisfy the requirements of
489
- `ValueSwappable` ([[swappable.requirements]]). The type
490
- `UniformRandomNumberGenerator` shall meet the requirements of a uniform
491
- random number generator ([[rand.req.urng]]) type whose return type is
492
- convertible to `iterator_traits<RandomAccessIterator>::difference_type`.
493
-
494
  *Complexity:* Exactly `(last - first) - 1` swaps.
495
 
496
  *Remarks:* To the extent that the implementation of this function makes
497
  use of random numbers, the object `g` shall serve as the
498
  implementation’s source of randomness.
499
 
500
- ### Partitions <a id="alg.partitions">[[alg.partitions]]</a>
501
-
502
- ``` cpp
503
- template <class InputIterator, class Predicate>
504
- bool is_partitioned(InputIterator first, InputIterator last, Predicate pred);
505
- ```
506
-
507
- *Requires:* `InputIterator`’s value type shall be convertible to
508
- `Predicate`’s argument type.
509
-
510
- *Returns:* `true` if \[`first`, `last`) is empty or if \[`first`,
511
- `last`) is partitioned by `pred`, i.e. if all elements that satisfy
512
- `pred` appear before those that do not.
513
-
514
- *Complexity:* Linear. At most `last - first` applications of `pred`.
515
-
516
- ``` cpp
517
- template<class ForwardIterator, class Predicate>
518
- ForwardIterator
519
- partition(ForwardIterator first,
520
- ForwardIterator last, Predicate pred);
521
- ```
522
-
523
- *Effects:* Places all the elements in the range \[`first`, `last`) that
524
- satisfy `pred` before all the elements that do not satisfy it.
525
-
526
- *Returns:* An iterator `i` such that for every iterator `j` in the range
527
- \[`first`, `i`) `pred(*j) != false`, and for every iterator `k` in the
528
- range \[`i`, `last`), `pred(*k) == false`.
529
-
530
- *Requires:* `ForwardIterator` shall satisfy the requirements of
531
- `ValueSwappable` ([[swappable.requirements]]).
532
-
533
- *Complexity:* If ForwardIterator meets the requirements for a
534
- BidirectionalIterator, at most `(last - first) / 2` swaps are done;
535
- otherwise at most `last - first` swaps are done. Exactly `last - first`
536
- applications of the predicate are done.
537
-
538
- ``` cpp
539
- template<class BidirectionalIterator, class Predicate>
540
- BidirectionalIterator
541
- stable_partition(BidirectionalIterator first,
542
- BidirectionalIterator last, Predicate pred);
543
- ```
544
-
545
- *Effects:* Places all the elements in the range \[`first`, `last`) that
546
- satisfy `pred` before all the elements that do not satisfy it.
547
-
548
- *Returns:* An iterator `i` such that for every iterator `j` in the range
549
- \[`first`, `i`), `pred(*j) != false`, and for every iterator `k` in the
550
- range \[`i`, `last`), `pred(*k) == false`. The relative order of the
551
- elements in both groups is preserved.
552
-
553
- *Requires:* `BidirectionalIterator` shall satisfy the requirements of
554
- `ValueSwappable` ([[swappable.requirements]]). The type of `*first`
555
- shall satisfy the requirements of `MoveConstructible`
556
- (Table  [[moveconstructible]]) and of `MoveAssignable`
557
- (Table  [[moveassignable]]).
558
-
559
- *Complexity:* At most `(last - first) * log(last - first)` swaps, but
560
- only linear number of swaps if there is enough extra memory. Exactly
561
- `last - first` applications of the predicate.
562
-
563
- ``` cpp
564
- template <class InputIterator, class OutputIterator1,
565
- class OutputIterator2, class Predicate>
566
- pair<OutputIterator1, OutputIterator2>
567
- partition_copy(InputIterator first, InputIterator last,
568
- OutputIterator1 out_true, OutputIterator2 out_false,
569
- Predicate pred);
570
- ```
571
-
572
- *Requires:* `InputIterator`’s value type shall be `CopyAssignable`, and
573
- shall be writable to the `out_true` and `out_false` `OutputIterator`s,
574
- and shall be convertible to `Predicate`’s argument type. The input range
575
- shall not overlap with either of the output ranges.
576
-
577
- *Effects:* For each iterator `i` in \[`first`, `last`), copies `*i` to
578
- the output range beginning with `out_true` if `pred(*i)` is `true`, or
579
- to the output range beginning with `out_false` otherwise.
580
-
581
- *Returns:* A pair `p` such that `p.first` is the end of the output range
582
- beginning at `out_true` and `p.second` is the end of the output range
583
- beginning at `out_false`.
584
-
585
- *Complexity:* Exactly `last - first` applications of `pred`.
586
-
587
- ``` cpp
588
- template<class ForwardIterator, class Predicate>
589
- ForwardIterator partition_point(ForwardIterator first,
590
- ForwardIterator last,
591
- Predicate pred);
592
- ```
593
-
594
- *Requires:* `ForwardIterator`’s value type shall be convertible to
595
- `Predicate`’s argument type. \[`first`, `last`) shall be partitioned by
596
- `pred`, i.e. all elements that satisfy `pred` shall appear before those
597
- that do not.
598
-
599
- *Returns:* An iterator `mid` such that `all_of(first, mid, pred)` and
600
- `none_of(mid, last, pred)` are both true.
601
-
602
- *Complexity:* 𝑂(log(last - first)) applications of `pred`.
603
-
 
6
  template<class InputIterator, class OutputIterator>
7
  OutputIterator copy(InputIterator first, InputIterator last,
8
  OutputIterator result);
9
  ```
10
 
11
+ *Requires:* `result` shall not be in the range \[`first`, `last`).
12
+
13
  *Effects:* Copies elements in the range \[`first`, `last`) into the
14
  range \[`result`, `result + (last - first)`) starting from `first` and
15
  proceeding to `last`. For each non-negative integer
16
  `n < (last - first)`, performs `*(result + n) = *(first + n)`.
17
 
18
  *Returns:* `result + (last - first)`.
19
 
20
+ *Complexity:* Exactly `last - first` assignments.
21
+
22
+ ``` cpp
23
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
24
+ ForwardIterator2 copy(ExecutionPolicy&& policy,
25
+ ForwardIterator1 first, ForwardIterator1 last,
26
+ ForwardIterator2 result);
27
+ ```
28
+
29
+ *Requires:* The ranges \[`first`, `last`) and \[`result`,
30
+ `result + (last - first)`) shall not overlap.
31
+
32
+ *Effects:* Copies elements in the range \[`first`, `last`) into the
33
+ range \[`result`, `result + (last - first)`). For each non-negative
34
+ integer `n < (last - first)`, performs `*(result + n) = *(first + n)`.
35
+
36
+ *Returns:* `result + (last - first)`.
37
 
38
  *Complexity:* Exactly `last - first` assignments.
39
 
40
  ``` cpp
41
  template<class InputIterator, class Size, class OutputIterator>
42
  OutputIterator copy_n(InputIterator first, Size n,
43
  OutputIterator result);
44
+ template<class ExecutionPolicy, class ForwardIterator1, class Size, class ForwardIterator2>
45
+ ForwardIterator2 copy_n(ExecutionPolicy&& exec,
46
+ ForwardIterator1 first, Size n,
47
+ ForwardIterator2 result);
48
  ```
49
 
50
  *Effects:* For each non-negative integer i < n, performs
51
  `*(result + i) = *(first + i)`.
52
 
 
56
 
57
  ``` cpp
58
  template<class InputIterator, class OutputIterator, class Predicate>
59
  OutputIterator copy_if(InputIterator first, InputIterator last,
60
  OutputIterator result, Predicate pred);
61
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class Predicate>
62
+ ForwardIterator2 copy_if(ExecutionPolicy&& exec,
63
+ ForwardIterator1 first, ForwardIterator1 last,
64
+ ForwardIterator2 result, Predicate pred);
65
  ```
66
 
67
  *Requires:* The ranges \[`first`, `last`) and \[`result`,
68
  `result + (last - first)`) shall not overlap.
69
 
70
+ [*Note 1*: For the overload with an `ExecutionPolicy`, there may be a
71
+ performance cost if `iterator_traits<ForwardIterator1>::value_type` is
72
+ not `MoveConstructible`
73
+ (Table  [[tab:moveconstructible]]). — *end note*]
74
+
75
  *Effects:* Copies all of the elements referred to by the iterator `i` in
76
  the range \[`first`, `last`) for which `pred(*i)` is `true`.
77
 
78
  *Returns:* The end of the resulting range.
79
 
 
88
  copy_backward(BidirectionalIterator1 first,
89
  BidirectionalIterator1 last,
90
  BidirectionalIterator2 result);
91
  ```
92
 
93
+ *Requires:* `result` shall not be in the range (`first`, `last`).
94
+
95
  *Effects:* Copies elements in the range \[`first`, `last`) into the
96
  range \[`result - (last-first)`, `result`) starting from `last - 1` and
97
  proceeding to `first`.[^2] For each positive integer
98
  `n <= (last - first)`, performs `*(result - n) = *(last - n)`.
99
 
 
 
100
  *Returns:* `result - (last - first)`.
101
 
102
  *Complexity:* Exactly `last - first` assignments.
103
 
104
  ### Move <a id="alg.move">[[alg.move]]</a>
105
 
106
  ``` cpp
107
  template<class InputIterator, class OutputIterator>
108
+ OutputIterator move(InputIterator first, InputIterator last, OutputIterator result);
 
109
  ```
110
 
111
+ *Requires:* `result` shall not be in the range \[`first`, `last`).
112
+
113
  *Effects:* Moves elements in the range \[`first`, `last`) into the range
114
  \[`result`, `result + (last - first)`) starting from first and
115
  proceeding to last. For each non-negative integer `n < (last-first)`,
116
  performs `*(result + n)` `= std::move(*(first + n))`.
117
 
118
  *Returns:* `result + (last - first)`.
119
 
 
 
120
  *Complexity:* Exactly `last - first` move assignments.
121
 
122
+ ``` cpp
123
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
124
+ ForwardIterator2 move(ExecutionPolicy&& policy,
125
+ ForwardIterator1 first, ForwardIterator1 last,
126
+ ForwardIterator2 result);
127
+ ```
128
+
129
+ *Requires:* The ranges \[`first`, `last`) and \[`result`,
130
+ `result + (last - first)`) shall not overlap.
131
+
132
+ *Effects:* Moves elements in the range \[`first`, `last`) into the range
133
+ \[`result`, `result + (last - first)`). For each non-negative integer
134
+ `n < (last - first)`, performs
135
+ `*(result + n) = std::move(*(first + n))`.
136
+
137
+ *Returns:* `result + (last - first)`.
138
+
139
+ *Complexity:* Exactly `last - first` assignments.
140
+
141
  ``` cpp
142
  template<class BidirectionalIterator1, class BidirectionalIterator2>
143
  BidirectionalIterator2
144
  move_backward(BidirectionalIterator1 first,
145
  BidirectionalIterator1 last,
146
  BidirectionalIterator2 result);
147
  ```
148
 
149
+ *Requires:* `result` shall not be in the range (`first`, `last`).
150
+
151
  *Effects:* Moves elements in the range \[`first`, `last`) into the range
152
  \[`result - (last-first)`, `result`) starting from `last - 1` and
153
  proceeding to first.[^3] For each positive integer
154
  `n <= (last - first)`, performs
155
  `*(result - n) = std::move(*(last - n))`.
156
 
 
 
157
  *Returns:* `result - (last - first)`.
158
 
159
  *Complexity:* Exactly `last - first` assignments.
160
 
161
+ ### Swap <a id="alg.swap">[[alg.swap]]</a>
162
 
163
  ``` cpp
164
  template<class ForwardIterator1, class ForwardIterator2>
165
  ForwardIterator2
166
  swap_ranges(ForwardIterator1 first1, ForwardIterator1 last1,
167
  ForwardIterator2 first2);
168
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
169
+ ForwardIterator2
170
+ swap_ranges(ExecutionPolicy&& exec,
171
+ ForwardIterator1 first1, ForwardIterator1 last1,
172
+ ForwardIterator2 first2);
173
  ```
174
 
 
 
 
175
  *Requires:* The two ranges \[`first1`, `last1`) and \[`first2`,
176
  `first2 + (last1 - first1)`) shall not overlap. `*(first1 + n)` shall be
177
  swappable with ([[swappable.requirements]]) `*(first2 + n)`.
178
 
179
+ *Effects:* For each non-negative integer `n < (last1 - first1)`
180
+ performs: `swap(*(first1 + n), *(first2 + n))`.
181
+
182
  *Returns:* `first2 + (last1 - first1)`.
183
 
184
  *Complexity:* Exactly `last1 - first1` swaps.
185
 
186
  ``` cpp
187
  template<class ForwardIterator1, class ForwardIterator2>
188
  void iter_swap(ForwardIterator1 a, ForwardIterator2 b);
189
  ```
190
 
 
 
191
  *Requires:* `a` and `b` shall be dereferenceable. `*a` shall be
192
  swappable with ([[swappable.requirements]]) `*b`.
193
 
194
+ *Effects:* As if by `swap(*a, *b)`.
195
+
196
  ### Transform <a id="alg.transform">[[alg.transform]]</a>
197
 
198
  ``` cpp
199
  template<class InputIterator, class OutputIterator,
200
  class UnaryOperation>
201
  OutputIterator
202
  transform(InputIterator first, InputIterator last,
203
  OutputIterator result, UnaryOperation op);
204
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
205
+ class UnaryOperation>
206
+ ForwardIterator2
207
+ transform(ExecutionPolicy&& exec,
208
+ ForwardIterator1 first, ForwardIterator1 last,
209
+ ForwardIterator2 result, UnaryOperation op);
210
 
211
  template<class InputIterator1, class InputIterator2,
212
  class OutputIterator, class BinaryOperation>
213
  OutputIterator
214
  transform(InputIterator1 first1, InputIterator1 last1,
215
  InputIterator2 first2, OutputIterator result,
216
  BinaryOperation binary_op);
217
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
218
+ class ForwardIterator, class BinaryOperation>
219
+ ForwardIterator
220
+ transform(ExecutionPolicy&& exec,
221
+ ForwardIterator1 first1, ForwardIterator1 last1,
222
+ ForwardIterator2 first2, ForwardIterator result,
223
+ BinaryOperation binary_op);
224
  ```
225
 
226
+ *Requires:* `op` and `binary_op` shall not invalidate iterators or
227
+ subranges, or modify elements in the ranges
228
+
229
+ - \[`first1`, `last1`\],
230
+ - \[`first2`, `first2 + (last1 - first1)`\], and
231
+ - \[`result`, `result + (last1 - first1)`\].[^4]
232
+
233
  *Effects:* Assigns through every iterator `i` in the range \[`result`,
234
  `result + (last1 - first1)`) a new corresponding value equal to
235
+ `op(*(first1 + (i - result)))` or
236
  `binary_op(*(first1 + (i - result)), *(first2 + (i - result)))`.
237
 
 
 
 
 
 
238
  *Returns:* `result + (last1 - first1)`.
239
 
240
  *Complexity:* Exactly `last1 - first1` applications of `op` or
241
+ `binary_op`. This requirement also applies to the overload with an
242
+ `ExecutionPolicy` .
243
 
244
  *Remarks:* `result` may be equal to `first` in case of unary transform,
245
  or to `first1` or `first2` in case of binary transform.
246
 
247
  ### Replace <a id="alg.replace">[[alg.replace]]</a>
248
 
249
  ``` cpp
250
  template<class ForwardIterator, class T>
251
  void replace(ForwardIterator first, ForwardIterator last,
252
  const T& old_value, const T& new_value);
253
+ template<class ExecutionPolicy, class ForwardIterator, class T>
254
+ void replace(ExecutionPolicy&& exec,
255
+ ForwardIterator first, ForwardIterator last,
256
+ const T& old_value, const T& new_value);
257
 
258
  template<class ForwardIterator, class Predicate, class T>
259
  void replace_if(ForwardIterator first, ForwardIterator last,
260
  Predicate pred, const T& new_value);
261
+ template<class ExecutionPolicy, class ForwardIterator, class Predicate, class T>
262
+ void replace_if(ExecutionPolicy&& exec,
263
+ ForwardIterator first, ForwardIterator last,
264
+ Predicate pred, const T& new_value);
265
  ```
266
 
267
  *Requires:* The expression `*first = new_value` shall be valid.
268
 
269
  *Effects:* Substitutes elements referred by the iterator `i` in the
 
277
  template<class InputIterator, class OutputIterator, class T>
278
  OutputIterator
279
  replace_copy(InputIterator first, InputIterator last,
280
  OutputIterator result,
281
  const T& old_value, const T& new_value);
282
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class T>
283
+ ForwardIterator2
284
+ replace_copy(ExecutionPolicy&& exec,
285
+ ForwardIterator1 first, ForwardIterator1 last,
286
+ ForwardIterator2 result,
287
+ const T& old_value, const T& new_value);
288
 
289
  template<class InputIterator, class OutputIterator, class Predicate, class T>
290
  OutputIterator
291
  replace_copy_if(InputIterator first, InputIterator last,
292
  OutputIterator result,
293
  Predicate pred, const T& new_value);
294
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
295
+ class Predicate, class T>
296
+ ForwardIterator2
297
+ replace_copy_if(ExecutionPolicy&& exec,
298
+ ForwardIterator1 first, ForwardIterator1 last,
299
+ ForwardIterator2 result,
300
+ Predicate pred, const T& new_value);
301
  ```
302
 
303
  *Requires:* The results of the expressions `*first` and `new_value`
304
+ shall be writable ([[iterator.requirements.general]]) to the `result`
305
+ output iterator. The ranges \[`first`, `last`) and \[`result`,
306
+ `result + (last - first)`) shall not overlap.
307
 
308
  *Effects:* Assigns to every iterator `i` in the range \[`result`,
309
  `result + (last - first)`) either `new_value` or
310
  `*(first + (i - result))` depending on whether the following
311
  corresponding conditions hold:
 
323
  ### Fill <a id="alg.fill">[[alg.fill]]</a>
324
 
325
  ``` cpp
326
  template<class ForwardIterator, class T>
327
  void fill(ForwardIterator first, ForwardIterator last, const T& value);
328
+ template<class ExecutionPolicy, class ForwardIterator, class T>
329
+ void fill(ExecutionPolicy&& exec,
330
+ ForwardIterator first, ForwardIterator last, const T& value);
331
 
332
  template<class OutputIterator, class Size, class T>
333
  OutputIterator fill_n(OutputIterator first, Size n, const T& value);
334
+ template<class ExecutionPolicy, class ForwardIterator, class Size, class T>
335
+ ForwardIterator fill_n(ExecutionPolicy&& exec,
336
+ ForwardIterator first, Size n, const T& value);
337
  ```
338
 
339
+ *Requires:* The expression `value` shall be
340
+ writable ([[iterator.requirements.general]]) to the output iterator.
341
+ The type `Size` shall be convertible to an integral
342
  type ([[conv.integral]], [[class.conv]]).
343
 
344
+ *Effects:* The `fill` algorithms assign `value` through all the
345
+ iterators in the range \[`first`, `last`). The `fill_n` algorithms
346
+ assign `value` through all the iterators in the range \[`first`,
347
+ `first + n`) if `n` is positive, otherwise they do nothing.
348
 
349
  *Returns:* `fill_n` returns `first + n` for non-negative values of `n`
350
  and `first` for negative values.
351
 
352
  *Complexity:* Exactly `last - first`, `n`, or 0 assignments,
 
356
 
357
  ``` cpp
358
  template<class ForwardIterator, class Generator>
359
  void generate(ForwardIterator first, ForwardIterator last,
360
  Generator gen);
361
+ template<class ExecutionPolicy, class ForwardIterator, class Generator>
362
+ void generate(ExecutionPolicy&& exec,
363
+ ForwardIterator first, ForwardIterator last,
364
+ Generator gen);
365
 
366
  template<class OutputIterator, class Size, class Generator>
367
  OutputIterator generate_n(OutputIterator first, Size n, Generator gen);
368
+ template<class ExecutionPolicy, class ForwardIterator, class Size, class Generator>
369
+ ForwardIterator generate_n(ExecutionPolicy&& exec,
370
+ ForwardIterator first, Size n, Generator gen);
371
  ```
372
 
 
 
 
 
 
 
 
373
  *Requires:* `gen` takes no arguments, `Size` shall be convertible to an
374
  integral type ([[conv.integral]], [[class.conv]]).
375
 
376
+ *Effects:* The `generate` algorithms invoke the function object `gen`
377
+ and assign the return value of `gen` through all the iterators in the
378
+ range \[`first`, `last`). The `generate_n` algorithms invoke the
379
+ function object `gen` and assign the return value of `gen` through all
380
+ the iterators in the range \[`first`, `first + n`) if `n` is positive,
381
+ otherwise they do nothing.
382
+
383
  *Returns:* `generate_n` returns `first + n` for non-negative values of
384
  `n` and `first` for negative values.
385
 
386
  *Complexity:* Exactly `last - first`, `n`, or 0 invocations of `gen` and
387
  assignments, respectively.
 
390
 
391
  ``` cpp
392
  template<class ForwardIterator, class T>
393
  ForwardIterator remove(ForwardIterator first, ForwardIterator last,
394
  const T& value);
395
+ template<class ExecutionPolicy, class ForwardIterator, class T>
396
+ ForwardIterator remove(ExecutionPolicy&& exec,
397
+ ForwardIterator first, ForwardIterator last,
398
+ const T& value);
399
 
400
  template<class ForwardIterator, class Predicate>
401
  ForwardIterator remove_if(ForwardIterator first, ForwardIterator last,
402
  Predicate pred);
403
+ template<class ExecutionPolicy, class ForwardIterator, class Predicate>
404
+ ForwardIterator remove_if(ExecutionPolicy&& exec,
405
+ ForwardIterator first, ForwardIterator last,
406
+ Predicate pred);
407
  ```
408
 
409
  *Requires:* The type of `*first` shall satisfy the `MoveAssignable`
410
+ requirements (Table  [[tab:moveassignable]]).
411
 
412
  *Effects:* Eliminates all the elements referred to by iterator `i` in
413
  the range \[`first`, `last`) for which the following corresponding
414
  conditions hold: `*i == value, pred(*i) != false`.
415
 
 
418
  *Remarks:* Stable ([[algorithm.stable]]).
419
 
420
  *Complexity:* Exactly `last - first` applications of the corresponding
421
  predicate.
422
 
423
+ [*Note 1*: Each element in the range \[`ret`, `last`), where `ret` is
424
+ the returned value, has a valid but unspecified state, because the
425
  algorithms can eliminate elements by moving from elements that were
426
+ originally in that range. — *end note*]
427
 
428
  ``` cpp
429
  template<class InputIterator, class OutputIterator, class T>
430
  OutputIterator
431
  remove_copy(InputIterator first, InputIterator last,
432
  OutputIterator result, const T& value);
433
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class T>
434
+ ForwardIterator2
435
+ remove_copy(ExecutionPolicy&& exec,
436
+ ForwardIterator1 first, ForwardIterator1 last,
437
+ ForwardIterator2 result, const T& value);
438
 
439
  template<class InputIterator, class OutputIterator, class Predicate>
440
  OutputIterator
441
  remove_copy_if(InputIterator first, InputIterator last,
442
  OutputIterator result, Predicate pred);
443
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class Predicate>
444
+ ForwardIterator2
445
+ remove_copy_if(ExecutionPolicy&& exec,
446
+ ForwardIterator1 first, ForwardIterator1 last,
447
+ ForwardIterator2 result, Predicate pred);
448
  ```
449
 
450
  *Requires:* The ranges \[`first`, `last`) and \[`result`,
451
  `result + (last - first)`) shall not overlap. The expression
452
  `*result = *first` shall be valid.
453
 
454
+ [*Note 2*: For the overloads with an `ExecutionPolicy`, there may be a
455
+ performance cost if `iterator_traits<ForwardIterator1>::value_type` is
456
+ not `MoveConstructible`
457
+ (Table  [[tab:moveconstructible]]). — *end note*]
458
+
459
  *Effects:* Copies all the elements referred to by the iterator `i` in
460
  the range \[`first`, `last`) for which the following corresponding
461
  conditions do not hold: `*i == value, pred(*i) != false`.
462
 
463
  *Returns:* The end of the resulting range.
 
470
  ### Unique <a id="alg.unique">[[alg.unique]]</a>
471
 
472
  ``` cpp
473
  template<class ForwardIterator>
474
  ForwardIterator unique(ForwardIterator first, ForwardIterator last);
475
+ template<class ExecutionPolicy, class ForwardIterator>
476
+ ForwardIterator unique(ExecutionPolicy&& exec,
477
+ ForwardIterator first, ForwardIterator last);
478
 
479
  template<class ForwardIterator, class BinaryPredicate>
480
  ForwardIterator unique(ForwardIterator first, ForwardIterator last,
481
  BinaryPredicate pred);
482
+ template<class ExecutionPolicy, class ForwardIterator, class BinaryPredicate>
483
+ ForwardIterator unique(ExecutionPolicy&& exec,
484
+ ForwardIterator first, ForwardIterator last,
485
+ BinaryPredicate pred);
486
  ```
487
 
488
+ *Requires:* The comparison function shall be an equivalence relation.
489
+ The type of `*first` shall satisfy the `MoveAssignable` requirements
490
+ (Table  [[tab:moveassignable]]).
491
+
492
  *Effects:* For a nonempty range, eliminates all but the first element
493
  from every consecutive group of equivalent elements referred to by the
494
  iterator `i` in the range \[`first + 1`, `last`) for which the following
495
  conditions hold: `*(i - 1) == *i` or `pred(*(i - 1), *i) != false`.
496
 
 
 
 
 
497
  *Returns:* The end of the resulting range.
498
 
499
  *Complexity:* For nonempty ranges, exactly `(last - first) - 1`
500
  applications of the corresponding predicate.
501
 
502
  ``` cpp
503
  template<class InputIterator, class OutputIterator>
504
  OutputIterator
505
  unique_copy(InputIterator first, InputIterator last,
506
  OutputIterator result);
507
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
508
+ ForwardIterator2
509
+ unique_copy(ExecutionPolicy&& exec,
510
+ ForwardIterator1 first, ForwardIterator1 last,
511
+ ForwardIterator2 result);
512
 
513
  template<class InputIterator, class OutputIterator,
514
  class BinaryPredicate>
515
  OutputIterator
516
  unique_copy(InputIterator first, InputIterator last,
517
  OutputIterator result, BinaryPredicate pred);
518
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
519
+ class BinaryPredicate>
520
+ ForwardIterator2
521
+ unique_copy(ExecutionPolicy&& exec,
522
+ ForwardIterator1 first, ForwardIterator1 last,
523
+ ForwardIterator2 result, BinaryPredicate pred);
524
  ```
525
 
526
+ *Requires:*
527
+
528
+ - The comparison function shall be an equivalence relation.
529
+ - The ranges \[`first`, `last`) and \[`result`, `result+(last-first)`)
530
+ shall not overlap.
531
+ - The expression `*result = *first` shall be valid.
532
+ - For the overloads with no `ExecutionPolicy`, let `T` be the value type
533
+ of `InputIterator`. If `InputIterator` meets the forward iterator
534
+ requirements, then there are no additional requirements for `T`.
535
+ Otherwise, if `OutputIterator` meets the forward iterator requirements
536
+ and its value type is the same as `T`, then `T` shall be
537
+ `CopyAssignable` (Table  [[tab:copyassignable]]). Otherwise, `T` shall
538
+ be both `CopyConstructible` (Table  [[tab:copyconstructible]]) and
539
+ `CopyAssignable`. \[*Note 1*: For the overloads with an
540
+ `ExecutionPolicy`, there may be a performance cost if the value type
541
+ of `ForwardIterator1` is not both `CopyConstructible` and
542
+ `CopyAssignable`. — *end note*]
543
 
544
  *Effects:* Copies only the first element from every consecutive group of
545
  equal elements referred to by the iterator `i` in the range \[`first`,
546
  `last`) for which the following corresponding conditions hold:
547
  `*i == *(i - 1)` or `pred(*i, *(i - 1)) != false`.
 
554
  ### Reverse <a id="alg.reverse">[[alg.reverse]]</a>
555
 
556
  ``` cpp
557
  template<class BidirectionalIterator>
558
  void reverse(BidirectionalIterator first, BidirectionalIterator last);
559
+ template<class ExecutionPolicy, class BidirectionalIterator>
560
+ void reverse(ExecutionPolicy&& exec,
561
+ BidirectionalIterator first, BidirectionalIterator last);
562
  ```
563
 
 
 
 
564
  *Requires:* `*first` shall be swappable ([[swappable.requirements]]).
565
 
566
+ *Effects:* For each non-negative integer `i < (last - first) / 2`,
567
+ applies `iter_swap` to all pairs of iterators
568
+ `first + i, (last - i) - 1`.
569
+
570
+ *Requires:* `BidirectionalIterator` shall satisfy the requirements of
571
+ `ValueSwappable` ([[swappable.requirements]]).
572
+
573
  *Complexity:* Exactly `(last - first)/2` swaps.
574
 
575
  ``` cpp
576
  template<class BidirectionalIterator, class OutputIterator>
577
  OutputIterator
578
+ reverse_copy(BidirectionalIterator first, BidirectionalIterator last,
579
+ OutputIterator result);
580
+ template<class ExecutionPolicy, class BidirectionalIterator, class ForwardIterator>
581
+ ForwardIterator
582
+ reverse_copy(ExecutionPolicy&& exec,
583
+ BidirectionalIterator first, BidirectionalIterator last,
584
+ ForwardIterator result);
585
  ```
586
 
587
+ *Requires:* The ranges \[`first`, `last`) and \[`result`,
588
+ `result + (last - first)`) shall not overlap.
589
+
590
  *Effects:* Copies the range \[`first`, `last`) to the range \[`result`,
591
  `result + (last - first)`) such that for every non-negative integer
592
  `i < (last - first)` the following assignment takes place:
593
  `*(result + (last - first) - 1 - i) = *(first + i)`.
594
 
 
 
 
595
  *Returns:* `result + (last - first)`.
596
 
597
  *Complexity:* Exactly `last - first` assignments.
598
 
599
  ### Rotate <a id="alg.rotate">[[alg.rotate]]</a>
600
 
601
  ``` cpp
602
  template<class ForwardIterator>
603
+ ForwardIterator
604
+ rotate(ForwardIterator first, ForwardIterator middle, ForwardIterator last);
605
+ template<class ExecutionPolicy, class ForwardIterator>
606
+ ForwardIterator
607
+ rotate(ExecutionPolicy&& exec,
608
+ ForwardIterator first, ForwardIterator middle, ForwardIterator last);
609
  ```
610
 
611
+ *Requires:* \[`first`, `middle`) and \[`middle`, `last`) shall be valid
612
+ ranges. `ForwardIterator` shall satisfy the requirements of
613
+ `ValueSwappable` ([[swappable.requirements]]). The type of `*first`
614
+ shall satisfy the requirements of `MoveConstructible`
615
+ (Table  [[tab:moveconstructible]]) and the requirements of
616
+ `MoveAssignable` (Table  [[tab:moveassignable]]).
617
+
618
  *Effects:* For each non-negative integer `i < (last - first)`, places
619
  the element from the position `first + i` into position
620
  `first + (i + (last - middle)) % (last - first)`.
621
 
622
  *Returns:* `first + (last - middle)`.
623
 
624
  *Remarks:* This is a left rotate.
625
 
 
 
 
 
 
 
 
626
  *Complexity:* At most `last - first` swaps.
627
 
628
  ``` cpp
629
  template<class ForwardIterator, class OutputIterator>
630
  OutputIterator
631
+ rotate_copy(ForwardIterator first, ForwardIterator middle, ForwardIterator last,
632
+ OutputIterator result);
633
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
634
+ ForwardIterator2
635
+ rotate_copy(ExecutionPolicy&& exec,
636
+ ForwardIterator1 first, ForwardIterator1 middle, ForwardIterator1 last,
637
+ ForwardIterator2 result);
638
  ```
639
 
640
+ *Requires:* The ranges \[`first`, `last`) and \[`result`,
641
+ `result + (last - first)`) shall not overlap.
642
+
643
  *Effects:* Copies the range \[`first`, `last`) to the range \[`result`,
644
  `result + (last - first)`) such that for each non-negative integer
645
  `i < (last - first)` the following assignment takes place:
646
  `*(result + i) = *(first + (i + (middle - first)) % (last - first))`.
647
 
648
  *Returns:* `result + (last - first)`.
649
 
 
 
 
650
  *Complexity:* Exactly `last - first` assignments.
651
 
652
+ ### Sample <a id="alg.random.sample">[[alg.random.sample]]</a>
653
+
654
+ ``` cpp
655
+ template<class PopulationIterator, class SampleIterator,
656
+ class Distance, class UniformRandomBitGenerator>
657
+ SampleIterator sample(PopulationIterator first, PopulationIterator last,
658
+ SampleIterator out, Distance n,
659
+ UniformRandomBitGenerator&& g);
660
+ ```
661
+
662
+ *Requires:*
663
+
664
+ - `PopulationIterator` shall satisfy the requirements of an input
665
+ iterator ([[input.iterators]]).
666
+ - `SampleIterator` shall satisfy the requirements of an output
667
+ iterator ([[output.iterators]]).
668
+ - `SampleIterator` shall satisfy the additional requirements of a random
669
+ access iterator ([[random.access.iterators]]) unless
670
+ `PopulationIterator` satisfies the additional requirements of a
671
+ forward iterator ([[forward.iterators]]).
672
+ - `PopulationIterator`’s value type shall be
673
+ writable ([[iterator.requirements.general]]) to `out`.
674
+ - `Distance` shall be an integer type.
675
+ - `remove_reference_t<UniformRandomBitGenerator>` shall meet the
676
+ requirements of a uniform random bit generator type
677
+ ([[rand.req.urng]]) whose return type is convertible to `Distance`.
678
+ - `out` shall not be in the range \[`first`, `last`).
679
+
680
+ *Effects:* Copies `min(last - first, n)` elements (the *sample*) from
681
+ \[`first`, `last`) (the *population*) to `out` such that each possible
682
+ sample has equal probability of appearance.
683
+
684
+ [*Note 1*: Algorithms that obtain such effects include *selection
685
+ sampling* and *reservoir sampling*. — *end note*]
686
+
687
+ *Returns:* The end of the resulting sample range.
688
+
689
+ *Complexity:* 𝑂(`last - first`).
690
+
691
+ *Remarks:*
692
+
693
+ - Stable if and only if `PopulationIterator` satisfies the requirements
694
+ of a forward iterator.
695
+ - To the extent that the implementation of this function makes use of
696
+ random numbers, the object `g` shall serve as the implementation’s
697
+ source of randomness.
698
+
699
  ### Shuffle <a id="alg.random.shuffle">[[alg.random.shuffle]]</a>
700
 
701
  ``` cpp
702
+ template<class RandomAccessIterator, class UniformRandomBitGenerator>
703
  void shuffle(RandomAccessIterator first,
704
  RandomAccessIterator last,
705
+ UniformRandomBitGenerator&& g);
706
  ```
707
 
708
+ *Requires:* `RandomAccessIterator` shall satisfy the requirements of
709
+ `ValueSwappable` ([[swappable.requirements]]). The type
710
+ `remove_reference_t<UniformRandomBitGenerator>` shall meet the
711
+ requirements of a uniform random bit generator ([[rand.req.urng]]) type
712
+ whose return type is convertible to
713
+ `iterator_traits<RandomAccessIterator>::difference_type`.
714
+
715
  *Effects:* Permutes the elements in the range \[`first`, `last`) such
716
  that each possible permutation of those elements has equal probability
717
  of appearance.
718
 
 
 
 
 
 
 
719
  *Complexity:* Exactly `(last - first) - 1` swaps.
720
 
721
  *Remarks:* To the extent that the implementation of this function makes
722
  use of random numbers, the object `g` shall serve as the
723
  implementation’s source of randomness.
724