From Jason Turner

[algorithms]

Large diff (193.0 KB) - rendering may be slow on some devices

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpzx2n0d1v/{from.md → to.md} +1982 -491
tmp/tmpzx2n0d1v/{from.md → to.md} RENAMED
@@ -5,11 +5,11 @@
5
  This Clause describes components that C++programs may use to perform
6
  algorithmic operations on containers (Clause  [[containers]]) and other
7
  sequences.
8
 
9
  The following subclauses describe components for non-modifying sequence
10
- operation, modifying sequence operations, sorting and related
11
  operations, and algorithms from the ISO C library, as summarized in
12
  Table  [[tab:algorithms.summary]].
13
 
14
  **Table: Algorithms library summary** <a id="tab:algorithms.summary">[tab:algorithms.summary]</a>
15
 
@@ -18,315 +18,629 @@ Table  [[tab:algorithms.summary]].
18
  | [[alg.nonmodifying]] | Non-modifying sequence operations | |
19
  | [[alg.modifying.operations]] | Mutating sequence operations | `<algorithm>` |
20
  | [[alg.sorting]] | Sorting and related operations | |
21
  | [[alg.c.library]] | C library algorithms | `<cstdlib>` |
22
 
 
 
 
23
  ``` cpp
24
  #include <initializer_list>
25
 
26
  namespace std {
27
-
28
- // [alg.nonmodifying], non-modifying sequence operations:
29
  template <class InputIterator, class Predicate>
30
  bool all_of(InputIterator first, InputIterator last, Predicate pred);
 
 
 
 
 
31
  template <class InputIterator, class Predicate>
32
  bool any_of(InputIterator first, InputIterator last, Predicate pred);
 
 
 
 
 
33
  template <class InputIterator, class Predicate>
34
  bool none_of(InputIterator first, InputIterator last, Predicate pred);
 
 
 
35
 
 
36
  template<class InputIterator, class Function>
37
  Function for_each(InputIterator first, InputIterator last, Function f);
 
 
 
 
 
 
 
 
 
 
38
  template<class InputIterator, class T>
39
  InputIterator find(InputIterator first, InputIterator last,
40
  const T& value);
 
 
 
 
41
  template<class InputIterator, class Predicate>
42
  InputIterator find_if(InputIterator first, InputIterator last,
43
  Predicate pred);
 
 
 
 
44
  template<class InputIterator, class Predicate>
45
  InputIterator find_if_not(InputIterator first, InputIterator last,
46
  Predicate pred);
 
 
 
 
 
 
47
  template<class ForwardIterator1, class ForwardIterator2>
48
  ForwardIterator1
49
  find_end(ForwardIterator1 first1, ForwardIterator1 last1,
50
  ForwardIterator2 first2, ForwardIterator2 last2);
51
- template<class ForwardIterator1, class ForwardIterator2,
52
- class BinaryPredicate>
53
  ForwardIterator1
54
  find_end(ForwardIterator1 first1, ForwardIterator1 last1,
55
  ForwardIterator2 first2, ForwardIterator2 last2,
56
  BinaryPredicate pred);
 
 
 
 
 
 
 
 
 
 
 
 
57
 
 
58
  template<class InputIterator, class ForwardIterator>
59
  InputIterator
60
  find_first_of(InputIterator first1, InputIterator last1,
61
  ForwardIterator first2, ForwardIterator last2);
62
- template<class InputIterator, class ForwardIterator,
63
- class BinaryPredicate>
64
  InputIterator
65
  find_first_of(InputIterator first1, InputIterator last1,
66
  ForwardIterator first2, ForwardIterator last2,
67
  BinaryPredicate pred);
 
 
 
 
 
 
 
 
 
 
 
 
68
 
 
69
  template<class ForwardIterator>
70
  ForwardIterator adjacent_find(ForwardIterator first,
71
  ForwardIterator last);
72
  template<class ForwardIterator, class BinaryPredicate>
73
  ForwardIterator adjacent_find(ForwardIterator first,
74
  ForwardIterator last,
75
  BinaryPredicate pred);
 
 
 
 
 
 
 
 
 
76
 
 
77
  template<class InputIterator, class T>
78
  typename iterator_traits<InputIterator>::difference_type
79
  count(InputIterator first, InputIterator last, const T& value);
 
 
 
 
80
  template<class InputIterator, class Predicate>
81
  typename iterator_traits<InputIterator>::difference_type
82
  count_if(InputIterator first, InputIterator last, Predicate pred);
 
 
 
 
83
 
 
84
  template<class InputIterator1, class InputIterator2>
85
  pair<InputIterator1, InputIterator2>
86
  mismatch(InputIterator1 first1, InputIterator1 last1,
87
  InputIterator2 first2);
88
- template
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,
 
 
 
 
 
 
 
 
 
 
147
  class BinaryPredicate>
148
  ForwardIterator1 search(
 
149
  ForwardIterator1 first1, ForwardIterator1 last1,
150
  ForwardIterator2 first2, ForwardIterator2 last2,
151
  BinaryPredicate pred);
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:
 
 
 
 
163
  template<class InputIterator, class OutputIterator>
164
  OutputIterator copy(InputIterator first, InputIterator last,
165
  OutputIterator result);
 
 
 
 
166
  template<class InputIterator, class Size, class OutputIterator>
167
  OutputIterator copy_n(InputIterator first, Size n,
168
  OutputIterator result);
 
 
 
 
 
169
  template<class InputIterator, class OutputIterator, class Predicate>
170
  OutputIterator copy_if(InputIterator first, InputIterator last,
171
  OutputIterator result, Predicate pred);
 
 
 
 
 
172
  template<class BidirectionalIterator1, class BidirectionalIterator2>
173
  BidirectionalIterator2 copy_backward(
174
  BidirectionalIterator1 first, BidirectionalIterator1 last,
175
  BidirectionalIterator2 result);
176
 
177
- // [alg.move], move:
178
  template<class InputIterator, class OutputIterator>
179
  OutputIterator move(InputIterator first, InputIterator last,
180
  OutputIterator result);
 
 
 
 
 
181
  template<class BidirectionalIterator1, class BidirectionalIterator2>
182
  BidirectionalIterator2 move_backward(
183
  BidirectionalIterator1 first, BidirectionalIterator1 last,
184
  BidirectionalIterator2 result);
185
 
186
- // [alg.swap], swap:
187
  template<class ForwardIterator1, class ForwardIterator2>
188
- ForwardIterator2 swap_ranges(ForwardIterator1 first1,
189
- ForwardIterator1 last1, ForwardIterator2 first2);
 
 
 
 
190
  template<class ForwardIterator1, class ForwardIterator2>
191
  void iter_swap(ForwardIterator1 a, ForwardIterator2 b);
192
 
 
193
  template<class InputIterator, class OutputIterator, class UnaryOperation>
194
  OutputIterator transform(InputIterator first, InputIterator last,
195
  OutputIterator result, UnaryOperation op);
196
  template<class InputIterator1, class InputIterator2, class OutputIterator,
197
  class BinaryOperation>
198
  OutputIterator transform(InputIterator1 first1, InputIterator1 last1,
199
  InputIterator2 first2, OutputIterator result,
200
  BinaryOperation binary_op);
 
 
 
 
 
 
 
 
 
 
 
201
 
 
202
  template<class ForwardIterator, class T>
203
  void replace(ForwardIterator first, ForwardIterator last,
204
  const T& old_value, const T& new_value);
 
 
 
 
205
  template<class ForwardIterator, class Predicate, class T>
206
  void replace_if(ForwardIterator first, ForwardIterator last,
207
  Predicate pred, const T& new_value);
 
 
 
 
208
  template<class InputIterator, class OutputIterator, class T>
209
  OutputIterator replace_copy(InputIterator first, InputIterator last,
210
  OutputIterator result,
211
  const T& old_value, const T& new_value);
 
 
 
 
 
212
  template<class InputIterator, class OutputIterator, class Predicate, class T>
213
  OutputIterator replace_copy_if(InputIterator first, InputIterator last,
214
  OutputIterator result,
215
  Predicate pred, const T& new_value);
 
 
 
 
 
 
216
 
 
217
  template<class ForwardIterator, class T>
218
  void fill(ForwardIterator first, ForwardIterator last, const T& value);
 
 
 
 
219
  template<class OutputIterator, class Size, class T>
220
  OutputIterator fill_n(OutputIterator first, Size n, const T& value);
 
 
 
 
221
 
 
222
  template<class ForwardIterator, class Generator>
223
  void generate(ForwardIterator first, ForwardIterator last,
224
  Generator gen);
 
 
 
 
225
  template<class OutputIterator, class Size, class Generator>
226
  OutputIterator generate_n(OutputIterator first, Size n, Generator gen);
 
 
 
227
 
 
228
  template<class ForwardIterator, class T>
229
  ForwardIterator remove(ForwardIterator first, ForwardIterator last,
230
  const T& value);
 
 
 
 
231
  template<class ForwardIterator, class Predicate>
232
  ForwardIterator remove_if(ForwardIterator first, ForwardIterator last,
233
  Predicate pred);
 
 
 
 
234
  template<class InputIterator, class OutputIterator, class T>
235
  OutputIterator remove_copy(InputIterator first, InputIterator last,
236
  OutputIterator result, const T& value);
 
 
 
 
 
237
  template<class InputIterator, class OutputIterator, class Predicate>
238
  OutputIterator remove_copy_if(InputIterator first, InputIterator last,
239
  OutputIterator result, Predicate pred);
 
 
 
 
 
240
 
 
241
  template<class ForwardIterator>
242
  ForwardIterator unique(ForwardIterator first, ForwardIterator last);
243
  template<class ForwardIterator, class BinaryPredicate>
244
  ForwardIterator unique(ForwardIterator first, ForwardIterator last,
245
  BinaryPredicate pred);
 
 
 
 
 
 
 
246
  template<class InputIterator, class OutputIterator>
247
  OutputIterator unique_copy(InputIterator first, InputIterator last,
248
  OutputIterator result);
249
  template<class InputIterator, class OutputIterator, class BinaryPredicate>
250
  OutputIterator unique_copy(InputIterator first, InputIterator last,
251
  OutputIterator result, BinaryPredicate pred);
 
 
 
 
 
 
 
 
 
252
 
 
253
  template<class BidirectionalIterator>
254
  void reverse(BidirectionalIterator first, BidirectionalIterator last);
 
 
 
255
  template<class BidirectionalIterator, class OutputIterator>
256
  OutputIterator reverse_copy(BidirectionalIterator first,
257
  BidirectionalIterator last,
258
  OutputIterator result);
 
 
 
 
 
259
 
 
260
  template<class ForwardIterator>
261
- ForwardIterator rotate(ForwardIterator first, ForwardIterator middle,
 
 
 
 
 
 
262
  ForwardIterator last);
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
 
287
  template<class ForwardIterator, class Predicate>
288
  ForwardIterator partition(ForwardIterator first,
289
  ForwardIterator last,
290
  Predicate pred);
 
 
 
 
 
291
  template<class BidirectionalIterator, class Predicate>
292
  BidirectionalIterator stable_partition(BidirectionalIterator first,
293
  BidirectionalIterator last,
294
  Predicate pred);
 
 
 
 
 
295
  template <class InputIterator, class OutputIterator1,
296
  class OutputIterator2, class Predicate>
297
  pair<OutputIterator1, OutputIterator2>
298
  partition_copy(InputIterator first, InputIterator last,
299
  OutputIterator1 out_true, OutputIterator2 out_false,
300
  Predicate pred);
 
 
 
 
 
 
 
301
  template<class ForwardIterator, class Predicate>
302
  ForwardIterator partition_point(ForwardIterator first,
303
  ForwardIterator last,
304
  Predicate pred);
305
 
306
- // [alg.sorting], sorting and related operations:
307
- // [alg.sort], sorting:
308
  template<class RandomAccessIterator>
309
  void sort(RandomAccessIterator first, RandomAccessIterator last);
310
  template<class RandomAccessIterator, class Compare>
311
  void sort(RandomAccessIterator first, RandomAccessIterator last,
312
  Compare comp);
 
 
 
 
 
 
 
313
 
314
  template<class RandomAccessIterator>
315
  void stable_sort(RandomAccessIterator first, RandomAccessIterator last);
316
  template<class RandomAccessIterator, class Compare>
317
  void stable_sort(RandomAccessIterator first, RandomAccessIterator last,
318
  Compare comp);
 
 
 
 
 
 
 
319
 
320
  template<class RandomAccessIterator>
321
  void partial_sort(RandomAccessIterator first,
322
  RandomAccessIterator middle,
323
  RandomAccessIterator last);
324
  template<class RandomAccessIterator, class Compare>
325
  void partial_sort(RandomAccessIterator first,
326
  RandomAccessIterator middle,
327
  RandomAccessIterator last, Compare comp);
 
 
 
 
 
 
 
 
 
 
328
  template<class InputIterator, class RandomAccessIterator>
329
  RandomAccessIterator partial_sort_copy(
330
  InputIterator first, InputIterator last,
331
  RandomAccessIterator result_first,
332
  RandomAccessIterator result_last);
@@ -334,29 +648,66 @@ namespace std {
334
  RandomAccessIterator partial_sort_copy(
335
  InputIterator first, InputIterator last,
336
  RandomAccessIterator result_first,
337
  RandomAccessIterator result_last,
338
  Compare comp);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
339
  template<class ForwardIterator>
340
  bool is_sorted(ForwardIterator first, ForwardIterator last);
341
  template<class ForwardIterator, class Compare>
342
  bool is_sorted(ForwardIterator first, ForwardIterator last,
343
  Compare comp);
 
 
 
 
 
 
 
344
  template<class ForwardIterator>
345
  ForwardIterator is_sorted_until(ForwardIterator first, ForwardIterator last);
346
  template<class ForwardIterator, class Compare>
347
  ForwardIterator is_sorted_until(ForwardIterator first, ForwardIterator last,
348
  Compare comp);
 
 
 
 
 
 
 
349
 
 
350
  template<class RandomAccessIterator>
351
  void nth_element(RandomAccessIterator first, RandomAccessIterator nth,
352
  RandomAccessIterator last);
353
  template<class RandomAccessIterator, class Compare>
354
  void nth_element(RandomAccessIterator first, RandomAccessIterator nth,
355
  RandomAccessIterator last, Compare comp);
 
 
 
 
 
 
 
 
356
 
357
- // [alg.binary.search], binary search:
358
  template<class ForwardIterator, class T>
359
  ForwardIterator lower_bound(ForwardIterator first, ForwardIterator last,
360
  const T& value);
361
  template<class ForwardIterator, class T, class Compare>
362
  ForwardIterator lower_bound(ForwardIterator first, ForwardIterator last,
@@ -383,86 +734,166 @@ namespace std {
383
  const T& value);
384
  template<class ForwardIterator, class T, class Compare>
385
  bool binary_search(ForwardIterator first, ForwardIterator last,
386
  const T& value, Compare comp);
387
 
388
- // [alg.merge], merge:
389
  template<class InputIterator1, class InputIterator2, class OutputIterator>
390
  OutputIterator merge(InputIterator1 first1, InputIterator1 last1,
391
  InputIterator2 first2, InputIterator2 last2,
392
  OutputIterator result);
393
  template<class InputIterator1, class InputIterator2, class OutputIterator,
394
  class Compare>
395
  OutputIterator merge(InputIterator1 first1, InputIterator1 last1,
396
  InputIterator2 first2, InputIterator2 last2,
397
  OutputIterator result, Compare comp);
 
 
 
 
 
 
 
 
 
 
 
 
398
 
399
  template<class BidirectionalIterator>
400
  void inplace_merge(BidirectionalIterator first,
401
  BidirectionalIterator middle,
402
  BidirectionalIterator last);
403
  template<class BidirectionalIterator, class Compare>
404
  void inplace_merge(BidirectionalIterator first,
405
  BidirectionalIterator middle,
406
  BidirectionalIterator last, Compare comp);
 
 
 
 
 
 
 
 
 
 
407
 
408
- // [alg.set.operations], set operations:
409
  template<class InputIterator1, class InputIterator2>
410
  bool includes(InputIterator1 first1, InputIterator1 last1,
411
  InputIterator2 first2, InputIterator2 last2);
412
  template<class InputIterator1, class InputIterator2, class Compare>
413
- bool includes(
414
- InputIterator1 first1, InputIterator1 last1,
415
  InputIterator2 first2, InputIterator2 last2, Compare comp);
 
 
 
 
 
 
 
 
 
416
 
417
  template<class InputIterator1, class InputIterator2, class OutputIterator>
418
  OutputIterator set_union(InputIterator1 first1, InputIterator1 last1,
419
  InputIterator2 first2, InputIterator2 last2,
420
  OutputIterator result);
421
- template<class InputIterator1, class InputIterator2, class OutputIterator,
422
- class Compare>
423
  OutputIterator set_union(InputIterator1 first1, InputIterator1 last1,
424
  InputIterator2 first2, InputIterator2 last2,
425
  OutputIterator result, Compare comp);
 
 
 
 
 
 
 
 
 
 
 
 
426
 
427
  template<class InputIterator1, class InputIterator2, class OutputIterator>
428
  OutputIterator set_intersection(
429
  InputIterator1 first1, InputIterator1 last1,
430
  InputIterator2 first2, InputIterator2 last2,
431
  OutputIterator result);
432
- template<class InputIterator1, class InputIterator2, class OutputIterator,
433
- class Compare>
434
  OutputIterator set_intersection(
435
  InputIterator1 first1, InputIterator1 last1,
436
  InputIterator2 first2, InputIterator2 last2,
437
  OutputIterator result, Compare comp);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
438
 
439
  template<class InputIterator1, class InputIterator2, class OutputIterator>
440
  OutputIterator set_difference(
441
  InputIterator1 first1, InputIterator1 last1,
442
  InputIterator2 first2, InputIterator2 last2,
443
  OutputIterator result);
444
- template<class InputIterator1, class InputIterator2, class OutputIterator,
445
- class Compare>
446
  OutputIterator set_difference(
447
  InputIterator1 first1, InputIterator1 last1,
448
  InputIterator2 first2, InputIterator2 last2,
449
  OutputIterator result, Compare comp);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
450
 
451
  template<class InputIterator1, class InputIterator2, class OutputIterator>
452
  OutputIterator set_symmetric_difference(
453
  InputIterator1 first1, InputIterator1 last1,
454
  InputIterator2 first2, InputIterator2 last2,
455
  OutputIterator result);
456
- template<class InputIterator1, class InputIterator2, class OutputIterator,
457
- class Compare>
458
  OutputIterator set_symmetric_difference(
459
  InputIterator1 first1, InputIterator1 last1,
460
  InputIterator2 first2, InputIterator2 last2,
461
  OutputIterator result, Compare comp);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
462
 
463
- // [alg.heap.operations], heap operations:
464
  template<class RandomAccessIterator>
465
  void push_heap(RandomAccessIterator first, RandomAccessIterator last);
466
  template<class RandomAccessIterator, class Compare>
467
  void push_heap(RandomAccessIterator first, RandomAccessIterator last,
468
  Compare comp);
@@ -487,17 +918,30 @@ namespace std {
487
 
488
  template<class RandomAccessIterator>
489
  bool is_heap(RandomAccessIterator first, RandomAccessIterator last);
490
  template<class RandomAccessIterator, class Compare>
491
  bool is_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
 
 
 
 
 
 
492
  template<class RandomAccessIterator>
493
  RandomAccessIterator is_heap_until(RandomAccessIterator first, RandomAccessIterator last);
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);
@@ -519,37 +963,78 @@ namespace std {
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,
 
 
 
 
 
 
 
527
  Compare comp);
528
  template<class ForwardIterator>
529
- ForwardIterator max_element(ForwardIterator first, ForwardIterator last);
530
  template<class ForwardIterator, class Compare>
531
- ForwardIterator max_element(ForwardIterator first, ForwardIterator last,
 
 
 
 
 
 
 
532
  Compare comp);
533
  template<class ForwardIterator>
534
- pair<ForwardIterator, ForwardIterator>
535
  minmax_element(ForwardIterator first, ForwardIterator last);
536
  template<class ForwardIterator, class Compare>
537
- pair<ForwardIterator, ForwardIterator>
538
  minmax_element(ForwardIterator first, ForwardIterator last, Compare comp);
 
 
 
 
 
 
 
 
539
 
 
 
 
 
 
 
 
540
  template<class InputIterator1, class InputIterator2>
541
  bool lexicographical_compare(
542
  InputIterator1 first1, InputIterator1 last1,
543
  InputIterator2 first2, InputIterator2 last2);
544
  template<class InputIterator1, class InputIterator2, class Compare>
545
  bool lexicographical_compare(
546
  InputIterator1 first1, InputIterator1 last1,
547
  InputIterator2 first2, InputIterator2 last2,
548
  Compare comp);
 
 
 
 
 
 
 
 
 
 
 
 
549
 
550
- // [alg.permutation.generators], permutations:
551
  template<class BidirectionalIterator>
552
  bool next_permutation(BidirectionalIterator first,
553
  BidirectionalIterator last);
554
  template<class BidirectionalIterator, class Compare>
555
  bool next_permutation(BidirectionalIterator first,
@@ -561,10 +1046,12 @@ namespace std {
561
  bool prev_permutation(BidirectionalIterator first,
562
  BidirectionalIterator last, Compare comp);
563
  }
564
  ```
565
 
 
 
566
  All of the algorithms are separated from the particular implementations
567
  of data structures and are parameterized by iterator types. Because of
568
  this, they can work with program-defined data structures, as long as
569
  these data structures have iterator types satisfying the assumptions on
570
  the algorithms.
@@ -594,17 +1081,18 @@ express type requirements.
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`).
@@ -630,19 +1118,20 @@ always takes the first iterator’s `value_type` as its first argument,
630
  that is, in those cases when `T value` is part of the signature, it
631
  should work correctly in the construct `binary_pred(*first1, value)`
632
  contextually converted to `bool` (Clause  [[conv]]). `binary_pred` shall
633
  not apply any non-constant function through the dereferenced iterators.
634
 
635
- Unless otherwise specified, algorithms that take function objects as
636
- arguments are permitted to copy those function objects freely.
637
- Programmers for whom object identity is important should consider using
638
- a wrapper class that points to a noncopied implementation object such as
639
- `reference_wrapper<T>` ([[refwrap]]), or some equivalent solution.
 
640
 
641
  When the description of an algorithm gives an expression such as
642
  `*first == value` for a condition, the expression shall evaluate to
643
- either true or false in boolean contexts.
644
 
645
  In the description of the algorithms operators `+` and `-` are used for
646
  some of the iterator categories for which they do not have to be
647
  defined. In these cases the semantics of `a+n` is the same as that of
648
 
@@ -656,17 +1145,274 @@ and that of `b-a` is the same as of
656
 
657
  ``` cpp
658
  return distance(a, b);
659
  ```
660
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
661
  ## Non-modifying sequence operations <a id="alg.nonmodifying">[[alg.nonmodifying]]</a>
662
 
663
  ### All of <a id="alg.all_of">[[alg.all_of]]</a>
664
 
665
  ``` cpp
666
  template <class InputIterator, class Predicate>
667
  bool all_of(InputIterator first, InputIterator last, Predicate pred);
 
 
 
668
  ```
669
 
670
  *Returns:* `true` if \[`first`, `last`) is empty or if `pred(*i)` is
671
  `true` for every iterator `i` in the range \[`first`, `last`), and
672
  `false` otherwise.
@@ -676,10 +1422,13 @@ template <class InputIterator, class Predicate>
676
  ### Any of <a id="alg.any_of">[[alg.any_of]]</a>
677
 
678
  ``` cpp
679
  template <class InputIterator, class Predicate>
680
  bool any_of(InputIterator first, InputIterator last, Predicate pred);
 
 
 
681
  ```
682
 
683
  *Returns:* `false` if \[`first`, `last`) is empty or if there is no
684
  iterator `i` in the range \[`first`, `last`) such that `pred(*i)` is
685
  `true`, and `true` otherwise.
@@ -689,10 +1438,13 @@ iterator `i` in the range \[`first`, `last`) such that `pred(*i)` is
689
  ### None of <a id="alg.none_of">[[alg.none_of]]</a>
690
 
691
  ``` cpp
692
  template <class InputIterator, class Predicate>
693
  bool none_of(InputIterator first, InputIterator last, Predicate pred);
 
 
 
694
  ```
695
 
696
  *Returns:* `true` if \[`first`, `last`) is empty or if `pred(*i)` is
697
  `false` for every iterator `i` in the range \[`first`, `last`), and
698
  `false` otherwise.
@@ -705,39 +1457,129 @@ template <class InputIterator, class Predicate>
705
  template<class InputIterator, class Function>
706
  Function for_each(InputIterator first, InputIterator last, Function f);
707
  ```
708
 
709
  *Requires:* `Function` shall meet the requirements of
710
- `MoveConstructible` (Table  [[moveconstructible]]). `Function` need not
711
- meet the requirements of `CopyConstructible`
712
- (Table  [[copyconstructible]]).
 
713
 
714
  *Effects:* Applies `f` to the result of dereferencing every iterator in
715
  the range \[`first`, `last`), starting from `first` and proceeding to
716
- `last - 1`. If the type of `first` satisfies the requirements of a
717
- mutable iterator, `f` may apply nonconstant functions through the
718
- dereferenced iterator.
719
 
720
- *Returns:* `std::move(f)`.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
721
 
722
  *Complexity:* Applies `f` exactly `last - first` times.
723
 
724
  *Remarks:* If `f` returns a result, the result is ignored.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
725
 
726
  ### Find <a id="alg.find">[[alg.find]]</a>
727
 
728
  ``` cpp
729
  template<class InputIterator, class T>
730
  InputIterator find(InputIterator first, InputIterator last,
731
  const T& value);
 
 
 
732
 
733
  template<class InputIterator, class Predicate>
734
  InputIterator find_if(InputIterator first, InputIterator last,
735
  Predicate pred);
 
 
 
 
736
  template<class InputIterator, class Predicate>
737
  InputIterator find_if_not(InputIterator first, InputIterator last,
738
  Predicate pred);
 
 
 
739
  ```
740
 
741
  *Returns:* The first iterator `i` in the range \[`first`, `last`) for
742
  which the following corresponding conditions hold: `*i == value`,
743
  `pred(*i) != false`, `pred(*i) == false`. Returns `last` if no such
@@ -751,17 +1593,29 @@ predicate.
751
  ``` cpp
752
  template<class ForwardIterator1, class ForwardIterator2>
753
  ForwardIterator1
754
  find_end(ForwardIterator1 first1, ForwardIterator1 last1,
755
  ForwardIterator2 first2, ForwardIterator2 last2);
 
 
 
 
 
756
 
757
  template<class ForwardIterator1, class ForwardIterator2,
758
  class BinaryPredicate>
759
  ForwardIterator1
760
  find_end(ForwardIterator1 first1, ForwardIterator1 last1,
761
  ForwardIterator2 first2, ForwardIterator2 last2,
762
  BinaryPredicate pred);
 
 
 
 
 
 
 
763
  ```
764
 
765
  *Effects:* Finds a subsequence of equal values in a sequence.
766
 
767
  *Returns:* The last iterator `i` in the range \[`first1`,
@@ -780,17 +1634,29 @@ applications of the corresponding predicate.
780
  ``` cpp
781
  template<class InputIterator, class ForwardIterator>
782
  InputIterator
783
  find_first_of(InputIterator first1, InputIterator last1,
784
  ForwardIterator first2, ForwardIterator last2);
 
 
 
 
 
785
 
786
  template<class InputIterator, class ForwardIterator,
787
  class BinaryPredicate>
788
  InputIterator
789
  find_first_of(InputIterator first1, InputIterator last1,
790
  ForwardIterator first2, ForwardIterator last2,
791
  BinaryPredicate pred);
 
 
 
 
 
 
 
792
  ```
793
 
794
  *Effects:* Finds an element that matches one of a set of values.
795
 
796
  *Returns:* The first iterator `i` in the range \[`first1`, `last1`) such
@@ -805,35 +1671,50 @@ the corresponding predicate.
805
  ### Adjacent find <a id="alg.adjacent.find">[[alg.adjacent.find]]</a>
806
 
807
  ``` cpp
808
  template<class ForwardIterator>
809
  ForwardIterator adjacent_find(ForwardIterator first, ForwardIterator last);
 
 
 
810
 
811
  template<class ForwardIterator, class BinaryPredicate>
812
  ForwardIterator adjacent_find(ForwardIterator first, ForwardIterator last,
813
  BinaryPredicate pred);
 
 
 
 
814
  ```
815
 
816
  *Returns:* The first iterator `i` such that both `i` and `i + 1` are in
817
  the range \[`first`, `last`) for which the following corresponding
818
  conditions hold: `*i == *(i + 1), pred(*i, *(i + 1)) != false`. Returns
819
  `last` if no such iterator is found.
820
 
821
- *Complexity:* For a nonempty range, exactly
822
  `min((i - first) + 1, (last - first) - 1)` applications of the
823
  corresponding predicate, where `i` is `adjacent_find`’s return value.
 
 
824
 
825
  ### Count <a id="alg.count">[[alg.count]]</a>
826
 
827
  ``` cpp
828
  template<class InputIterator, class T>
829
  typename iterator_traits<InputIterator>::difference_type
830
  count(InputIterator first, InputIterator last, const T& value);
 
 
 
831
 
832
  template<class InputIterator, class Predicate>
833
  typename iterator_traits<InputIterator>::difference_type
834
  count_if(InputIterator first, InputIterator last, Predicate pred);
 
 
 
835
  ```
836
 
837
  *Effects:* Returns the number of iterators `i` in the range \[`first`,
838
  `last`) for which the following corresponding conditions hold:
839
  `*i == value, pred(*i) != false`.
@@ -846,70 +1727,107 @@ predicate.
846
  ``` cpp
847
  template<class InputIterator1, class InputIterator2>
848
  pair<InputIterator1, InputIterator2>
849
  mismatch(InputIterator1 first1, InputIterator1 last1,
850
  InputIterator2 first2);
 
 
 
 
 
851
 
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>
891
 
892
  ``` cpp
893
  template<class InputIterator1, class InputIterator2>
894
  bool equal(InputIterator1 first1, InputIterator1 last1,
895
  InputIterator2 first2);
 
 
 
 
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
 
@@ -917,14 +1835,24 @@ template<class InputIterator1, class InputIterator2,
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
@@ -960,31 +1888,43 @@ 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>
976
  ForwardIterator1
977
  search(ForwardIterator1 first1, ForwardIterator1 last1,
978
  ForwardIterator2 first2, ForwardIterator2 last2);
 
 
 
 
 
979
 
980
  template<class ForwardIterator1, class ForwardIterator2,
981
  class BinaryPredicate>
982
  ForwardIterator1
983
  search(ForwardIterator1 first1, ForwardIterator1 last1,
984
  ForwardIterator2 first2, ForwardIterator2 last2,
985
  BinaryPredicate pred);
 
 
 
 
 
 
 
986
  ```
987
 
988
  *Effects:* Finds a subsequence of equal values in a sequence.
989
 
990
  *Returns:* The first iterator `i` in the range \[`first1`,
@@ -1006,10 +1946,23 @@ template<class ForwardIterator, class Size, class T>
1006
  template<class ForwardIterator, class Size, class T,
1007
  class BinaryPredicate>
1008
  ForwardIterator
1009
  search_n(ForwardIterator first, ForwardIterator last, Size count,
1010
  const T& value, BinaryPredicate pred);
 
 
 
 
 
 
 
 
 
 
 
 
 
1011
  ```
1012
 
1013
  *Requires:* The type `Size` shall be convertible to integral
1014
  type ([[conv.integral]], [[class.conv]]).
1015
 
@@ -1022,35 +1975,68 @@ following corresponding conditions hold:
1022
  such iterator is found.
1023
 
1024
  *Complexity:* At most `last - first` applications of the corresponding
1025
  predicate.
1026
 
 
 
 
 
 
 
 
 
 
 
 
1027
  ## Mutating sequence operations <a id="alg.modifying.operations">[[alg.modifying.operations]]</a>
1028
 
1029
  ### Copy <a id="alg.copy">[[alg.copy]]</a>
1030
 
1031
  ``` cpp
1032
  template<class InputIterator, class OutputIterator>
1033
  OutputIterator copy(InputIterator first, InputIterator last,
1034
  OutputIterator result);
1035
  ```
1036
 
 
 
1037
  *Effects:* Copies elements in the range \[`first`, `last`) into the
1038
  range \[`result`, `result + (last - first)`) starting from `first` and
1039
  proceeding to `last`. For each non-negative integer
1040
  `n < (last - first)`, performs `*(result + n) = *(first + n)`.
1041
 
1042
  *Returns:* `result + (last - first)`.
1043
 
1044
- *Requires:* `result` shall not be in the range \[`first`, `last`).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1045
 
1046
  *Complexity:* Exactly `last - first` assignments.
1047
 
1048
  ``` cpp
1049
  template<class InputIterator, class Size, class OutputIterator>
1050
  OutputIterator copy_n(InputIterator first, Size n,
1051
  OutputIterator result);
 
 
 
 
1052
  ```
1053
 
1054
  *Effects:* For each non-negative integer i < n, performs
1055
  `*(result + i) = *(first + i)`.
1056
 
@@ -1060,15 +2046,24 @@ template<class InputIterator, class Size, class OutputIterator>
1060
 
1061
  ``` cpp
1062
  template<class InputIterator, class OutputIterator, class Predicate>
1063
  OutputIterator copy_if(InputIterator first, InputIterator last,
1064
  OutputIterator result, Predicate pred);
 
 
 
 
1065
  ```
1066
 
1067
  *Requires:* The ranges \[`first`, `last`) and \[`result`,
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
 
@@ -1083,135 +2078,182 @@ template<class BidirectionalIterator1, class BidirectionalIterator2>
1083
  copy_backward(BidirectionalIterator1 first,
1084
  BidirectionalIterator1 last,
1085
  BidirectionalIterator2 result);
1086
  ```
1087
 
 
 
1088
  *Effects:* Copies elements in the range \[`first`, `last`) into the
1089
  range \[`result - (last-first)`, `result`) starting from `last - 1` and
1090
  proceeding to `first`.[^2] For each positive integer
1091
  `n <= (last - first)`, performs `*(result - n) = *(last - n)`.
1092
 
1093
- *Requires:* `result` shall not be in the range (`first`, `last`).
1094
-
1095
  *Returns:* `result - (last - first)`.
1096
 
1097
  *Complexity:* Exactly `last - first` assignments.
1098
 
1099
  ### Move <a id="alg.move">[[alg.move]]</a>
1100
 
1101
  ``` cpp
1102
  template<class InputIterator, class OutputIterator>
1103
- OutputIterator move(InputIterator first, InputIterator last,
1104
- OutputIterator result);
1105
  ```
1106
 
 
 
1107
  *Effects:* Moves elements in the range \[`first`, `last`) into the range
1108
  \[`result`, `result + (last - first)`) starting from first and
1109
  proceeding to last. For each non-negative integer `n < (last-first)`,
1110
  performs `*(result + n)` `= std::move(*(first + n))`.
1111
 
1112
  *Returns:* `result + (last - first)`.
1113
 
1114
- *Requires:* `result` shall not be in the range \[`first`, `last`).
1115
-
1116
  *Complexity:* Exactly `last - first` move assignments.
1117
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1118
  ``` cpp
1119
  template<class BidirectionalIterator1, class BidirectionalIterator2>
1120
  BidirectionalIterator2
1121
  move_backward(BidirectionalIterator1 first,
1122
  BidirectionalIterator1 last,
1123
  BidirectionalIterator2 result);
1124
  ```
1125
 
 
 
1126
  *Effects:* Moves elements in the range \[`first`, `last`) into the range
1127
  \[`result - (last-first)`, `result`) starting from `last - 1` and
1128
  proceeding to first.[^3] For each positive integer
1129
  `n <= (last - first)`, performs
1130
  `*(result - n) = std::move(*(last - n))`.
1131
 
1132
- *Requires:* `result` shall not be in the range (`first`, `last`).
1133
-
1134
  *Returns:* `result - (last - first)`.
1135
 
1136
  *Complexity:* Exactly `last - first` assignments.
1137
 
1138
- ### swap <a id="alg.swap">[[alg.swap]]</a>
1139
 
1140
  ``` cpp
1141
  template<class ForwardIterator1, class ForwardIterator2>
1142
  ForwardIterator2
1143
  swap_ranges(ForwardIterator1 first1, ForwardIterator1 last1,
1144
  ForwardIterator2 first2);
 
 
 
 
 
1145
  ```
1146
 
1147
- *Effects:* For each non-negative integer `n < (last1 - first1)`
1148
- performs: `swap(*(first1 + n), *(first2 + n))`.
1149
-
1150
  *Requires:* The two ranges \[`first1`, `last1`) and \[`first2`,
1151
  `first2 + (last1 - first1)`) shall not overlap. `*(first1 + n)` shall be
1152
  swappable with ([[swappable.requirements]]) `*(first2 + n)`.
1153
 
 
 
 
1154
  *Returns:* `first2 + (last1 - first1)`.
1155
 
1156
  *Complexity:* Exactly `last1 - first1` swaps.
1157
 
1158
  ``` cpp
1159
  template<class ForwardIterator1, class ForwardIterator2>
1160
  void iter_swap(ForwardIterator1 a, ForwardIterator2 b);
1161
  ```
1162
 
1163
- *Effects:* `swap(*a, *b)`.
1164
-
1165
  *Requires:* `a` and `b` shall be dereferenceable. `*a` shall be
1166
  swappable with ([[swappable.requirements]]) `*b`.
1167
 
 
 
1168
  ### Transform <a id="alg.transform">[[alg.transform]]</a>
1169
 
1170
  ``` cpp
1171
  template<class InputIterator, class OutputIterator,
1172
  class UnaryOperation>
1173
  OutputIterator
1174
  transform(InputIterator first, InputIterator last,
1175
  OutputIterator result, UnaryOperation op);
 
 
 
 
 
 
1176
 
1177
  template<class InputIterator1, class InputIterator2,
1178
  class OutputIterator, class BinaryOperation>
1179
  OutputIterator
1180
  transform(InputIterator1 first1, InputIterator1 last1,
1181
  InputIterator2 first2, OutputIterator result,
1182
  BinaryOperation binary_op);
 
 
 
 
 
 
 
1183
  ```
1184
 
 
 
 
 
 
 
 
1185
  *Effects:* Assigns through every iterator `i` in the range \[`result`,
1186
  `result + (last1 - first1)`) a new corresponding value equal to
1187
- `op(*(first1 + (i - result))` or
1188
  `binary_op(*(first1 + (i - result)), *(first2 + (i - result)))`.
1189
 
1190
- *Requires:* `op` and `binary_op` shall not invalidate iterators or
1191
- subranges, or modify elements in the ranges \[`first1`, `last1`\],
1192
- \[`first2`, `first2 + (last1 - first1)`\], and \[`result`,
1193
- `result + (last1 - first1)`\].[^4]
1194
-
1195
  *Returns:* `result + (last1 - first1)`.
1196
 
1197
  *Complexity:* Exactly `last1 - first1` applications of `op` or
1198
- `binary_op`.
 
1199
 
1200
  *Remarks:* `result` may be equal to `first` in case of unary transform,
1201
  or to `first1` or `first2` in case of binary transform.
1202
 
1203
  ### Replace <a id="alg.replace">[[alg.replace]]</a>
1204
 
1205
  ``` cpp
1206
  template<class ForwardIterator, class T>
1207
  void replace(ForwardIterator first, ForwardIterator last,
1208
  const T& old_value, const T& new_value);
 
 
 
 
1209
 
1210
  template<class ForwardIterator, class Predicate, class T>
1211
  void replace_if(ForwardIterator first, ForwardIterator last,
1212
  Predicate pred, const T& new_value);
 
 
 
 
1213
  ```
1214
 
1215
  *Requires:* The expression `*first = new_value` shall be valid.
1216
 
1217
  *Effects:* Substitutes elements referred by the iterator `i` in the
@@ -1225,21 +2267,35 @@ predicate.
1225
  template<class InputIterator, class OutputIterator, class T>
1226
  OutputIterator
1227
  replace_copy(InputIterator first, InputIterator last,
1228
  OutputIterator result,
1229
  const T& old_value, const T& new_value);
 
 
 
 
 
 
1230
 
1231
  template<class InputIterator, class OutputIterator, class Predicate, class T>
1232
  OutputIterator
1233
  replace_copy_if(InputIterator first, InputIterator last,
1234
  OutputIterator result,
1235
  Predicate pred, const T& new_value);
 
 
 
 
 
 
 
1236
  ```
1237
 
1238
  *Requires:* The results of the expressions `*first` and `new_value`
1239
- shall be writable to the `result` output iterator. The ranges \[`first`,
1240
- `last`) and \[`result`, `result + (last - first)`) shall not overlap.
 
1241
 
1242
  *Effects:* Assigns to every iterator `i` in the range \[`result`,
1243
  `result + (last - first)`) either `new_value` or
1244
  `*(first + (i - result))` depending on whether the following
1245
  corresponding conditions hold:
@@ -1257,23 +2313,30 @@ predicate.
1257
  ### Fill <a id="alg.fill">[[alg.fill]]</a>
1258
 
1259
  ``` cpp
1260
  template<class ForwardIterator, class T>
1261
  void fill(ForwardIterator first, ForwardIterator last, const T& value);
 
 
 
1262
 
1263
  template<class OutputIterator, class Size, class T>
1264
  OutputIterator fill_n(OutputIterator first, Size n, const T& value);
 
 
 
1265
  ```
1266
 
1267
- *Requires:* The expression `value` shall be writable to the output
1268
- iterator. The type `Size` shall be convertible to an integral
 
1269
  type ([[conv.integral]], [[class.conv]]).
1270
 
1271
- *Effects:* The first algorithm assigns `value` through all the iterators
1272
- in the range \[`first`, `last`). The second algorithm assigns `value`
1273
- through all the iterators in the range \[`first`, `first + n`) if `n` is
1274
- positive, otherwise it does nothing.
1275
 
1276
  *Returns:* `fill_n` returns `first + n` for non-negative values of `n`
1277
  and `first` for negative values.
1278
 
1279
  *Complexity:* Exactly `last - first`, `n`, or 0 assignments,
@@ -1283,25 +2346,32 @@ respectively.
1283
 
1284
  ``` cpp
1285
  template<class ForwardIterator, class Generator>
1286
  void generate(ForwardIterator first, ForwardIterator last,
1287
  Generator gen);
 
 
 
 
1288
 
1289
  template<class OutputIterator, class Size, class Generator>
1290
  OutputIterator generate_n(OutputIterator first, Size n, Generator gen);
 
 
 
1291
  ```
1292
 
1293
- *Effects:* The first algorithm invokes the function object `gen` and
1294
- assigns the return value of `gen` through all the iterators in the range
1295
- \[`first`, `last`). The second algorithm invokes the function object
1296
- `gen` and assigns the return value of `gen` through all the iterators in
1297
- the range \[`first`, `first + n`) if `n` is positive, otherwise it does
1298
- nothing.
1299
-
1300
  *Requires:* `gen` takes no arguments, `Size` shall be convertible to an
1301
  integral type ([[conv.integral]], [[class.conv]]).
1302
 
 
 
 
 
 
 
 
1303
  *Returns:* `generate_n` returns `first + n` for non-negative values of
1304
  `n` and `first` for negative values.
1305
 
1306
  *Complexity:* Exactly `last - first`, `n`, or 0 invocations of `gen` and
1307
  assignments, respectively.
@@ -1310,18 +2380,26 @@ assignments, respectively.
1310
 
1311
  ``` cpp
1312
  template<class ForwardIterator, class T>
1313
  ForwardIterator remove(ForwardIterator first, ForwardIterator last,
1314
  const T& value);
 
 
 
 
1315
 
1316
  template<class ForwardIterator, class Predicate>
1317
  ForwardIterator remove_if(ForwardIterator first, ForwardIterator last,
1318
  Predicate pred);
 
 
 
 
1319
  ```
1320
 
1321
  *Requires:* The type of `*first` shall satisfy the `MoveAssignable`
1322
- requirements (Table  [[moveassignable]]).
1323
 
1324
  *Effects:* Eliminates all the elements referred to by iterator `i` in
1325
  the range \[`first`, `last`) for which the following corresponding
1326
  conditions hold: `*i == value, pred(*i) != false`.
1327
 
@@ -1330,31 +2408,46 @@ conditions hold: `*i == value, pred(*i) != false`.
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,
1344
  OutputIterator result, const T& value);
 
 
 
 
 
1345
 
1346
  template<class InputIterator, class OutputIterator, class Predicate>
1347
  OutputIterator
1348
  remove_copy_if(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.
@@ -1367,51 +2460,78 @@ predicate.
1367
  ### Unique <a id="alg.unique">[[alg.unique]]</a>
1368
 
1369
  ``` cpp
1370
  template<class ForwardIterator>
1371
  ForwardIterator unique(ForwardIterator first, ForwardIterator last);
 
 
 
1372
 
1373
  template<class ForwardIterator, class BinaryPredicate>
1374
  ForwardIterator unique(ForwardIterator first, ForwardIterator last,
1375
  BinaryPredicate pred);
 
 
 
 
1376
  ```
1377
 
 
 
 
 
1378
  *Effects:* For a nonempty range, eliminates all but the first element
1379
  from every consecutive group of equivalent elements referred to by the
1380
  iterator `i` in the range \[`first + 1`, `last`) for which the following
1381
  conditions hold: `*(i - 1) == *i` or `pred(*(i - 1), *i) != false`.
1382
 
1383
- *Requires:* The comparison function shall be an equivalence relation.
1384
- The type of `*first` shall satisfy the `MoveAssignable` requirements
1385
- (Table  [[moveassignable]]).
1386
-
1387
  *Returns:* The end of the resulting range.
1388
 
1389
  *Complexity:* For nonempty ranges, exactly `(last - first) - 1`
1390
  applications of the corresponding predicate.
1391
 
1392
  ``` cpp
1393
  template<class InputIterator, class OutputIterator>
1394
  OutputIterator
1395
  unique_copy(InputIterator first, InputIterator last,
1396
  OutputIterator result);
 
 
 
 
 
1397
 
1398
  template<class InputIterator, class OutputIterator,
1399
  class BinaryPredicate>
1400
  OutputIterator
1401
  unique_copy(InputIterator first, InputIterator last,
1402
  OutputIterator result, BinaryPredicate pred);
 
 
 
 
 
 
1403
  ```
1404
 
1405
- *Requires:* The comparison function shall be an equivalence relation.
1406
- The ranges \[`first`, `last`) and \[`result`, `result+(last-first)`)
1407
- shall not overlap. The expression `*result = *first` shall be valid. If
1408
- neither `InputIterator` nor `OutputIterator` meets the requirements of
1409
- forward iterator then the value type of `InputIterator` shall be
1410
- `CopyConstructible` (Table  [[copyconstructible]]) and `CopyAssignable`
1411
- (Table  [[copyassignable]]). Otherwise `CopyConstructible` is not
1412
- required.
 
 
 
 
 
 
 
 
 
1413
 
1414
  *Effects:* Copies only the first element from every consecutive group of
1415
  equal elements referred to by the iterator `i` in the range \[`first`,
1416
  `last`) for which the following corresponding conditions hold:
1417
  `*i == *(i - 1)` or `pred(*i, *(i - 1)) != false`.
@@ -1424,211 +2544,176 @@ applications of the corresponding predicate.
1424
  ### Reverse <a id="alg.reverse">[[alg.reverse]]</a>
1425
 
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
 
1438
  ``` cpp
1439
  template<class BidirectionalIterator, class OutputIterator>
1440
  OutputIterator
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)`.
1454
 
1455
  *Complexity:* Exactly `last - first` assignments.
1456
 
1457
  ### Rotate <a id="alg.rotate">[[alg.rotate]]</a>
1458
 
1459
  ``` cpp
1460
  template<class ForwardIterator>
1461
- ForwardIterator rotate(ForwardIterator first, ForwardIterator middle,
1462
- ForwardIterator last);
 
 
 
 
1463
  ```
1464
 
 
 
 
 
 
 
 
1465
  *Effects:* For each non-negative integer `i < (last - first)`, places
1466
  the element from the position `first + i` into position
1467
  `first + (i + (last - middle)) % (last - first)`.
1468
 
1469
  *Returns:* `first + (last - middle)`.
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
 
1482
  ``` cpp
1483
  template<class ForwardIterator, class OutputIterator>
1484
  OutputIterator
1485
- rotate_copy(ForwardIterator first, ForwardIterator middle,
1486
- ForwardIterator last, OutputIterator result);
 
 
 
 
 
1487
  ```
1488
 
 
 
 
1489
  *Effects:* Copies the range \[`first`, `last`) to the range \[`result`,
1490
  `result + (last - first)`) such that for each non-negative integer
1491
  `i < (last - first)` the following assignment takes place:
1492
  `*(result + i) = *(first + (i + (middle - first)) % (last - first))`.
1493
 
1494
  *Returns:* `result + (last - first)`.
1495
 
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
  ```
1509
 
 
 
 
 
 
 
 
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>
1530
- bool is_partitioned(InputIterator first, InputIterator last, Predicate pred);
1531
- ```
1532
-
1533
- *Requires:* `InputIterator`’s value type shall be convertible to
1534
- `Predicate`’s argument type.
1535
-
1536
- *Returns:* `true` if \[`first`, `last`) is empty or if \[`first`,
1537
- `last`) is partitioned by `pred`, i.e. if all elements that satisfy
1538
- `pred` appear before those that do not.
1539
-
1540
- *Complexity:* Linear. At most `last - first` applications of `pred`.
1541
-
1542
- ``` cpp
1543
- template<class ForwardIterator, class Predicate>
1544
- ForwardIterator
1545
- partition(ForwardIterator first,
1546
- ForwardIterator last, Predicate pred);
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
-
1559
- *Complexity:* If ForwardIterator meets the requirements for a
1560
- BidirectionalIterator, at most `(last - first) / 2` swaps are done;
1561
- otherwise at most `last - first` swaps are done. Exactly `last - first`
1562
- applications of the predicate are done.
1563
-
1564
- ``` cpp
1565
- template<class BidirectionalIterator, class Predicate>
1566
- BidirectionalIterator
1567
- stable_partition(BidirectionalIterator first,
1568
- BidirectionalIterator last, Predicate pred);
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`
1581
- shall satisfy the requirements of `MoveConstructible`
1582
- (Table  [[moveconstructible]]) and of `MoveAssignable`
1583
- (Table  [[moveassignable]]).
1584
-
1585
- *Complexity:* At most `(last - first) * log(last - first)` swaps, but
1586
- only linear number of swaps if there is enough extra memory. Exactly
1587
- `last - first` applications of the predicate.
1588
-
1589
- ``` cpp
1590
- template <class InputIterator, class OutputIterator1,
1591
- class OutputIterator2, class Predicate>
1592
- pair<OutputIterator1, OutputIterator2>
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.
1606
-
1607
- *Returns:* A pair `p` such that `p.first` is the end of the output range
1608
- beginning at `out_true` and `p.second` is the end of the output range
1609
- beginning at `out_false`.
1610
-
1611
- *Complexity:* Exactly `last - first` applications of `pred`.
1612
-
1613
- ``` cpp
1614
- template<class ForwardIterator, class Predicate>
1615
- ForwardIterator partition_point(ForwardIterator first,
1616
- ForwardIterator last,
1617
- Predicate pred);
1618
- ```
1619
-
1620
- *Requires:* `ForwardIterator`’s value type shall be convertible to
1621
- `Predicate`’s argument type. \[`first`, `last`) shall be partitioned by
1622
- `pred`, i.e. all elements that satisfy `pred` shall appear before those
1623
- that do not.
1624
-
1625
- *Returns:* An iterator `mid` such that `all_of(first, mid, pred)` and
1626
- `none_of(mid, last, pred)` are both true.
1627
-
1628
- *Complexity:* 𝑂(log(last - first)) applications of `pred`.
1629
-
1630
  ## Sorting and related operations <a id="alg.sorting">[[alg.sorting]]</a>
1631
 
1632
  All the operations in  [[alg.sorting]] have two versions: one that takes
1633
  a function object of type `Compare` and one that uses an `operator<`.
1634
 
@@ -1643,37 +2728,43 @@ 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
1649
- weak ordering on the values.
1650
 
1651
  The term *strict* refers to the requirement of an irreflexive relation
1652
  (`!comp(x, x)` for all `x`), and the term *weak* to requirements that
1653
  are not as strong as those for a total ordering, but stronger than those
1654
  for a partial ordering. If we define `equiv(a, b)` as
1655
  `!comp(a, b) && !comp(b, a)`, then the requirements are that `comp` and
1656
  `equiv` both be transitive relations:
1657
 
1658
  - `comp(a, b) && comp(b, c)` implies `comp(a, c)`
1659
- - `equiv(a, b) && equiv(b, c)`
1660
- implies `equiv(a, c)` Under these conditions, it can be shown that
 
 
 
 
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
1673
- `0 <= i < distance(start, finish)`, `f(*(start + i))` is true if and
1674
- only if `i < n`.
1675
 
1676
  In the descriptions of the functions that deal with ordering
1677
  relationships we frequently use a notion of equivalence to describe
1678
  concepts such as stability. The equivalence to which we refer is not
1679
  necessarily an `operator==`, but an equivalence relation induced by the
@@ -1685,111 +2776,150 @@ equivalent if and only if `!(a < b) && !(b < a)`.
1685
  #### `sort` <a id="sort">[[sort]]</a>
1686
 
1687
  ``` cpp
1688
  template<class RandomAccessIterator>
1689
  void sort(RandomAccessIterator first, RandomAccessIterator last);
 
 
 
1690
 
1691
  template<class RandomAccessIterator, class Compare>
1692
  void sort(RandomAccessIterator first, RandomAccessIterator last,
1693
  Compare comp);
 
 
 
 
1694
  ```
1695
 
1696
- *Effects:* Sorts the elements in the range \[`first`, `last`).
1697
-
1698
  *Requires:* `RandomAccessIterator` shall satisfy the requirements of
1699
  `ValueSwappable` ([[swappable.requirements]]). The type of `*first`
1700
  shall satisfy the requirements of `MoveConstructible`
1701
- (Table  [[moveconstructible]]) and of `MoveAssignable`
1702
- (Table  [[moveassignable]]).
1703
 
1704
- *Complexity:* 𝑂(Nlog(N)) (where N` == last - first`) comparisons.
 
 
1705
 
1706
  #### `stable_sort` <a id="stable.sort">[[stable.sort]]</a>
1707
 
1708
  ``` cpp
1709
  template<class RandomAccessIterator>
1710
  void stable_sort(RandomAccessIterator first, RandomAccessIterator last);
 
 
 
1711
 
1712
  template<class RandomAccessIterator, class Compare>
1713
  void stable_sort(RandomAccessIterator first, RandomAccessIterator last,
1714
  Compare comp);
 
 
 
 
1715
  ```
1716
 
1717
- *Effects:* Sorts the elements in the range \[`first`, `last`).
1718
-
1719
  *Requires:* `RandomAccessIterator` shall satisfy the requirements of
1720
  `ValueSwappable` ([[swappable.requirements]]). The type of `*first`
1721
  shall satisfy the requirements of `MoveConstructible`
1722
- (Table  [[moveconstructible]]) and of `MoveAssignable`
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>
1734
  void partial_sort(RandomAccessIterator first,
1735
  RandomAccessIterator middle,
1736
  RandomAccessIterator last);
 
 
 
 
 
1737
 
1738
  template<class RandomAccessIterator, class Compare>
1739
  void partial_sort(RandomAccessIterator first,
1740
  RandomAccessIterator middle,
1741
  RandomAccessIterator last,
1742
  Compare comp);
 
 
 
 
 
 
1743
  ```
1744
 
 
 
 
 
 
 
1745
  *Effects:* Places the first `middle - first` sorted elements from the
1746
  range \[`first`, `last`) into the range \[`first`, `middle`). The rest
1747
  of the elements in the range \[`middle`, `last`) are placed in an
1748
  unspecified order.
1749
 
1750
- *Requires:* `RandomAccessIterator` shall satisfy the requirements of
1751
- `ValueSwappable` ([[swappable.requirements]]). The type of `*first`
1752
- shall satisfy the requirements of `MoveConstructible`
1753
- (Table  [[moveconstructible]]) and of `MoveAssignable`
1754
- (Table  [[moveassignable]]).
1755
-
1756
- *Complexity:* It takes approximately
1757
- `(last - first) * log(middle - first)` comparisons.
1758
 
1759
  #### `partial_sort_copy` <a id="partial.sort.copy">[[partial.sort.copy]]</a>
1760
 
1761
  ``` cpp
1762
  template<class InputIterator, class RandomAccessIterator>
1763
  RandomAccessIterator
1764
  partial_sort_copy(InputIterator first, InputIterator last,
1765
  RandomAccessIterator result_first,
1766
  RandomAccessIterator result_last);
 
 
 
 
 
 
1767
 
1768
  template<class InputIterator, class RandomAccessIterator,
1769
  class Compare>
1770
  RandomAccessIterator
1771
  partial_sort_copy(InputIterator first, InputIterator last,
1772
  RandomAccessIterator result_first,
1773
  RandomAccessIterator result_last,
1774
  Compare comp);
 
 
 
 
 
 
 
 
1775
  ```
1776
 
 
 
 
 
 
 
1777
  *Effects:* Places the first
1778
  `min(last - first, result_last - result_first)` sorted elements into the
1779
  range \[`result_first`,
1780
  `result_first + min(last - first, result_last - result_first)`).
1781
 
1782
  *Returns:* The smaller of: `result_last` or
1783
  `result_first + (last - first)`.
1784
 
1785
- *Requires:* `RandomAccessIterator` shall satisfy the requirements of
1786
- `ValueSwappable` ([[swappable.requirements]]). The type of
1787
- `*result_first` shall satisfy the requirements of `MoveConstructible`
1788
- (Table  [[moveconstructible]]) and of `MoveAssignable`
1789
- (Table  [[moveassignable]]).
1790
-
1791
  *Complexity:* Approximately
1792
  `(last - first) * log(min(last - first, result_last - result_first))`
1793
  comparisons.
1794
 
1795
  #### `is_sorted` <a id="is.sorted">[[is.sorted]]</a>
@@ -1799,57 +2929,97 @@ template<class ForwardIterator>
1799
  bool is_sorted(ForwardIterator first, ForwardIterator last);
1800
  ```
1801
 
1802
  *Returns:* `is_sorted_until(first, last) == last`
1803
 
 
 
 
 
 
 
 
 
 
1804
  ``` cpp
1805
  template<class ForwardIterator, class Compare>
1806
  bool is_sorted(ForwardIterator first, ForwardIterator last,
1807
  Compare comp);
1808
  ```
1809
 
1810
  *Returns:* `is_sorted_until(first, last, comp) == last`
1811
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1812
  ``` cpp
1813
  template<class ForwardIterator>
1814
  ForwardIterator is_sorted_until(ForwardIterator first, ForwardIterator last);
 
 
 
 
1815
  template<class ForwardIterator, class Compare>
1816
  ForwardIterator is_sorted_until(ForwardIterator first, ForwardIterator last,
1817
  Compare comp);
 
 
 
 
1818
  ```
1819
 
1820
- *Returns:* If `distance(first, last) < 2`, returns `last`. Otherwise,
1821
- returns the last iterator `i` in \[`first`, `last`\] for which the range
1822
  \[`first`, `i`) is sorted.
1823
 
1824
  *Complexity:* Linear.
1825
 
1826
  ### Nth element <a id="alg.nth.element">[[alg.nth.element]]</a>
1827
 
1828
  ``` cpp
1829
  template<class RandomAccessIterator>
1830
  void nth_element(RandomAccessIterator first, RandomAccessIterator nth,
1831
  RandomAccessIterator last);
 
 
 
 
1832
 
1833
  template<class RandomAccessIterator, class Compare>
1834
  void nth_element(RandomAccessIterator first, RandomAccessIterator nth,
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`
1848
- (Table  [[moveassignable]]).
1849
 
1850
- *Complexity:* Linear on average.
 
 
 
 
 
 
 
 
1851
 
1852
  ### Binary search <a id="alg.binary.search">[[alg.binary.search]]</a>
1853
 
1854
  All of the algorithms in this section are versions of binary search and
1855
  assume that the sequence being searched is partitioned with respect to
@@ -1969,77 +3139,250 @@ implies `!comp(value, e)`.
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,
1978
  class OutputIterator>
1979
  OutputIterator
1980
  merge(InputIterator1 first1, InputIterator1 last1,
1981
  InputIterator2 first2, InputIterator2 last2,
1982
  OutputIterator result);
 
 
 
 
 
 
 
1983
 
1984
  template<class InputIterator1, class InputIterator2,
1985
  class OutputIterator, class Compare>
1986
  OutputIterator
1987
  merge(InputIterator1 first1, InputIterator1 last1,
1988
  InputIterator2 first2, InputIterator2 last2,
1989
  OutputIterator result, Compare comp);
 
 
 
 
 
 
 
1990
  ```
1991
 
 
 
 
 
1992
  *Effects:*  Copies all the elements of the two ranges \[`first1`,
1993
  `last1`) and \[`first2`, `last2`) into the range \[`result`,
1994
  `result_last`), where `result_last` is
1995
  `result + (last1 - first1) + (last2 - first2)`, such that the resulting
1996
  range satisfies `is_sorted(result, result_last)` or
1997
  `is_sorted(result, result_last, comp)`, respectively.
1998
 
1999
- *Requires:* The ranges \[`first1`, `last1`) and \[`first2`, `last2`)
2000
- shall be sorted with respect to `operator<` or `comp`. The resulting
2001
- range shall not overlap with either of the original ranges.
2002
-
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,
2014
  BidirectionalIterator last);
 
 
 
 
 
2015
 
2016
  template<class BidirectionalIterator, class Compare>
2017
  void inplace_merge(BidirectionalIterator first,
2018
  BidirectionalIterator middle,
2019
  BidirectionalIterator last, Compare comp);
 
 
 
 
 
2020
  ```
2021
 
 
 
 
 
 
 
 
 
2022
  *Effects:* Merges two sorted consecutive ranges \[`first`, `middle`) and
2023
  \[`middle`, `last`), putting the result of the merge into the range
2024
  \[`first`, `last`). The resulting range will be in non-decreasing order;
2025
  that is, for every iterator `i` in \[`first`, `last`) other than
2026
  `first`, the condition `*i < *(i - 1)` or, respectively,
2027
- `comp(*i, *(i - 1))` will be false.
2028
 
2029
- *Requires:* The ranges \[`first`, `middle`) and \[`middle`, `last`)
2030
- shall be sorted with respect to `operator<` or `comp`.
2031
- `BidirectionalIterator` shall satisfy the requirements of
2032
- `ValueSwappable` ([[swappable.requirements]]). The type of `*first`
2033
- shall satisfy the requirements of `MoveConstructible`
2034
- (Table  [[moveconstructible]]) and of `MoveAssignable`
2035
- (Table  [[moveassignable]]).
2036
 
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
 
@@ -2054,15 +3397,24 @@ to contain the maximum number of occurrences of every element,
2054
 
2055
  ``` cpp
2056
  template<class InputIterator1, class InputIterator2>
2057
  bool includes(InputIterator1 first1, InputIterator1 last1,
2058
  InputIterator2 first2, InputIterator2 last2);
 
 
 
 
2059
 
2060
  template<class InputIterator1, class InputIterator2, class Compare>
2061
  bool includes(InputIterator1 first1, InputIterator1 last1,
2062
  InputIterator2 first2, InputIterator2 last2,
2063
  Compare comp);
 
 
 
 
 
2064
  ```
2065
 
2066
  *Returns:* `true` if \[`first2`, `last2`) is empty or if every element
2067
  in the range \[`first2`, `last2`) is contained in the range \[`first1`,
2068
  `last1`). Returns `false` otherwise.
@@ -2077,26 +3429,40 @@ template<class InputIterator1, class InputIterator2,
2077
  class OutputIterator>
2078
  OutputIterator
2079
  set_union(InputIterator1 first1, InputIterator1 last1,
2080
  InputIterator2 first2, InputIterator2 last2,
2081
  OutputIterator result);
 
 
 
 
 
 
 
2082
 
2083
  template<class InputIterator1, class InputIterator2,
2084
  class OutputIterator, class Compare>
2085
  OutputIterator
2086
  set_union(InputIterator1 first1, InputIterator1 last1,
2087
  InputIterator2 first2, InputIterator2 last2,
2088
  OutputIterator result, Compare comp);
 
 
 
 
 
 
 
2089
  ```
2090
 
 
 
 
2091
  *Effects:* Constructs a sorted union of the elements from the two
2092
  ranges; that is, the set of elements that are present in one or both of
2093
  the ranges.
2094
 
2095
- *Requires:* The resulting range shall not overlap with either of the
2096
- original ranges.
2097
-
2098
  *Returns:* The end of the constructed range.
2099
 
2100
  *Complexity:* At most `2 * ((last1 - first1) + (last2 - first2)) - 1`
2101
  comparisons.
2102
 
@@ -2114,26 +3480,40 @@ template<class InputIterator1, class InputIterator2,
2114
  class OutputIterator>
2115
  OutputIterator
2116
  set_intersection(InputIterator1 first1, InputIterator1 last1,
2117
  InputIterator2 first2, InputIterator2 last2,
2118
  OutputIterator result);
 
 
 
 
 
 
 
2119
 
2120
  template<class InputIterator1, class InputIterator2,
2121
  class OutputIterator, class Compare>
2122
  OutputIterator
2123
  set_intersection(InputIterator1 first1, InputIterator1 last1,
2124
  InputIterator2 first2, InputIterator2 last2,
2125
  OutputIterator result, Compare comp);
 
 
 
 
 
 
 
2126
  ```
2127
 
 
 
 
2128
  *Effects:* Constructs a sorted intersection of the elements from the two
2129
  ranges; that is, the set of elements that are present in both of the
2130
  ranges.
2131
 
2132
- *Requires:* The resulting range shall not overlap with either of the
2133
- original ranges.
2134
-
2135
  *Returns:* The end of the constructed range.
2136
 
2137
  *Complexity:* At most `2 * ((last1 - first1) + (last2 - first2)) - 1`
2138
  comparisons.
2139
 
@@ -2149,26 +3529,40 @@ template<class InputIterator1, class InputIterator2,
2149
  class OutputIterator>
2150
  OutputIterator
2151
  set_difference(InputIterator1 first1, InputIterator1 last1,
2152
  InputIterator2 first2, InputIterator2 last2,
2153
  OutputIterator result);
 
 
 
 
 
 
 
2154
 
2155
  template<class InputIterator1, class InputIterator2,
2156
  class OutputIterator, class Compare>
2157
  OutputIterator
2158
  set_difference(InputIterator1 first1, InputIterator1 last1,
2159
  InputIterator2 first2, InputIterator2 last2,
2160
  OutputIterator result, Compare comp);
 
 
 
 
 
 
 
2161
  ```
2162
 
 
 
 
2163
  *Effects:* Copies the elements of the range \[`first1`, `last1`) which
2164
  are not present in the range \[`first2`, `last2`) to the range beginning
2165
  at `result`. The elements in the constructed range are sorted.
2166
 
2167
- *Requires:* The resulting range shall not overlap with either of the
2168
- original ranges.
2169
-
2170
  *Returns:* The end of the constructed range.
2171
 
2172
  *Complexity:* At most `2 * ((last1 - first1) + (last2 - first2)) - 1`
2173
  comparisons.
2174
 
@@ -2184,28 +3578,42 @@ template<class InputIterator1, class InputIterator2,
2184
  class OutputIterator>
2185
  OutputIterator
2186
  set_symmetric_difference(InputIterator1 first1, InputIterator1 last1,
2187
  InputIterator2 first2, InputIterator2 last2,
2188
  OutputIterator result);
 
 
 
 
 
 
 
2189
 
2190
  template<class InputIterator1, class InputIterator2,
2191
  class OutputIterator, class Compare>
2192
  OutputIterator
2193
  set_symmetric_difference(InputIterator1 first1, InputIterator1 last1,
2194
  InputIterator2 first2, InputIterator2 last2,
2195
  OutputIterator result, Compare comp);
 
 
 
 
 
 
 
2196
  ```
2197
 
 
 
 
2198
  *Effects:* Copies the elements of the range \[`first1`, `last1`) that
2199
  are not present in the range \[`first2`, `last2`), and the elements of
2200
  the range \[`first2`, `last2`) that are not present in the range
2201
  \[`first1`, `last1`) to the range beginning at `result`. The elements in
2202
  the constructed range are sorted.
2203
 
2204
- *Requires:* The resulting range shall not overlap with either of the
2205
- original ranges.
2206
-
2207
  *Returns:* The end of the constructed range.
2208
 
2209
  *Complexity:* At most `2 * ((last1 - first1) + (last2 - first2)) - 1`
2210
  comparisons.
2211
 
@@ -2217,24 +3625,17 @@ copied to the output range: the last m - n of these elements from
2217
  \[`first2`, `last2`) if m < n.
2218
 
2219
  ### Heap operations <a id="alg.heap.operations">[[alg.heap.operations]]</a>
2220
 
2221
  A *heap* is a particular organization of elements in a range between two
2222
- random access iterators \[`a`, `b`). Its two key properties are:
2223
 
2224
- - **(1)} There is no element greater than
2225
- \texttt{\*a}
2226
- in the range and**
2227
-
2228
- - **`(2)} \texttt{*a}
2229
- may be removed by
2230
- \texttt{pop_heap()},
2231
- or a new element added by
2232
- \texttt{push_heap()},
2233
- in
2234
- $\mathcal{O}(\log(N))$
2235
- time.`**
2236
 
2237
  These properties make heaps useful as priority queues.
2238
 
2239
  `make_heap()`
2240
 
@@ -2250,19 +3651,19 @@ template<class RandomAccessIterator>
2250
  template<class RandomAccessIterator, class Compare>
2251
  void push_heap(RandomAccessIterator first, RandomAccessIterator last,
2252
  Compare comp);
2253
  ```
2254
 
2255
- *Effects:* Places the value in the location `last - 1` into the
2256
- resulting heap \[`first`, `last`).
2257
-
2258
  *Requires:* The range \[`first`, `last - 1`) shall be a valid heap. The
2259
  type of `*first` shall satisfy the `MoveConstructible` requirements
2260
- (Table  [[moveconstructible]]) and the `MoveAssignable` requirements
2261
- (Table  [[moveassignable]]).
2262
 
2263
- *Complexity:* At most `log(last - first)` comparisons.
 
 
 
2264
 
2265
  #### `pop_heap` <a id="pop.heap">[[pop.heap]]</a>
2266
 
2267
  ``` cpp
2268
  template<class RandomAccessIterator>
@@ -2275,17 +3676,17 @@ template<class RandomAccessIterator, class Compare>
2275
 
2276
  *Requires:* The range \[`first`, `last`) shall be a valid non-empty
2277
  heap. `RandomAccessIterator` shall satisfy the requirements of
2278
  `ValueSwappable` ([[swappable.requirements]]). The type of `*first`
2279
  shall satisfy the requirements of `MoveConstructible`
2280
- (Table  [[moveconstructible]]) and of `MoveAssignable`
2281
- (Table  [[moveassignable]]).
2282
 
2283
  *Effects:* Swaps the value in the location `first` with the value in the
2284
  location `last - 1` and makes \[`first`, `last - 1`) into a heap.
2285
 
2286
- *Complexity:* At most `2 * log(last - first)` comparisons.
2287
 
2288
  #### `make_heap` <a id="make.heap">[[make.heap]]</a>
2289
 
2290
  ``` cpp
2291
  template<class RandomAccessIterator>
@@ -2294,17 +3695,17 @@ template<class RandomAccessIterator>
2294
  template<class RandomAccessIterator, class Compare>
2295
  void make_heap(RandomAccessIterator first, RandomAccessIterator last,
2296
  Compare comp);
2297
  ```
2298
 
2299
- *Effects:* Constructs a heap out of the range \[`first`, `last`).
2300
-
2301
  *Requires:* The type of `*first` shall satisfy the `MoveConstructible`
2302
- requirements (Table  [[moveconstructible]]) and the `MoveAssignable`
2303
- requirements (Table  [[moveassignable]]).
2304
 
2305
- *Complexity:* At most `3 * (last - first)` comparisons.
 
 
2306
 
2307
  #### `sort_heap` <a id="sort.heap">[[sort.heap]]</a>
2308
 
2309
  ``` cpp
2310
  template<class RandomAccessIterator>
@@ -2313,47 +3714,76 @@ template<class RandomAccessIterator>
2313
  template<class RandomAccessIterator, class Compare>
2314
  void sort_heap(RandomAccessIterator first, RandomAccessIterator last,
2315
  Compare comp);
2316
  ```
2317
 
2318
- *Effects:* Sorts elements in the heap \[`first`, `last`).
2319
-
2320
  *Requires:* The range \[`first`, `last`) shall be a valid heap.
2321
  `RandomAccessIterator` shall satisfy the requirements of
2322
  `ValueSwappable` ([[swappable.requirements]]). The type of `*first`
2323
  shall satisfy the requirements of `MoveConstructible`
2324
- (Table  [[moveconstructible]]) and of `MoveAssignable`
2325
- (Table  [[moveassignable]]).
2326
 
2327
- *Complexity:* At most N log(N) comparisons (where `N == last - first`).
 
 
2328
 
2329
  #### `is_heap` <a id="is.heap">[[is.heap]]</a>
2330
 
2331
  ``` cpp
2332
  template<class RandomAccessIterator>
2333
  bool is_heap(RandomAccessIterator first, RandomAccessIterator last);
2334
  ```
2335
 
2336
  *Returns:* `is_heap_until(first, last) == last`
2337
 
 
 
 
 
 
 
 
 
 
2338
  ``` cpp
2339
  template<class RandomAccessIterator, class Compare>
2340
  bool is_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
2341
  ```
2342
 
2343
  *Returns:* `is_heap_until(first, last, comp) == last`
2344
 
 
 
 
 
 
 
 
 
 
 
 
 
2345
  ``` cpp
2346
  template<class RandomAccessIterator>
2347
  RandomAccessIterator is_heap_until(RandomAccessIterator first, RandomAccessIterator last);
 
 
 
 
2348
  template<class RandomAccessIterator, class Compare>
2349
  RandomAccessIterator is_heap_until(RandomAccessIterator first, RandomAccessIterator last,
2350
  Compare comp);
 
 
 
 
2351
  ```
2352
 
2353
- *Returns:* If `distance(first, last) < 2`, returns `last`. Otherwise,
2354
- returns the last iterator `i` in \[`first`, `last`\] for which the range
2355
  \[`first`, `i`) is a heap.
2356
 
2357
  *Complexity:* Linear.
2358
 
2359
  ### Minimum and maximum <a id="alg.min.max">[[alg.min.max]]</a>
@@ -2362,68 +3792,76 @@ returns the last iterator `i` in \[`first`, `last`\] for which the range
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
 
2370
  *Returns:* The smaller value.
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
 
2384
  *Returns:* The smallest value in the initializer_list.
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
 
2398
  *Returns:* The larger value.
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
 
2412
  *Returns:* The largest value in the initializer_list.
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
 
2426
  *Returns:* `pair<const T&, const T&>(b, a)` if `b` is smaller than `a`,
2427
  and `pair<const T&, const T&>(a, b)` otherwise.
2428
 
2429
  *Remarks:* Returns `pair<const T&, const T&>(a, b)` when the arguments
@@ -2436,116 +3874,179 @@ 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
 
2444
  *Returns:* `pair<T, T>(x, y)`, where `x` has the smallest and `y` has
2445
  the largest value in the initializer list.
2446
 
2447
  *Remarks:* `x` is a copy of the leftmost argument when several arguments
2448
  are equivalent to the smallest. `y` is a copy of the rightmost argument
2449
  when several arguments are equivalent to the largest.
2450
 
2451
- *Complexity:* At most `(3/2) * t.size()` applications of the
2452
- corresponding predicate.
2453
 
2454
  ``` cpp
2455
  template<class ForwardIterator>
2456
- ForwardIterator min_element(ForwardIterator first, ForwardIterator last);
 
 
 
 
2457
 
2458
  template<class ForwardIterator, class Compare>
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
2472
  template<class ForwardIterator>
2473
- ForwardIterator max_element(ForwardIterator first, ForwardIterator last);
 
 
 
 
2474
  template<class ForwardIterator, class Compare>
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
2488
  template<class ForwardIterator>
2489
- pair<ForwardIterator, ForwardIterator>
2490
  minmax_element(ForwardIterator first, ForwardIterator last);
 
 
 
 
 
2491
  template<class ForwardIterator, class Compare>
2492
- pair<ForwardIterator, ForwardIterator>
2493
  minmax_element(ForwardIterator first, ForwardIterator last, Compare comp);
 
 
 
 
2494
  ```
2495
 
2496
  *Returns:* `make_pair(first, first)` if \[`first`, `last`) is empty,
2497
  otherwise `make_pair(m, M)`, where `m` is the first iterator in
2498
  \[`first`, `last`) such that no iterator in the range refers to a
2499
- smaller element, and where `M` is the last iterator in \[`first`,
2500
  `last`) such that no iterator in the range refers to a larger element.
2501
 
2502
- *Complexity:* At most $max(\lfloor{\frac{3}{2}} (N-1)\rfloor, 0)$
2503
- applications of the corresponding predicate, where N is
2504
- `distance(first, last)`.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2505
 
2506
  ### Lexicographical comparison <a id="alg.lex.comparison">[[alg.lex.comparison]]</a>
2507
 
2508
  ``` cpp
2509
  template<class InputIterator1, class InputIterator2>
2510
  bool
2511
  lexicographical_compare(InputIterator1 first1, InputIterator1 last1,
2512
  InputIterator2 first2, InputIterator2 last2);
 
 
 
 
 
2513
 
2514
  template<class InputIterator1, class InputIterator2, class Compare>
2515
  bool
2516
  lexicographical_compare(InputIterator1 first1, InputIterator1 last1,
2517
  InputIterator2 first2, InputIterator2 last2,
2518
  Compare comp);
 
 
 
 
 
 
2519
  ```
2520
 
2521
  *Returns:* `true` if the sequence of elements defined by the range
2522
  \[`first1`, `last1`) is lexicographically less than the sequence of
2523
  elements defined by the range \[`first2`, `last2`) and `false`
2524
  otherwise.
2525
 
2526
- *Complexity:* At most `2*min((last1 - first1), (last2 - first2))`
2527
  applications of the corresponding comparison.
2528
 
2529
  *Remarks:* If two sequences have the same number of elements and their
2530
- corresponding elements are equivalent, then neither sequence is
2531
  lexicographically less than the other. If one sequence is a prefix of
2532
  the other, then the shorter sequence is lexicographically less than the
2533
  longer sequence. Otherwise, the lexicographical comparison of the
2534
  sequences yields the same result as the comparison of the first
2535
  corresponding pair of elements that are not equivalent.
2536
 
 
 
 
 
2537
  ``` cpp
2538
- for ( ; first1 != last1 && first2 != last2 ; ++first1, ++first2) {
2539
  if (*first1 < *first2) return true;
2540
  if (*first2 < *first1) return false;
2541
  }
2542
  return first1 == last1 && first2 != last2;
2543
  ```
2544
 
2545
- *Remarks:*  An empty sequence is lexicographically less than any
2546
- non-empty sequence, but not less than any empty sequence.
 
 
2547
 
2548
  ### Permutation generators <a id="alg.permutation.generators">[[alg.permutation.generators]]</a>
2549
 
2550
  ``` cpp
2551
  template<class BidirectionalIterator>
@@ -2555,19 +4056,21 @@ template<class BidirectionalIterator>
2555
  template<class BidirectionalIterator, class Compare>
2556
  bool next_permutation(BidirectionalIterator first,
2557
  BidirectionalIterator last, Compare comp);
2558
  ```
2559
 
 
 
 
2560
  *Effects:* Takes a sequence defined by the range \[`first`, `last`) and
2561
  transforms it into the next permutation. The next permutation is found
2562
  by assuming that the set of all permutations is lexicographically sorted
2563
- with respect to `operator<` or `comp`. If such a permutation exists, it
2564
- returns `true`. Otherwise, it transforms the sequence into the smallest
2565
- permutation, that is, the ascendingly sorted one, and returns `false`.
2566
 
2567
- *Requires:* `BidirectionalIterator` shall satisfy the requirements of
2568
- `ValueSwappable` ([[swappable.requirements]]).
 
2569
 
2570
  *Complexity:* At most `(last - first) / 2` swaps.
2571
 
2572
  ``` cpp
2573
  template<class BidirectionalIterator>
@@ -2577,84 +4080,56 @@ template<class BidirectionalIterator>
2577
  template<class BidirectionalIterator, class Compare>
2578
  bool prev_permutation(BidirectionalIterator first,
2579
  BidirectionalIterator last, Compare comp);
2580
  ```
2581
 
 
 
 
2582
  *Effects:* Takes a sequence defined by the range \[`first`, `last`) and
2583
  transforms it into the previous permutation. The previous permutation is
2584
  found by assuming that the set of all permutations is lexicographically
2585
  sorted with respect to `operator<` or `comp`.
2586
 
2587
  *Returns:* `true` if such a permutation exists. Otherwise, it transforms
2588
  the sequence into the largest permutation, that is, the descendingly
2589
  sorted one, and returns `false`.
2590
 
2591
- *Requires:* `BidirectionalIterator` shall satisfy the requirements of
2592
- `ValueSwappable` ([[swappable.requirements]]).
2593
-
2594
  *Complexity:* At most `(last - first) / 2` swaps.
2595
 
2596
  ## C library algorithms <a id="alg.c.library">[[alg.c.library]]</a>
2597
 
2598
- Table  [[tab:algorithms.hdr.cstdlib]] describes some of the contents of
2599
- the header `<cstdlib>`.
2600
-
2601
- The contents are the same as the Standard C library header `<stdlib.h>`
2602
- with the following exceptions:
2603
-
2604
- The function signature:
2605
-
2606
- ``` cpp
2607
- bsearch(const void *, const void *, size_t, size_t,
2608
- int (*)(const void *, const void *));
2609
- ```
2610
-
2611
- is replaced by the two declarations:
2612
-
2613
- ``` cpp
2614
- extern "C" void* bsearch(const void* key, const void* base,
2615
- size_t nmemb, size_t size,
2616
- int (*compar)(const void*, const void*));
2617
- extern "C++" void* bsearch(const void* key, const void* base,
2618
- size_t nmemb, size_t size,
2619
- int (*compar)(const void*, const void*));
2620
- ```
2621
-
2622
- both of which have the same behavior as the original declaration.
2623
-
2624
- The function signature:
2625
 
2626
  ``` cpp
2627
- qsort(void *, size_t, size_t,
2628
- int (*)(const void *, const void *));
 
 
 
 
2629
  ```
2630
 
2631
- is replaced by the two declarations:
2632
-
2633
- ``` cpp
2634
- extern "C" void qsort(void* base, size_t nmemb, size_t size,
2635
- int (*compar)(const void*, const void*));
2636
- extern "C++" void qsort(void* base, size_t nmemb, size_t size,
2637
- int (*compar)(const void*, const void*));
2638
- ```
2639
 
2640
- both of which have the same behavior as the original declaration. The
2641
- behavior is undefined unless the objects in the array pointed to by
2642
- `base` are of trivial type.
2643
 
2644
- Because the function argument `compar()` may throw an exception,
2645
- `bsearch()` and `qsort()` are allowed to propagate the exception (
2646
- [[res.on.exception.handling]]).
2647
 
2648
- ISO C 7.10.5.
2649
 
2650
  <!-- Link reference definitions -->
2651
  [alg.adjacent.find]: #alg.adjacent.find
2652
  [alg.all_of]: #alg.all_of
2653
  [alg.any_of]: #alg.any_of
2654
  [alg.binary.search]: #alg.binary.search
2655
  [alg.c.library]: #alg.c.library
 
2656
  [alg.copy]: #alg.copy
2657
  [alg.count]: #alg.count
2658
  [alg.equal]: #alg.equal
2659
  [alg.fill]: #alg.fill
2660
  [alg.find]: #alg.find
@@ -2672,10 +4147,11 @@ ISO C 7.10.5.
2672
  [alg.none_of]: #alg.none_of
2673
  [alg.nonmodifying]: #alg.nonmodifying
2674
  [alg.nth.element]: #alg.nth.element
2675
  [alg.partitions]: #alg.partitions
2676
  [alg.permutation.generators]: #alg.permutation.generators
 
2677
  [alg.random.shuffle]: #alg.random.shuffle
2678
  [alg.remove]: #alg.remove
2679
  [alg.replace]: #alg.replace
2680
  [alg.reverse]: #alg.reverse
2681
  [alg.rotate]: #alg.rotate
@@ -2685,34 +4161,42 @@ ISO C 7.10.5.
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
2695
  [containers]: containers.md#containers
2696
  [conv]: conv.md#conv
2697
  [conv.integral]: conv.md#conv.integral
2698
- [copyassignable]: #copyassignable
2699
- [copyconstructible]: #copyconstructible
2700
  [equal.range]: #equal.range
 
2701
  [forward.iterators]: iterators.md#forward.iterators
2702
  [function.objects]: utilities.md#function.objects
2703
  [includes]: #includes
2704
  [input.iterators]: iterators.md#input.iterators
 
 
2705
  [is.heap]: #is.heap
2706
  [is.sorted]: #is.sorted
2707
  [iterator.requirements]: iterators.md#iterator.requirements
2708
- [lessthancomparable]: #lessthancomparable
2709
  [lower.bound]: #lower.bound
2710
  [make.heap]: #make.heap
2711
  [mismatch]: #mismatch
2712
- [moveassignable]: #moveassignable
2713
- [moveconstructible]: #moveconstructible
2714
  [multiset]: containers.md#multiset
2715
  [output.iterators]: iterators.md#output.iterators
2716
  [partial.sort]: #partial.sort
2717
  [partial.sort.copy]: #partial.sort.copy
2718
  [pop.heap]: #pop.heap
@@ -2727,12 +4211,17 @@ ISO C 7.10.5.
2727
  [set.union]: #set.union
2728
  [sort]: #sort
2729
  [sort.heap]: #sort.heap
2730
  [stable.sort]: #stable.sort
2731
  [swappable.requirements]: library.md#swappable.requirements
2732
- [tab:algorithms.hdr.cstdlib]: #tab:algorithms.hdr.cstdlib
2733
  [tab:algorithms.summary]: #tab:algorithms.summary
 
 
 
 
 
 
2734
  [upper.bound]: #upper.bound
2735
 
2736
  [^1]: The decision whether to include a copying version was usually
2737
  based on complexity considerations. When the cost of doing the
2738
  operation dominates the cost of copy, the copying version is not
@@ -2745,5 +4234,7 @@ ISO C 7.10.5.
2745
 
2746
  [^3]: `move_backward` should be used instead of move when last is in the
2747
  range \[`result - (last - first)`, `result`).
2748
 
2749
  [^4]: The use of fully closed ranges is intentional.
 
 
 
5
  This Clause describes components that C++programs may use to perform
6
  algorithmic operations on containers (Clause  [[containers]]) and other
7
  sequences.
8
 
9
  The following subclauses describe components for non-modifying sequence
10
+ operations, modifying sequence operations, sorting and related
11
  operations, and algorithms from the ISO C library, as summarized in
12
  Table  [[tab:algorithms.summary]].
13
 
14
  **Table: Algorithms library summary** <a id="tab:algorithms.summary">[tab:algorithms.summary]</a>
15
 
 
18
  | [[alg.nonmodifying]] | Non-modifying sequence operations | |
19
  | [[alg.modifying.operations]] | Mutating sequence operations | `<algorithm>` |
20
  | [[alg.sorting]] | Sorting and related operations | |
21
  | [[alg.c.library]] | C library algorithms | `<cstdlib>` |
22
 
23
+
24
+ ## Header `<algorithm>` synopsis <a id="algorithm.syn">[[algorithm.syn]]</a>
25
+
26
  ``` cpp
27
  #include <initializer_list>
28
 
29
  namespace std {
30
+ // [alg.nonmodifying], non-modifying sequence operations
31
+ // [alg.all_of], all of
32
  template <class InputIterator, class Predicate>
33
  bool all_of(InputIterator first, InputIterator last, Predicate pred);
34
+ template <class ExecutionPolicy, class ForwardIterator, class Predicate>
35
+ bool all_of(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
36
+ ForwardIterator first, ForwardIterator last, Predicate pred);
37
+
38
+ // [alg.any_of], any of
39
  template <class InputIterator, class Predicate>
40
  bool any_of(InputIterator first, InputIterator last, Predicate pred);
41
+ template <class ExecutionPolicy, class ForwardIterator, class Predicate>
42
+ bool any_of(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
43
+ ForwardIterator first, ForwardIterator last, Predicate pred);
44
+
45
+ // [alg.none_of], none of
46
  template <class InputIterator, class Predicate>
47
  bool none_of(InputIterator first, InputIterator last, Predicate pred);
48
+ template <class ExecutionPolicy, class ForwardIterator, class Predicate>
49
+ bool none_of(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
50
+ ForwardIterator first, ForwardIterator last, Predicate pred);
51
 
52
+ // [alg.foreach], for each
53
  template<class InputIterator, class Function>
54
  Function for_each(InputIterator first, InputIterator last, Function f);
55
+ template<class ExecutionPolicy, class ForwardIterator, class Function>
56
+ void for_each(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
57
+ ForwardIterator first, ForwardIterator last, Function f);
58
+ template<class InputIterator, class Size, class Function>
59
+ InputIterator for_each_n(InputIterator first, Size n, Function f);
60
+ template<class ExecutionPolicy, class ForwardIterator, class Size, class Function>
61
+ ForwardIterator for_each_n(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
62
+ ForwardIterator first, Size n, Function f);
63
+
64
+ // [alg.find], find
65
  template<class InputIterator, class T>
66
  InputIterator find(InputIterator first, InputIterator last,
67
  const T& value);
68
+ template<class ExecutionPolicy, class ForwardIterator, class T>
69
+ ForwardIterator find(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
70
+ ForwardIterator first, ForwardIterator last,
71
+ const T& value);
72
  template<class InputIterator, class Predicate>
73
  InputIterator find_if(InputIterator first, InputIterator last,
74
  Predicate pred);
75
+ template<class ExecutionPolicy, class ForwardIterator, class Predicate>
76
+ ForwardIterator find_if(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
77
+ ForwardIterator first, ForwardIterator last,
78
+ Predicate pred);
79
  template<class InputIterator, class Predicate>
80
  InputIterator find_if_not(InputIterator first, InputIterator last,
81
  Predicate pred);
82
+ template<class ExecutionPolicy, class ForwardIterator, class Predicate>
83
+ ForwardIterator find_if_not(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
84
+ ForwardIterator first, ForwardIterator last,
85
+ Predicate pred);
86
+
87
+ // [alg.find.end], find end
88
  template<class ForwardIterator1, class ForwardIterator2>
89
  ForwardIterator1
90
  find_end(ForwardIterator1 first1, ForwardIterator1 last1,
91
  ForwardIterator2 first2, ForwardIterator2 last2);
92
+ template<class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
 
93
  ForwardIterator1
94
  find_end(ForwardIterator1 first1, ForwardIterator1 last1,
95
  ForwardIterator2 first2, ForwardIterator2 last2,
96
  BinaryPredicate pred);
97
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
98
+ ForwardIterator1
99
+ find_end(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
100
+ ForwardIterator1 first1, ForwardIterator1 last1,
101
+ ForwardIterator2 first2, ForwardIterator2 last2);
102
+ template<class ExecutionPolicy, class ForwardIterator1,
103
+ class ForwardIterator2, class BinaryPredicate>
104
+ ForwardIterator1
105
+ find_end(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
106
+ ForwardIterator1 first1, ForwardIterator1 last1,
107
+ ForwardIterator2 first2, ForwardIterator2 last2,
108
+ BinaryPredicate pred);
109
 
110
+ // [alg.find.first.of], find first
111
  template<class InputIterator, class ForwardIterator>
112
  InputIterator
113
  find_first_of(InputIterator first1, InputIterator last1,
114
  ForwardIterator first2, ForwardIterator last2);
115
+ template<class InputIterator, class ForwardIterator, class BinaryPredicate>
 
116
  InputIterator
117
  find_first_of(InputIterator first1, InputIterator last1,
118
  ForwardIterator first2, ForwardIterator last2,
119
  BinaryPredicate pred);
120
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
121
+ ForwardIterator1
122
+ find_first_of(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
123
+ ForwardIterator1 first1, ForwardIterator1 last1,
124
+ ForwardIterator2 first2, ForwardIterator2 last2);
125
+ template<class ExecutionPolicy, class ForwardIterator1,
126
+ class ForwardIterator2, class BinaryPredicate>
127
+ ForwardIterator1
128
+ find_first_of(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
129
+ ForwardIterator1 first1, ForwardIterator1 last1,
130
+ ForwardIterator2 first2, ForwardIterator2 last2,
131
+ BinaryPredicate pred);
132
 
133
+ // [alg.adjacent.find], adjacent find
134
  template<class ForwardIterator>
135
  ForwardIterator adjacent_find(ForwardIterator first,
136
  ForwardIterator last);
137
  template<class ForwardIterator, class BinaryPredicate>
138
  ForwardIterator adjacent_find(ForwardIterator first,
139
  ForwardIterator last,
140
  BinaryPredicate pred);
141
+ template<class ExecutionPolicy, class ForwardIterator>
142
+ ForwardIterator adjacent_find(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
143
+ ForwardIterator first,
144
+ ForwardIterator last);
145
+ template<class ExecutionPolicy, class ForwardIterator, class BinaryPredicate>
146
+ ForwardIterator adjacent_find(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
147
+ ForwardIterator first,
148
+ ForwardIterator last,
149
+ BinaryPredicate pred);
150
 
151
+ // [alg.count], count
152
  template<class InputIterator, class T>
153
  typename iterator_traits<InputIterator>::difference_type
154
  count(InputIterator first, InputIterator last, const T& value);
155
+ template<class ExecutionPolicy, class ForwardIterator, class T>
156
+ typename iterator_traits<ForwardIterator>::difference_type
157
+ count(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
158
+ ForwardIterator first, ForwardIterator last, const T& value);
159
  template<class InputIterator, class Predicate>
160
  typename iterator_traits<InputIterator>::difference_type
161
  count_if(InputIterator first, InputIterator last, Predicate pred);
162
+ template<class ExecutionPolicy, class ForwardIterator, class Predicate>
163
+ typename iterator_traits<ForwardIterator>::difference_type
164
+ count_if(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
165
+ ForwardIterator first, ForwardIterator last, Predicate pred);
166
 
167
+ // [mismatch], mismatch
168
  template<class InputIterator1, class InputIterator2>
169
  pair<InputIterator1, InputIterator2>
170
  mismatch(InputIterator1 first1, InputIterator1 last1,
171
  InputIterator2 first2);
172
+ template<class InputIterator1, class InputIterator2, class BinaryPredicate>
 
173
  pair<InputIterator1, InputIterator2>
174
  mismatch(InputIterator1 first1, InputIterator1 last1,
175
  InputIterator2 first2, BinaryPredicate pred);
 
176
  template<class InputIterator1, class InputIterator2>
177
  pair<InputIterator1, InputIterator2>
178
  mismatch(InputIterator1 first1, InputIterator1 last1,
179
  InputIterator2 first2, InputIterator2 last2);
180
+ template<class InputIterator1, class InputIterator2, class BinaryPredicate>
 
 
181
  pair<InputIterator1, InputIterator2>
182
  mismatch(InputIterator1 first1, InputIterator1 last1,
183
  InputIterator2 first2, InputIterator2 last2,
184
  BinaryPredicate pred);
185
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
186
+ pair<ForwardIterator1, ForwardIterator2>
187
+ mismatch(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
188
+ ForwardIterator1 first1, ForwardIterator1 last1,
189
+ ForwardIterator2 first2);
190
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
191
+ class BinaryPredicate>
192
+ pair<ForwardIterator1, ForwardIterator2>
193
+ mismatch(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
194
+ ForwardIterator1 first1, ForwardIterator1 last1,
195
+ ForwardIterator2 first2, BinaryPredicate pred);
196
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
197
+ pair<ForwardIterator1, ForwardIterator2>
198
+ mismatch(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
199
+ ForwardIterator1 first1, ForwardIterator1 last1,
200
+ ForwardIterator2 first2, ForwardIterator2 last2);
201
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
202
+ class BinaryPredicate>
203
+ pair<ForwardIterator1, ForwardIterator2>
204
+ mismatch(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
205
+ ForwardIterator1 first1, ForwardIterator1 last1,
206
+ ForwardIterator2 first2, ForwardIterator2 last2,
207
+ BinaryPredicate pred);
208
 
209
+ // [alg.equal], equal
210
  template<class InputIterator1, class InputIterator2>
211
  bool equal(InputIterator1 first1, InputIterator1 last1,
212
  InputIterator2 first2);
213
+ template<class InputIterator1, class InputIterator2, class BinaryPredicate>
 
214
  bool equal(InputIterator1 first1, InputIterator1 last1,
215
  InputIterator2 first2, BinaryPredicate pred);
 
216
  template<class InputIterator1, class InputIterator2>
217
  bool equal(InputIterator1 first1, InputIterator1 last1,
218
  InputIterator2 first2, InputIterator2 last2);
219
+ template<class InputIterator1, class InputIterator2, class BinaryPredicate>
 
 
220
  bool equal(InputIterator1 first1, InputIterator1 last1,
221
  InputIterator2 first2, InputIterator2 last2,
222
  BinaryPredicate pred);
223
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
224
+ bool equal(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
225
+ ForwardIterator1 first1, ForwardIterator1 last1,
226
+ ForwardIterator2 first2);
227
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
228
+ class BinaryPredicate>
229
+ bool equal(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
230
+ ForwardIterator1 first1, ForwardIterator1 last1,
231
+ ForwardIterator2 first2, BinaryPredicate pred);
232
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
233
+ bool equal(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
234
+ ForwardIterator1 first1, ForwardIterator1 last1,
235
+ ForwardIterator2 first2, ForwardIterator2 last2);
236
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
237
+ class BinaryPredicate>
238
+ bool equal(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
239
+ ForwardIterator1 first1, ForwardIterator1 last1,
240
+ ForwardIterator2 first2, ForwardIterator2 last2,
241
+ BinaryPredicate pred);
242
 
243
+ // [alg.is_permutation], is permutation
244
  template<class ForwardIterator1, class ForwardIterator2>
245
  bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
246
  ForwardIterator2 first2);
247
+ template<class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
 
248
  bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
249
  ForwardIterator2 first2, BinaryPredicate pred);
250
 
251
  template<class ForwardIterator1, class ForwardIterator2>
252
  bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
253
  ForwardIterator2 first2, ForwardIterator2 last2);
254
 
255
+ template<class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
 
256
  bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
257
  ForwardIterator2 first2, ForwardIterator2 last2,
258
  BinaryPredicate pred);
259
 
260
+ // [alg.search], search
261
  template<class ForwardIterator1, class ForwardIterator2>
262
  ForwardIterator1 search(
263
  ForwardIterator1 first1, ForwardIterator1 last1,
264
  ForwardIterator2 first2, ForwardIterator2 last2);
265
+ template<class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
266
+ ForwardIterator1 search(
267
+ ForwardIterator1 first1, ForwardIterator1 last1,
268
+ ForwardIterator2 first2, ForwardIterator2 last2,
269
+ BinaryPredicate pred);
270
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
271
+ ForwardIterator1 search(
272
+ ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
273
+ ForwardIterator1 first1, ForwardIterator1 last1,
274
+ ForwardIterator2 first2, ForwardIterator2 last2);
275
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
276
  class BinaryPredicate>
277
  ForwardIterator1 search(
278
+ ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
279
  ForwardIterator1 first1, ForwardIterator1 last1,
280
  ForwardIterator2 first2, ForwardIterator2 last2,
281
  BinaryPredicate pred);
282
  template<class ForwardIterator, class Size, class T>
283
  ForwardIterator search_n(ForwardIterator first, ForwardIterator last,
284
  Size count, const T& value);
285
+ template<class ForwardIterator, class Size, class T, class BinaryPredicate>
 
286
  ForwardIterator search_n(ForwardIterator first, ForwardIterator last,
287
  Size count, const T& value,
288
  BinaryPredicate pred);
289
+ template<class ExecutionPolicy, class ForwardIterator, class Size, class T>
290
+ ForwardIterator search_n(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
291
+ ForwardIterator first, ForwardIterator last,
292
+ Size count, const T& value);
293
+ template<class ExecutionPolicy, class ForwardIterator, class Size, class T,
294
+ class BinaryPredicate>
295
+ ForwardIterator search_n(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
296
+ ForwardIterator first, ForwardIterator last,
297
+ Size count, const T& value,
298
+ BinaryPredicate pred);
299
 
300
+ template <class ForwardIterator, class Searcher>
301
+ ForwardIterator search(ForwardIterator first, ForwardIterator last,
302
+ const Searcher& searcher);
303
+
304
+ // [alg.modifying.operations], modifying sequence operations
305
+ // [alg.copy], copy
306
  template<class InputIterator, class OutputIterator>
307
  OutputIterator copy(InputIterator first, InputIterator last,
308
  OutputIterator result);
309
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
310
+ ForwardIterator2 copy(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
311
+ ForwardIterator1 first, ForwardIterator1 last,
312
+ ForwardIterator2 result);
313
  template<class InputIterator, class Size, class OutputIterator>
314
  OutputIterator copy_n(InputIterator first, Size n,
315
  OutputIterator result);
316
+ template<class ExecutionPolicy, class ForwardIterator1, class Size,
317
+ class ForwardIterator2>
318
+ ForwardIterator2 copy_n(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
319
+ ForwardIterator1 first, Size n,
320
+ ForwardIterator2 result);
321
  template<class InputIterator, class OutputIterator, class Predicate>
322
  OutputIterator copy_if(InputIterator first, InputIterator last,
323
  OutputIterator result, Predicate pred);
324
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
325
+ class Predicate>
326
+ ForwardIterator2 copy_if(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
327
+ ForwardIterator1 first, ForwardIterator1 last,
328
+ ForwardIterator2 result, Predicate pred);
329
  template<class BidirectionalIterator1, class BidirectionalIterator2>
330
  BidirectionalIterator2 copy_backward(
331
  BidirectionalIterator1 first, BidirectionalIterator1 last,
332
  BidirectionalIterator2 result);
333
 
334
+ // [alg.move], move
335
  template<class InputIterator, class OutputIterator>
336
  OutputIterator move(InputIterator first, InputIterator last,
337
  OutputIterator result);
338
+ template<class ExecutionPolicy, class ForwardIterator1,
339
+ class ForwardIterator2>
340
+ ForwardIterator2 move(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
341
+ ForwardIterator1 first, ForwardIterator1 last,
342
+ ForwardIterator2 result);
343
  template<class BidirectionalIterator1, class BidirectionalIterator2>
344
  BidirectionalIterator2 move_backward(
345
  BidirectionalIterator1 first, BidirectionalIterator1 last,
346
  BidirectionalIterator2 result);
347
 
348
+ // [alg.swap], swap
349
  template<class ForwardIterator1, class ForwardIterator2>
350
+ ForwardIterator2 swap_ranges(ForwardIterator1 first1, ForwardIterator1 last1,
351
+ ForwardIterator2 first2);
352
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
353
+ ForwardIterator2 swap_ranges(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
354
+ ForwardIterator1 first1, ForwardIterator1 last1,
355
+ ForwardIterator2 first2);
356
  template<class ForwardIterator1, class ForwardIterator2>
357
  void iter_swap(ForwardIterator1 a, ForwardIterator2 b);
358
 
359
+ // [alg.transform], transform
360
  template<class InputIterator, class OutputIterator, class UnaryOperation>
361
  OutputIterator transform(InputIterator first, InputIterator last,
362
  OutputIterator result, UnaryOperation op);
363
  template<class InputIterator1, class InputIterator2, class OutputIterator,
364
  class BinaryOperation>
365
  OutputIterator transform(InputIterator1 first1, InputIterator1 last1,
366
  InputIterator2 first2, OutputIterator result,
367
  BinaryOperation binary_op);
368
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
369
+ class UnaryOperation>
370
+ ForwardIterator2 transform(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
371
+ ForwardIterator1 first, ForwardIterator1 last,
372
+ ForwardIterator2 result, UnaryOperation op);
373
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
374
+ class ForwardIterator, class BinaryOperation>
375
+ ForwardIterator transform(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
376
+ ForwardIterator1 first1, ForwardIterator1 last1,
377
+ ForwardIterator2 first2, ForwardIterator result,
378
+ BinaryOperation binary_op);
379
 
380
+ // [alg.replace], replace
381
  template<class ForwardIterator, class T>
382
  void replace(ForwardIterator first, ForwardIterator last,
383
  const T& old_value, const T& new_value);
384
+ template<class ExecutionPolicy, class ForwardIterator, class T>
385
+ void replace(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
386
+ ForwardIterator first, ForwardIterator last,
387
+ const T& old_value, const T& new_value);
388
  template<class ForwardIterator, class Predicate, class T>
389
  void replace_if(ForwardIterator first, ForwardIterator last,
390
  Predicate pred, const T& new_value);
391
+ template<class ExecutionPolicy, class ForwardIterator, class Predicate, class T>
392
+ void replace_if(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
393
+ ForwardIterator first, ForwardIterator last,
394
+ Predicate pred, const T& new_value);
395
  template<class InputIterator, class OutputIterator, class T>
396
  OutputIterator replace_copy(InputIterator first, InputIterator last,
397
  OutputIterator result,
398
  const T& old_value, const T& new_value);
399
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class T>
400
+ ForwardIterator2 replace_copy(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
401
+ ForwardIterator1 first, ForwardIterator1 last,
402
+ ForwardIterator2 result,
403
+ const T& old_value, const T& new_value);
404
  template<class InputIterator, class OutputIterator, class Predicate, class T>
405
  OutputIterator replace_copy_if(InputIterator first, InputIterator last,
406
  OutputIterator result,
407
  Predicate pred, const T& new_value);
408
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
409
+ class Predicate, class T>
410
+ ForwardIterator2 replace_copy_if(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
411
+ ForwardIterator1 first, ForwardIterator1 last,
412
+ ForwardIterator2 result,
413
+ Predicate pred, const T& new_value);
414
 
415
+ // [alg.fill], fill
416
  template<class ForwardIterator, class T>
417
  void fill(ForwardIterator first, ForwardIterator last, const T& value);
418
+ template<class ExecutionPolicy, class ForwardIterator,
419
+ class T>
420
+ void fill(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
421
+ ForwardIterator first, ForwardIterator last, const T& value);
422
  template<class OutputIterator, class Size, class T>
423
  OutputIterator fill_n(OutputIterator first, Size n, const T& value);
424
+ template<class ExecutionPolicy, class ForwardIterator,
425
+ class Size, class T>
426
+ ForwardIterator fill_n(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
427
+ ForwardIterator first, Size n, const T& value);
428
 
429
+ // [alg.generate], generate
430
  template<class ForwardIterator, class Generator>
431
  void generate(ForwardIterator first, ForwardIterator last,
432
  Generator gen);
433
+ template<class ExecutionPolicy, class ForwardIterator, class Generator>
434
+ void generate(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
435
+ ForwardIterator first, ForwardIterator last,
436
+ Generator gen);
437
  template<class OutputIterator, class Size, class Generator>
438
  OutputIterator generate_n(OutputIterator first, Size n, Generator gen);
439
+ template<class ExecutionPolicy, class ForwardIterator, class Size, class Generator>
440
+ ForwardIterator generate_n(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
441
+ ForwardIterator first, Size n, Generator gen);
442
 
443
+ // [alg.remove], remove
444
  template<class ForwardIterator, class T>
445
  ForwardIterator remove(ForwardIterator first, ForwardIterator last,
446
  const T& value);
447
+ template<class ExecutionPolicy, class ForwardIterator, class T>
448
+ ForwardIterator remove(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
449
+ ForwardIterator first, ForwardIterator last,
450
+ const T& value);
451
  template<class ForwardIterator, class Predicate>
452
  ForwardIterator remove_if(ForwardIterator first, ForwardIterator last,
453
  Predicate pred);
454
+ template<class ExecutionPolicy, class ForwardIterator, class Predicate>
455
+ ForwardIterator remove_if(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
456
+ ForwardIterator first, ForwardIterator last,
457
+ Predicate pred);
458
  template<class InputIterator, class OutputIterator, class T>
459
  OutputIterator remove_copy(InputIterator first, InputIterator last,
460
  OutputIterator result, const T& value);
461
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
462
+ class T>
463
+ ForwardIterator2 remove_copy(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
464
+ ForwardIterator1 first, ForwardIterator1 last,
465
+ ForwardIterator2 result, const T& value);
466
  template<class InputIterator, class OutputIterator, class Predicate>
467
  OutputIterator remove_copy_if(InputIterator first, InputIterator last,
468
  OutputIterator result, Predicate pred);
469
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
470
+ class Predicate>
471
+ ForwardIterator2 remove_copy_if(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
472
+ ForwardIterator1 first, ForwardIterator1 last,
473
+ ForwardIterator2 result, Predicate pred);
474
 
475
+ // [alg.unique], unique
476
  template<class ForwardIterator>
477
  ForwardIterator unique(ForwardIterator first, ForwardIterator last);
478
  template<class ForwardIterator, class BinaryPredicate>
479
  ForwardIterator unique(ForwardIterator first, ForwardIterator last,
480
  BinaryPredicate pred);
481
+ template<class ExecutionPolicy, class ForwardIterator>
482
+ ForwardIterator unique(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
483
+ ForwardIterator first, ForwardIterator last);
484
+ template<class ExecutionPolicy, class ForwardIterator, class BinaryPredicate>
485
+ ForwardIterator unique(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
486
+ ForwardIterator first, ForwardIterator last,
487
+ BinaryPredicate pred);
488
  template<class InputIterator, class OutputIterator>
489
  OutputIterator unique_copy(InputIterator first, InputIterator last,
490
  OutputIterator result);
491
  template<class InputIterator, class OutputIterator, class BinaryPredicate>
492
  OutputIterator unique_copy(InputIterator first, InputIterator last,
493
  OutputIterator result, BinaryPredicate pred);
494
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
495
+ ForwardIterator2 unique_copy(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
496
+ ForwardIterator1 first, ForwardIterator1 last,
497
+ ForwardIterator2 result);
498
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
499
+ class BinaryPredicate>
500
+ ForwardIterator2 unique_copy(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
501
+ ForwardIterator1 first, ForwardIterator1 last,
502
+ ForwardIterator2 result, BinaryPredicate pred);
503
 
504
+ // [alg.reverse], reverse
505
  template<class BidirectionalIterator>
506
  void reverse(BidirectionalIterator first, BidirectionalIterator last);
507
+ template<class ExecutionPolicy, class BidirectionalIterator>
508
+ void reverse(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
509
+ BidirectionalIterator first, BidirectionalIterator last);
510
  template<class BidirectionalIterator, class OutputIterator>
511
  OutputIterator reverse_copy(BidirectionalIterator first,
512
  BidirectionalIterator last,
513
  OutputIterator result);
514
+ template<class ExecutionPolicy, class BidirectionalIterator, class ForwardIterator>
515
+ ForwardIterator reverse_copy(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
516
+ BidirectionalIterator first,
517
+ BidirectionalIterator last,
518
+ ForwardIterator result);
519
 
520
+ // [alg.rotate], rotate
521
  template<class ForwardIterator>
522
+ ForwardIterator rotate(ForwardIterator first,
523
+ ForwardIterator middle,
524
+ ForwardIterator last);
525
+ template<class ExecutionPolicy, class ForwardIterator>
526
+ ForwardIterator rotate(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
527
+ ForwardIterator first,
528
+ ForwardIterator middle,
529
  ForwardIterator last);
530
  template<class ForwardIterator, class OutputIterator>
531
  OutputIterator rotate_copy(
532
  ForwardIterator first, ForwardIterator middle,
533
  ForwardIterator last, OutputIterator result);
534
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
535
+ ForwardIterator2 rotate_copy(
536
+ ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
537
+ ForwardIterator1 first, ForwardIterator1 middle,
538
+ ForwardIterator1 last, ForwardIterator2 result);
539
 
540
+ // [alg.random.sample], sample
541
+ template<class PopulationIterator, class SampleIterator,
542
+ class Distance, class UniformRandomBitGenerator>
543
+ SampleIterator sample(PopulationIterator first, PopulationIterator last,
544
+ SampleIterator out, Distance n,
545
+ UniformRandomBitGenerator&& g);
 
 
546
 
547
+ // [alg.random.shuffle], shuffle
548
+ template<class RandomAccessIterator, class UniformRandomBitGenerator>
549
  void shuffle(RandomAccessIterator first,
550
  RandomAccessIterator last,
551
+ UniformRandomBitGenerator&& g);
552
 
553
+ // [alg.partitions], partitions
554
  template <class InputIterator, class Predicate>
555
  bool is_partitioned(InputIterator first, InputIterator last, Predicate pred);
556
+ template <class ExecutionPolicy, class ForwardIterator, class Predicate>
557
+ bool is_partitioned(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
558
+ ForwardIterator first, ForwardIterator last, Predicate pred);
559
 
560
  template<class ForwardIterator, class Predicate>
561
  ForwardIterator partition(ForwardIterator first,
562
  ForwardIterator last,
563
  Predicate pred);
564
+ template<class ExecutionPolicy, class ForwardIterator, class Predicate>
565
+ ForwardIterator partition(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
566
+ ForwardIterator first,
567
+ ForwardIterator last,
568
+ Predicate pred);
569
  template<class BidirectionalIterator, class Predicate>
570
  BidirectionalIterator stable_partition(BidirectionalIterator first,
571
  BidirectionalIterator last,
572
  Predicate pred);
573
+ template<class ExecutionPolicy, class BidirectionalIterator, class Predicate>
574
+ BidirectionalIterator stable_partition(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
575
+ BidirectionalIterator first,
576
+ BidirectionalIterator last,
577
+ Predicate pred);
578
  template <class InputIterator, class OutputIterator1,
579
  class OutputIterator2, class Predicate>
580
  pair<OutputIterator1, OutputIterator2>
581
  partition_copy(InputIterator first, InputIterator last,
582
  OutputIterator1 out_true, OutputIterator2 out_false,
583
  Predicate pred);
584
+ template <class ExecutionPolicy, class ForwardIterator, class ForwardIterator1,
585
+ class ForwardIterator2, class Predicate>
586
+ pair<ForwardIterator1, ForwardIterator2>
587
+ partition_copy(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
588
+ ForwardIterator first, ForwardIterator last,
589
+ ForwardIterator1 out_true, ForwardIterator2 out_false,
590
+ Predicate pred);
591
  template<class ForwardIterator, class Predicate>
592
  ForwardIterator partition_point(ForwardIterator first,
593
  ForwardIterator last,
594
  Predicate pred);
595
 
596
+ // [alg.sorting], sorting and related operations
597
+ // [alg.sort], sorting
598
  template<class RandomAccessIterator>
599
  void sort(RandomAccessIterator first, RandomAccessIterator last);
600
  template<class RandomAccessIterator, class Compare>
601
  void sort(RandomAccessIterator first, RandomAccessIterator last,
602
  Compare comp);
603
+ template<class ExecutionPolicy, class RandomAccessIterator>
604
+ void sort(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
605
+ RandomAccessIterator first, RandomAccessIterator last);
606
+ template<class ExecutionPolicy, class RandomAccessIterator, class Compare>
607
+ void sort(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
608
+ RandomAccessIterator first, RandomAccessIterator last,
609
+ Compare comp);
610
 
611
  template<class RandomAccessIterator>
612
  void stable_sort(RandomAccessIterator first, RandomAccessIterator last);
613
  template<class RandomAccessIterator, class Compare>
614
  void stable_sort(RandomAccessIterator first, RandomAccessIterator last,
615
  Compare comp);
616
+ template<class ExecutionPolicy, class RandomAccessIterator>
617
+ void stable_sort(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
618
+ RandomAccessIterator first, RandomAccessIterator last);
619
+ template<class ExecutionPolicy, class RandomAccessIterator, class Compare>
620
+ void stable_sort(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
621
+ RandomAccessIterator first, RandomAccessIterator last,
622
+ Compare comp);
623
 
624
  template<class RandomAccessIterator>
625
  void partial_sort(RandomAccessIterator first,
626
  RandomAccessIterator middle,
627
  RandomAccessIterator last);
628
  template<class RandomAccessIterator, class Compare>
629
  void partial_sort(RandomAccessIterator first,
630
  RandomAccessIterator middle,
631
  RandomAccessIterator last, Compare comp);
632
+ template<class ExecutionPolicy, class RandomAccessIterator>
633
+ void partial_sort(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
634
+ RandomAccessIterator first,
635
+ RandomAccessIterator middle,
636
+ RandomAccessIterator last);
637
+ template<class ExecutionPolicy, class RandomAccessIterator, class Compare>
638
+ void partial_sort(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
639
+ RandomAccessIterator first,
640
+ RandomAccessIterator middle,
641
+ RandomAccessIterator last, Compare comp);
642
  template<class InputIterator, class RandomAccessIterator>
643
  RandomAccessIterator partial_sort_copy(
644
  InputIterator first, InputIterator last,
645
  RandomAccessIterator result_first,
646
  RandomAccessIterator result_last);
 
648
  RandomAccessIterator partial_sort_copy(
649
  InputIterator first, InputIterator last,
650
  RandomAccessIterator result_first,
651
  RandomAccessIterator result_last,
652
  Compare comp);
653
+ template<class ExecutionPolicy, class ForwardIterator, class RandomAccessIterator>
654
+ RandomAccessIterator partial_sort_copy(
655
+ ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
656
+ ForwardIterator first, ForwardIterator last,
657
+ RandomAccessIterator result_first,
658
+ RandomAccessIterator result_last);
659
+ template<class ExecutionPolicy, class ForwardIterator, class RandomAccessIterator,
660
+ class Compare>
661
+ RandomAccessIterator partial_sort_copy(
662
+ ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
663
+ ForwardIterator first, ForwardIterator last,
664
+ RandomAccessIterator result_first,
665
+ RandomAccessIterator result_last,
666
+ Compare comp);
667
  template<class ForwardIterator>
668
  bool is_sorted(ForwardIterator first, ForwardIterator last);
669
  template<class ForwardIterator, class Compare>
670
  bool is_sorted(ForwardIterator first, ForwardIterator last,
671
  Compare comp);
672
+ template<class ExecutionPolicy, class ForwardIterator>
673
+ bool is_sorted(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
674
+ ForwardIterator first, ForwardIterator last);
675
+ template<class ExecutionPolicy, class ForwardIterator, class Compare>
676
+ bool is_sorted(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
677
+ ForwardIterator first, ForwardIterator last,
678
+ Compare comp);
679
  template<class ForwardIterator>
680
  ForwardIterator is_sorted_until(ForwardIterator first, ForwardIterator last);
681
  template<class ForwardIterator, class Compare>
682
  ForwardIterator is_sorted_until(ForwardIterator first, ForwardIterator last,
683
  Compare comp);
684
+ template<class ExecutionPolicy, class ForwardIterator>
685
+ ForwardIterator is_sorted_until(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
686
+ ForwardIterator first, ForwardIterator last);
687
+ template<class ExecutionPolicy, class ForwardIterator, class Compare>
688
+ ForwardIterator is_sorted_until(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
689
+ ForwardIterator first, ForwardIterator last,
690
+ Compare comp);
691
 
692
+ // [alg.nth.element], Nth element
693
  template<class RandomAccessIterator>
694
  void nth_element(RandomAccessIterator first, RandomAccessIterator nth,
695
  RandomAccessIterator last);
696
  template<class RandomAccessIterator, class Compare>
697
  void nth_element(RandomAccessIterator first, RandomAccessIterator nth,
698
  RandomAccessIterator last, Compare comp);
699
+ template<class ExecutionPolicy, class RandomAccessIterator>
700
+ void nth_element(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
701
+ RandomAccessIterator first, RandomAccessIterator nth,
702
+ RandomAccessIterator last);
703
+ template<class ExecutionPolicy, class RandomAccessIterator, class Compare>
704
+ void nth_element(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
705
+ RandomAccessIterator first, RandomAccessIterator nth,
706
+ RandomAccessIterator last, Compare comp);
707
 
708
+ // [alg.binary.search], binary search
709
  template<class ForwardIterator, class T>
710
  ForwardIterator lower_bound(ForwardIterator first, ForwardIterator last,
711
  const T& value);
712
  template<class ForwardIterator, class T, class Compare>
713
  ForwardIterator lower_bound(ForwardIterator first, ForwardIterator last,
 
734
  const T& value);
735
  template<class ForwardIterator, class T, class Compare>
736
  bool binary_search(ForwardIterator first, ForwardIterator last,
737
  const T& value, Compare comp);
738
 
739
+ // [alg.merge], merge
740
  template<class InputIterator1, class InputIterator2, class OutputIterator>
741
  OutputIterator merge(InputIterator1 first1, InputIterator1 last1,
742
  InputIterator2 first2, InputIterator2 last2,
743
  OutputIterator result);
744
  template<class InputIterator1, class InputIterator2, class OutputIterator,
745
  class Compare>
746
  OutputIterator merge(InputIterator1 first1, InputIterator1 last1,
747
  InputIterator2 first2, InputIterator2 last2,
748
  OutputIterator result, Compare comp);
749
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
750
+ class ForwardIterator>
751
+ ForwardIterator merge(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
752
+ ForwardIterator1 first1, ForwardIterator1 last1,
753
+ ForwardIterator2 first2, ForwardIterator2 last2,
754
+ ForwardIterator result);
755
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
756
+ class ForwardIterator, class Compare>
757
+ ForwardIterator merge(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
758
+ ForwardIterator1 first1, ForwardIterator1 last1,
759
+ ForwardIterator2 first2, ForwardIterator2 last2,
760
+ ForwardIterator result, Compare comp);
761
 
762
  template<class BidirectionalIterator>
763
  void inplace_merge(BidirectionalIterator first,
764
  BidirectionalIterator middle,
765
  BidirectionalIterator last);
766
  template<class BidirectionalIterator, class Compare>
767
  void inplace_merge(BidirectionalIterator first,
768
  BidirectionalIterator middle,
769
  BidirectionalIterator last, Compare comp);
770
+ template<class ExecutionPolicy, class BidirectionalIterator>
771
+ void inplace_merge(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
772
+ BidirectionalIterator first,
773
+ BidirectionalIterator middle,
774
+ BidirectionalIterator last);
775
+ template<class ExecutionPolicy, class BidirectionalIterator, class Compare>
776
+ void inplace_merge(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
777
+ BidirectionalIterator first,
778
+ BidirectionalIterator middle,
779
+ BidirectionalIterator last, Compare comp);
780
 
781
+ // [alg.set.operations], set operations
782
  template<class InputIterator1, class InputIterator2>
783
  bool includes(InputIterator1 first1, InputIterator1 last1,
784
  InputIterator2 first2, InputIterator2 last2);
785
  template<class InputIterator1, class InputIterator2, class Compare>
786
+ bool includes(InputIterator1 first1, InputIterator1 last1,
 
787
  InputIterator2 first2, InputIterator2 last2, Compare comp);
788
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
789
+ bool includes(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
790
+ ForwardIterator1 first1, ForwardIterator1 last1,
791
+ ForwardIterator2 first2, ForwardIterator2 last2);
792
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
793
+ class Compare>
794
+ bool includes(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
795
+ ForwardIterator1 first1, ForwardIterator1 last1,
796
+ ForwardIterator2 first2, ForwardIterator2 last2, Compare comp);
797
 
798
  template<class InputIterator1, class InputIterator2, class OutputIterator>
799
  OutputIterator set_union(InputIterator1 first1, InputIterator1 last1,
800
  InputIterator2 first2, InputIterator2 last2,
801
  OutputIterator result);
802
+ template<class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
 
803
  OutputIterator set_union(InputIterator1 first1, InputIterator1 last1,
804
  InputIterator2 first2, InputIterator2 last2,
805
  OutputIterator result, Compare comp);
806
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
807
+ class ForwardIterator>
808
+ ForwardIterator set_union(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
809
+ ForwardIterator1 first1, ForwardIterator1 last1,
810
+ ForwardIterator2 first2, ForwardIterator2 last2,
811
+ ForwardIterator result);
812
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
813
+ class ForwardIterator, class Compare>
814
+ ForwardIterator set_union(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
815
+ ForwardIterator1 first1, ForwardIterator1 last1,
816
+ ForwardIterator2 first2, ForwardIterator2 last2,
817
+ ForwardIterator result, Compare comp);
818
 
819
  template<class InputIterator1, class InputIterator2, class OutputIterator>
820
  OutputIterator set_intersection(
821
  InputIterator1 first1, InputIterator1 last1,
822
  InputIterator2 first2, InputIterator2 last2,
823
  OutputIterator result);
824
+ template<class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
 
825
  OutputIterator set_intersection(
826
  InputIterator1 first1, InputIterator1 last1,
827
  InputIterator2 first2, InputIterator2 last2,
828
  OutputIterator result, Compare comp);
829
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
830
+ class ForwardIterator>
831
+ ForwardIterator set_intersection(
832
+ ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
833
+ ForwardIterator1 first1, ForwardIterator1 last1,
834
+ ForwardIterator2 first2, ForwardIterator2 last2,
835
+ ForwardIterator result);
836
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
837
+ class ForwardIterator, class Compare>
838
+ ForwardIterator set_intersection(
839
+ ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
840
+ ForwardIterator1 first1, ForwardIterator1 last1,
841
+ ForwardIterator2 first2, ForwardIterator2 last2,
842
+ ForwardIterator result, Compare comp);
843
 
844
  template<class InputIterator1, class InputIterator2, class OutputIterator>
845
  OutputIterator set_difference(
846
  InputIterator1 first1, InputIterator1 last1,
847
  InputIterator2 first2, InputIterator2 last2,
848
  OutputIterator result);
849
+ template<class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
 
850
  OutputIterator set_difference(
851
  InputIterator1 first1, InputIterator1 last1,
852
  InputIterator2 first2, InputIterator2 last2,
853
  OutputIterator result, Compare comp);
854
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
855
+ class ForwardIterator>
856
+ ForwardIterator set_difference(
857
+ ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
858
+ ForwardIterator1 first1, ForwardIterator1 last1,
859
+ ForwardIterator2 first2, ForwardIterator2 last2,
860
+ ForwardIterator result);
861
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
862
+ class ForwardIterator, class Compare>
863
+ ForwardIterator set_difference(
864
+ ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
865
+ ForwardIterator1 first1, ForwardIterator1 last1,
866
+ ForwardIterator2 first2, ForwardIterator2 last2,
867
+ ForwardIterator result, Compare comp);
868
 
869
  template<class InputIterator1, class InputIterator2, class OutputIterator>
870
  OutputIterator set_symmetric_difference(
871
  InputIterator1 first1, InputIterator1 last1,
872
  InputIterator2 first2, InputIterator2 last2,
873
  OutputIterator result);
874
+ template<class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
 
875
  OutputIterator set_symmetric_difference(
876
  InputIterator1 first1, InputIterator1 last1,
877
  InputIterator2 first2, InputIterator2 last2,
878
  OutputIterator result, Compare comp);
879
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
880
+ class ForwardIterator>
881
+ ForwardIterator set_symmetric_difference(
882
+ ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
883
+ ForwardIterator1 first1, ForwardIterator1 last1,
884
+ ForwardIterator2 first2, ForwardIterator2 last2,
885
+ ForwardIterator result);
886
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
887
+ class ForwardIterator, class Compare>
888
+ ForwardIterator set_symmetric_difference(
889
+ ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
890
+ ForwardIterator1 first1, ForwardIterator1 last1,
891
+ ForwardIterator2 first2, ForwardIterator2 last2,
892
+ ForwardIterator result, Compare comp);
893
 
894
+ // [alg.heap.operations], heap operations
895
  template<class RandomAccessIterator>
896
  void push_heap(RandomAccessIterator first, RandomAccessIterator last);
897
  template<class RandomAccessIterator, class Compare>
898
  void push_heap(RandomAccessIterator first, RandomAccessIterator last,
899
  Compare comp);
 
918
 
919
  template<class RandomAccessIterator>
920
  bool is_heap(RandomAccessIterator first, RandomAccessIterator last);
921
  template<class RandomAccessIterator, class Compare>
922
  bool is_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
923
+ template<class ExecutionPolicy, class RandomAccessIterator>
924
+ bool is_heap(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
925
+ RandomAccessIterator first, RandomAccessIterator last);
926
+ template<class ExecutionPolicy, class RandomAccessIterator, class Compare>
927
+ bool is_heap(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
928
+ RandomAccessIterator first, RandomAccessIterator last, Compare comp);
929
  template<class RandomAccessIterator>
930
  RandomAccessIterator is_heap_until(RandomAccessIterator first, RandomAccessIterator last);
931
  template<class RandomAccessIterator, class Compare>
932
  RandomAccessIterator is_heap_until(RandomAccessIterator first, RandomAccessIterator last,
933
  Compare comp);
934
+ template<class ExecutionPolicy, class RandomAccessIterator>
935
+ RandomAccessIterator is_heap_until(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
936
+ RandomAccessIterator first, RandomAccessIterator last);
937
+ template<class ExecutionPolicy, class RandomAccessIterator, class Compare>
938
+ RandomAccessIterator is_heap_until(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
939
+ RandomAccessIterator first, RandomAccessIterator last,
940
+ Compare comp);
941
 
942
+ // [alg.min.max], minimum and maximum
943
  template<class T> constexpr const T& min(const T& a, const T& b);
944
  template<class T, class Compare>
945
  constexpr const T& min(const T& a, const T& b, Compare comp);
946
  template<class T>
947
  constexpr T min(initializer_list<T> t);
 
963
  constexpr pair<T, T> minmax(initializer_list<T> t);
964
  template<class T, class Compare>
965
  constexpr pair<T, T> minmax(initializer_list<T> t, Compare comp);
966
 
967
  template<class ForwardIterator>
968
+ constexpr ForwardIterator min_element(ForwardIterator first, ForwardIterator last);
969
  template<class ForwardIterator, class Compare>
970
+ constexpr ForwardIterator min_element(ForwardIterator first, ForwardIterator last,
971
+ Compare comp);
972
+ template<class ExecutionPolicy, class ForwardIterator>
973
+ ForwardIterator min_element(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
974
+ ForwardIterator first, ForwardIterator last);
975
+ template<class ExecutionPolicy, class ForwardIterator, class Compare>
976
+ ForwardIterator min_element(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
977
+ ForwardIterator first, ForwardIterator last,
978
  Compare comp);
979
  template<class ForwardIterator>
980
+ constexpr ForwardIterator max_element(ForwardIterator first, ForwardIterator last);
981
  template<class ForwardIterator, class Compare>
982
+ constexpr ForwardIterator max_element(ForwardIterator first, ForwardIterator last,
983
+ Compare comp);
984
+ template<class ExecutionPolicy, class ForwardIterator>
985
+ ForwardIterator max_element(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
986
+ ForwardIterator first, ForwardIterator last);
987
+ template<class ExecutionPolicy, class ForwardIterator, class Compare>
988
+ ForwardIterator max_element(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
989
+ ForwardIterator first, ForwardIterator last,
990
  Compare comp);
991
  template<class ForwardIterator>
992
+ constexpr pair<ForwardIterator, ForwardIterator>
993
  minmax_element(ForwardIterator first, ForwardIterator last);
994
  template<class ForwardIterator, class Compare>
995
+ constexpr pair<ForwardIterator, ForwardIterator>
996
  minmax_element(ForwardIterator first, ForwardIterator last, Compare comp);
997
+ template<class ExecutionPolicy, class ForwardIterator>
998
+ pair<ForwardIterator, ForwardIterator>
999
+ minmax_element(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
1000
+ ForwardIterator first, ForwardIterator last);
1001
+ template<class ExecutionPolicy, class ForwardIterator, class Compare>
1002
+ pair<ForwardIterator, ForwardIterator>
1003
+ minmax_element(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
1004
+ ForwardIterator first, ForwardIterator last, Compare comp);
1005
 
1006
+ // [alg.clamp], bounded value
1007
+ template<class T>
1008
+ constexpr const T& clamp(const T& v, const T& lo, const T& hi);
1009
+ template<class T, class Compare>
1010
+ constexpr const T& clamp(const T& v, const T& lo, const T& hi, Compare comp);
1011
+
1012
+ // [alg.lex.comparison], lexicographical comparison
1013
  template<class InputIterator1, class InputIterator2>
1014
  bool lexicographical_compare(
1015
  InputIterator1 first1, InputIterator1 last1,
1016
  InputIterator2 first2, InputIterator2 last2);
1017
  template<class InputIterator1, class InputIterator2, class Compare>
1018
  bool lexicographical_compare(
1019
  InputIterator1 first1, InputIterator1 last1,
1020
  InputIterator2 first2, InputIterator2 last2,
1021
  Compare comp);
1022
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
1023
+ bool lexicographical_compare(
1024
+ ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
1025
+ ForwardIterator1 first1, ForwardIterator1 last1,
1026
+ ForwardIterator2 first2, ForwardIterator2 last2);
1027
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
1028
+ class Compare>
1029
+ bool lexicographical_compare(
1030
+ ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
1031
+ ForwardIterator1 first1, ForwardIterator1 last1,
1032
+ ForwardIterator2 first2, ForwardIterator2 last2,
1033
+ Compare comp);
1034
 
1035
+ // [alg.permutation.generators], permutations
1036
  template<class BidirectionalIterator>
1037
  bool next_permutation(BidirectionalIterator first,
1038
  BidirectionalIterator last);
1039
  template<class BidirectionalIterator, class Compare>
1040
  bool next_permutation(BidirectionalIterator first,
 
1046
  bool prev_permutation(BidirectionalIterator first,
1047
  BidirectionalIterator last, Compare comp);
1048
  }
1049
  ```
1050
 
1051
+ ## Algorithms requirements <a id="algorithms.requirements">[[algorithms.requirements]]</a>
1052
+
1053
  All of the algorithms are separated from the particular implementations
1054
  of data structures and are parameterized by iterator types. Because of
1055
  this, they can work with program-defined data structures, as long as
1056
  these data structures have iterator types satisfying the assumptions on
1057
  the algorithms.
 
1081
  - If an algorithm’s template parameter is named `RandomAccessIterator`,
1082
  `RandomAccessIterator1`, or `RandomAccessIterator2`, the template
1083
  argument shall satisfy the requirements of a random-access iterator (
1084
  [[random.access.iterators]]).
1085
 
1086
+ If an algorithm’s *Effects:* section says that a value pointed to by any
1087
+ iterator passed as an argument is modified, then that algorithm has an
1088
+ additional type requirement: The type of that argument shall satisfy the
1089
+ requirements of a mutable iterator ([[iterator.requirements]]).
1090
+
1091
+ [*Note 1*: This requirement does not affect arguments that are named
1092
+ `OutputIterator`, `OutputIterator1`, or `OutputIterator2`, because
1093
+ output iterators must always be mutable. — *end note*]
1094
 
1095
  Both in-place and copying versions are provided for certain
1096
  algorithms.[^1] When such a version is provided for *algorithm* it is
1097
  called *algorithm`_copy`*. Algorithms that take predicates end with the
1098
  suffix `_if` (which follows the suffix `_copy`).
 
1118
  that is, in those cases when `T value` is part of the signature, it
1119
  should work correctly in the construct `binary_pred(*first1, value)`
1120
  contextually converted to `bool` (Clause  [[conv]]). `binary_pred` shall
1121
  not apply any non-constant function through the dereferenced iterators.
1122
 
1123
+ [*Note 2*: Unless otherwise specified, algorithms that take function
1124
+ objects as arguments are permitted to copy those function objects
1125
+ freely. Programmers for whom object identity is important should
1126
+ consider using a wrapper class that points to a noncopied implementation
1127
+ object such as `reference_wrapper<T>` ([[refwrap]]), or some equivalent
1128
+ solution. — *end note*]
1129
 
1130
  When the description of an algorithm gives an expression such as
1131
  `*first == value` for a condition, the expression shall evaluate to
1132
+ either `true` or `false` in boolean contexts.
1133
 
1134
  In the description of the algorithms operators `+` and `-` are used for
1135
  some of the iterator categories for which they do not have to be
1136
  defined. In these cases the semantics of `a+n` is the same as that of
1137
 
 
1145
 
1146
  ``` cpp
1147
  return distance(a, b);
1148
  ```
1149
 
1150
+ ## Parallel algorithms <a id="algorithms.parallel">[[algorithms.parallel]]</a>
1151
+
1152
+ This section describes components that C++programs may use to perform
1153
+ operations on containers and other sequences in parallel.
1154
+
1155
+ ### Terms and definitions <a id="algorithms.parallel.defns">[[algorithms.parallel.defns]]</a>
1156
+
1157
+ A *parallel algorithm* is a function template listed in this
1158
+ International Standard with a template parameter named
1159
+ `ExecutionPolicy`.
1160
+
1161
+ Parallel algorithms access objects indirectly accessible via their
1162
+ arguments by invoking the following functions:
1163
+
1164
+ - All operations of the categories of the iterators that the algorithm
1165
+ is instantiated with.
1166
+ - Operations on those sequence elements that are required by its
1167
+ specification.
1168
+ - User-provided function objects to be applied during the execution of
1169
+ the algorithm, if required by the specification.
1170
+ - Operations on those function objects required by the specification.
1171
+ \[*Note 1*: See  [[algorithms.general]]. — *end note*]
1172
+
1173
+ These functions are herein called *element access functions*.
1174
+
1175
+ [*Example 1*:
1176
+
1177
+ The `sort` function may invoke the following element access functions:
1178
+
1179
+ - Operations of the random-access iterator of the actual template
1180
+ argument (as per [[random.access.iterators]]), as implied by the name
1181
+ of the template parameter `RandomAccessIterator`.
1182
+ - The `swap` function on the elements of the sequence (as per the
1183
+ preconditions specified in [[sort]]).
1184
+ - The user-provided `Compare` function object.
1185
+
1186
+ — *end example*]
1187
+
1188
+ ### Requirements on user-provided function objects <a id="algorithms.parallel.user">[[algorithms.parallel.user]]</a>
1189
+
1190
+ Unless otherwise specified, function objects passed into parallel
1191
+ algorithms as objects of type `Predicate`, `BinaryPredicate`, `Compare`,
1192
+ `UnaryOperation`, `BinaryOperation`, `BinaryOperation1`,
1193
+ `BinaryOperation2`, and the operators used by the analogous overloads to
1194
+ these parallel algorithms that could be formed by the invocation with
1195
+ the specified default predicate or operation (where applicable) shall
1196
+ not directly or indirectly modify objects via their arguments, nor shall
1197
+ they rely on the identity of the provided objects..
1198
+
1199
+ ### Effect of execution policies on algorithm execution <a id="algorithms.parallel.exec">[[algorithms.parallel.exec]]</a>
1200
+
1201
+ Parallel algorithms have template parameters named `ExecutionPolicy` (
1202
+ [[execpol]]) which describe the manner in which the execution of these
1203
+ algorithms may be parallelized and the manner in which they apply the
1204
+ element access functions.
1205
+
1206
+ Unless otherwise stated, implementations may make arbitrary copies of
1207
+ elements (with type `T`) from sequences where
1208
+ `is_trivially_copy_constructible_v<T>` and
1209
+ `is_trivially_destructible_v<T>` are `true`.
1210
+
1211
+ [*Note 1*: This implies that user-supplied function objects should not
1212
+ rely on object identity of arguments for such input sequences. Users for
1213
+ whom the object identity of the arguments to these function objects is
1214
+ important should consider using a wrapping iterator that returns a
1215
+ non-copied implementation object such as `reference_wrapper<T>` (
1216
+ [[refwrap]]) or some equivalent solution. — *end note*]
1217
+
1218
+ The invocations of element access functions in parallel algorithms
1219
+ invoked with an execution policy object of type
1220
+ `execution::sequenced_policy` all occur in the calling thread of
1221
+ execution.
1222
+
1223
+ [*Note 2*: The invocations are not interleaved; see 
1224
+ [[intro.execution]]. — *end note*]
1225
+
1226
+ The invocations of element access functions in parallel algorithms
1227
+ invoked with an execution policy object of type
1228
+ `execution::parallel_policy` are permitted to execute in either the
1229
+ invoking thread of execution or in a thread of execution implicitly
1230
+ created by the library to support parallel algorithm execution. If the
1231
+ threads of execution created by `thread` ([[thread.thread.class]])
1232
+ provide concurrent forward progress guarantees ([[intro.progress]]),
1233
+ then a thread of execution implicitly created by the library will
1234
+ provide parallel forward progress guarantees; otherwise, the provided
1235
+ forward progress guarantee is *implementation-defined*. Any such
1236
+ invocations executing in the same thread of execution are
1237
+ indeterminately sequenced with respect to each other.
1238
+
1239
+ [*Note 3*: It is the caller’s responsibility to ensure that the
1240
+ invocation does not introduce data races or deadlocks. — *end note*]
1241
+
1242
+ [*Example 1*:
1243
+
1244
+ ``` cpp
1245
+ int a[] = {0,1};
1246
+ std::vector<int> v;
1247
+ std::for_each(std::execution::par, std::begin(a), std::end(a), [&](int i) {
1248
+ v.push_back(i*2+1); // incorrect: data race
1249
+ });
1250
+ ```
1251
+
1252
+ The program above has a data race because of the unsynchronized access
1253
+ to the container `v`.
1254
+
1255
+ — *end example*]
1256
+
1257
+ [*Example 2*:
1258
+
1259
+ ``` cpp
1260
+ std::atomic<int> x{0};
1261
+ int a[] = {1,2};
1262
+ std::for_each(std::execution::par, std::begin(a), std::end(a), [&](int) {
1263
+ x.fetch_add(1, std::memory_order_relaxed);
1264
+ // spin wait for another iteration to change the value of x
1265
+ while (x.load(std::memory_order_relaxed) == 1) { } // incorrect: assumes execution order
1266
+ });
1267
+ ```
1268
+
1269
+ The above example depends on the order of execution of the iterations,
1270
+ and will not terminate if both iterations are executed sequentially on
1271
+ the same thread of execution.
1272
+
1273
+ — *end example*]
1274
+
1275
+ [*Example 3*:
1276
+
1277
+ ``` cpp
1278
+ int x = 0;
1279
+ std::mutex m;
1280
+ int a[] = {1,2};
1281
+ std::for_each(std::execution::par, std::begin(a), std::end(a), [&](int) {
1282
+ std::lock_guard<mutex> guard(m);
1283
+ ++x;
1284
+ });
1285
+ ```
1286
+
1287
+ The above example synchronizes access to object `x` ensuring that it is
1288
+ incremented correctly.
1289
+
1290
+ — *end example*]
1291
+
1292
+ The invocations of element access functions in parallel algorithms
1293
+ invoked with an execution policy of type
1294
+ `execution::parallel_unsequenced_policy` are permitted to execute in an
1295
+ unordered fashion in unspecified threads of execution, and unsequenced
1296
+ with respect to one another within each thread of execution. These
1297
+ threads of execution are either the invoking thread of execution or
1298
+ threads of execution implicitly created by the library; the latter will
1299
+ provide weakly parallel forward progress guarantees.
1300
+
1301
+ [*Note 4*: This means that multiple function object invocations may be
1302
+ interleaved on a single thread of execution, which overrides the usual
1303
+ guarantee from [[intro.execution]] that function executions do not
1304
+ interleave with one another. — *end note*]
1305
+
1306
+ Since `execution::parallel_unsequenced_policy` allows the execution of
1307
+ element access functions to be interleaved on a single thread of
1308
+ execution, blocking synchronization, including the use of mutexes, risks
1309
+ deadlock. Thus, the synchronization with
1310
+ `execution::parallel_unsequenced_policy` is restricted as follows: A
1311
+ standard library function is *vectorization-unsafe* if it is specified
1312
+ to synchronize with another function invocation, or another function
1313
+ invocation is specified to synchronize with it, and if it is not a
1314
+ memory allocation or deallocation function. Vectorization-unsafe
1315
+ standard library functions may not be invoked by user code called from
1316
+ `execution::parallel_unsequenced_policy` algorithms.
1317
+
1318
+ [*Note 5*: Implementations must ensure that internal synchronization
1319
+ inside standard library functions does not prevent forward progress when
1320
+ those functions are executed by threads of execution with weakly
1321
+ parallel forward progress guarantees. — *end note*]
1322
+
1323
+ [*Example 4*:
1324
+
1325
+ ``` cpp
1326
+ int x = 0;
1327
+ std::mutex m;
1328
+ int a[] = {1,2};
1329
+ std::for_each(std::execution::par_unseq, std::begin(a), std::end(a), [&](int) {
1330
+ std::lock_guard<mutex> guard(m); // incorrect: lock_guard constructor calls m.lock()
1331
+ ++x;
1332
+ });
1333
+ ```
1334
+
1335
+ The above program may result in two consecutive calls to `m.lock()` on
1336
+ the same thread of execution (which may deadlock), because the
1337
+ applications of the function object are not guaranteed to run on
1338
+ different threads of execution.
1339
+
1340
+ — *end example*]
1341
+
1342
+ [*Note 6*: The semantics of the `execution::parallel_policy` or the
1343
+ `execution::parallel_unsequenced_policy` invocation allow the
1344
+ implementation to fall back to sequential execution if the system cannot
1345
+ parallelize an algorithm invocation due to lack of
1346
+ resources. — *end note*]
1347
+
1348
+ If an invocation of a parallel algorithm uses threads of execution
1349
+ implicitly created by the library, then the invoking thread of execution
1350
+ will either
1351
+
1352
+ - temporarily block with forward progress guarantee delegation (
1353
+ [[intro.progress]]) on the completion of these library-managed threads
1354
+ of execution, or
1355
+ - eventually execute an element access function;
1356
+
1357
+ the thread of execution will continue to do so until the algorithm is
1358
+ finished.
1359
+
1360
+ [*Note 7*: In blocking with forward progress guarantee delegation in
1361
+ this context, a thread of execution created by the library is considered
1362
+ to have finished execution as soon as it has finished the execution of
1363
+ the particular element access function that the invoking thread of
1364
+ execution logically depends on. — *end note*]
1365
+
1366
+ The semantics of parallel algorithms invoked with an execution policy
1367
+ object of *implementation-defined* type are *implementation-defined*.
1368
+
1369
+ ### Parallel algorithm exceptions <a id="algorithms.parallel.exceptions">[[algorithms.parallel.exceptions]]</a>
1370
+
1371
+ During the execution of a parallel algorithm, if temporary memory
1372
+ resources are required for parallelization and none are available, the
1373
+ algorithm throws a `bad_alloc` exception.
1374
+
1375
+ During the execution of a parallel algorithm, if the invocation of an
1376
+ element access function exits via an uncaught exception, the behavior is
1377
+ determined by the `ExecutionPolicy`.
1378
+
1379
+ ### `ExecutionPolicy` algorithm overloads <a id="algorithms.parallel.overloads">[[algorithms.parallel.overloads]]</a>
1380
+
1381
+ Parallel algorithms are algorithm overloads. Each parallel algorithm
1382
+ overload has an additional template type parameter named
1383
+ `ExecutionPolicy`, which is the first template parameter. Additionally,
1384
+ each parallel algorithm overload has an additional function parameter of
1385
+ type `ExecutionPolicy&&`, which is the first function parameter.
1386
+
1387
+ [*Note 1*: Not all algorithms have parallel algorithm
1388
+ overloads. — *end note*]
1389
+
1390
+ Unless otherwise specified, the semantics of `ExecutionPolicy` algorithm
1391
+ overloads are identical to their overloads without.
1392
+
1393
+ Unless otherwise specified, the complexity requirements of
1394
+ `ExecutionPolicy` algorithm overloads are relaxed from the complexity
1395
+ requirements of the overloads without as follows: when the guarantee
1396
+ says “at most *expr*” or “exactly *expr*” and does not specify the
1397
+ number of assignments or swaps, and *expr* is not already expressed with
1398
+ 𝑂() notation, the complexity of the algorithm shall be
1399
+ 𝑂(\placeholder{expr}).
1400
+
1401
+ Parallel algorithms shall not participate in overload resolution unless
1402
+ `is_execution_policy_v<decay_t<ExecutionPolicy>>` is `true`.
1403
+
1404
  ## Non-modifying sequence operations <a id="alg.nonmodifying">[[alg.nonmodifying]]</a>
1405
 
1406
  ### All of <a id="alg.all_of">[[alg.all_of]]</a>
1407
 
1408
  ``` cpp
1409
  template <class InputIterator, class Predicate>
1410
  bool all_of(InputIterator first, InputIterator last, Predicate pred);
1411
+ template <class ExecutionPolicy, class ForwardIterator, class Predicate>
1412
+ bool all_of(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last,
1413
+ Predicate pred);
1414
  ```
1415
 
1416
  *Returns:* `true` if \[`first`, `last`) is empty or if `pred(*i)` is
1417
  `true` for every iterator `i` in the range \[`first`, `last`), and
1418
  `false` otherwise.
 
1422
  ### Any of <a id="alg.any_of">[[alg.any_of]]</a>
1423
 
1424
  ``` cpp
1425
  template <class InputIterator, class Predicate>
1426
  bool any_of(InputIterator first, InputIterator last, Predicate pred);
1427
+ template <class ExecutionPolicy, class ForwardIterator, class Predicate>
1428
+ bool any_of(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last,
1429
+ Predicate pred);
1430
  ```
1431
 
1432
  *Returns:* `false` if \[`first`, `last`) is empty or if there is no
1433
  iterator `i` in the range \[`first`, `last`) such that `pred(*i)` is
1434
  `true`, and `true` otherwise.
 
1438
  ### None of <a id="alg.none_of">[[alg.none_of]]</a>
1439
 
1440
  ``` cpp
1441
  template <class InputIterator, class Predicate>
1442
  bool none_of(InputIterator first, InputIterator last, Predicate pred);
1443
+ template <class ExecutionPolicy, class ForwardIterator, class Predicate>
1444
+ bool none_of(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last,
1445
+ Predicate pred);
1446
  ```
1447
 
1448
  *Returns:* `true` if \[`first`, `last`) is empty or if `pred(*i)` is
1449
  `false` for every iterator `i` in the range \[`first`, `last`), and
1450
  `false` otherwise.
 
1457
  template<class InputIterator, class Function>
1458
  Function for_each(InputIterator first, InputIterator last, Function f);
1459
  ```
1460
 
1461
  *Requires:* `Function` shall meet the requirements of
1462
+ `MoveConstructible` (Table  [[tab:moveconstructible]]).
1463
+
1464
+ [*Note 1*: `Function` need not meet the requirements of
1465
+ `CopyConstructible` (Table  [[tab:copyconstructible]]). — *end note*]
1466
 
1467
  *Effects:* Applies `f` to the result of dereferencing every iterator in
1468
  the range \[`first`, `last`), starting from `first` and proceeding to
1469
+ `last - 1`.
 
 
1470
 
1471
+ [*Note 2*: If the type of `first` satisfies the requirements of a
1472
+ mutable iterator, `f` may apply non-constant functions through the
1473
+ dereferenced iterator. — *end note*]
1474
+
1475
+ *Returns:* `f`.
1476
+
1477
+ *Complexity:* Applies `f` exactly `last - first` times.
1478
+
1479
+ *Remarks:* If `f` returns a result, the result is ignored.
1480
+
1481
+ ``` cpp
1482
+ template<class ExecutionPolicy, class ForwardIterator, class Function>
1483
+ void for_each(ExecutionPolicy&& exec,
1484
+ ForwardIterator first, ForwardIterator last,
1485
+ Function f);
1486
+ ```
1487
+
1488
+ *Requires:* `Function` shall meet the requirements of
1489
+ `CopyConstructible`.
1490
+
1491
+ *Effects:* Applies `f` to the result of dereferencing every iterator in
1492
+ the range \[`first`, `last`).
1493
+
1494
+ [*Note 3*: If the type of `first` satisfies the requirements of a
1495
+ mutable iterator, `f` may apply non-constant functions through the
1496
+ dereferenced iterator. — *end note*]
1497
 
1498
  *Complexity:* Applies `f` exactly `last - first` times.
1499
 
1500
  *Remarks:* If `f` returns a result, the result is ignored.
1501
+ Implementations do not have the freedom granted under
1502
+ [[algorithms.parallel.exec]] to make arbitrary copies of elements from
1503
+ the input sequence.
1504
+
1505
+ [*Note 4*: Does not return a copy of its `Function` parameter, since
1506
+ parallelization may not permit efficient state
1507
+ accumulation. — *end note*]
1508
+
1509
+ ``` cpp
1510
+ template<class InputIterator, class Size, class Function>
1511
+ InputIterator for_each_n(InputIterator first, Size n, Function f);
1512
+ ```
1513
+
1514
+ *Requires:* `Function` shall meet the requirements of
1515
+ `MoveConstructible`
1516
+
1517
+ [*Note 5*: `Function` need not meet the requirements of
1518
+ `CopyConstructible`. — *end note*]
1519
+
1520
+ *Requires:* `n >= 0`.
1521
+
1522
+ *Effects:* Applies `f` to the result of dereferencing every iterator in
1523
+ the range \[`first`, `first + n`) in order.
1524
+
1525
+ [*Note 6*: If the type of `first` satisfies the requirements of a
1526
+ mutable iterator, `f` may apply non-constant functions through the
1527
+ dereferenced iterator. — *end note*]
1528
+
1529
+ *Returns:* `first + n`.
1530
+
1531
+ *Remarks:* If `f` returns a result, the result is ignored.
1532
+
1533
+ ``` cpp
1534
+ template<class ExecutionPolicy, class ForwardIterator, class Size, class Function>
1535
+ ForwardIterator for_each_n(ExecutionPolicy&& exec, ForwardIterator first, Size n,
1536
+ Function f);
1537
+ ```
1538
+
1539
+ *Requires:* `Function` shall meet the requirements of
1540
+ `CopyConstructible`.
1541
+
1542
+ *Requires:* `n >= 0`.
1543
+
1544
+ *Effects:* Applies `f` to the result of dereferencing every iterator in
1545
+ the range \[`first`, `first + n`).
1546
+
1547
+ [*Note 7*: If the type of `first` satisfies the requirements of a
1548
+ mutable iterator, `f` may apply non-constant functions through the
1549
+ dereferenced iterator. — *end note*]
1550
+
1551
+ *Returns:* `first + n`.
1552
+
1553
+ *Remarks:* If `f` returns a result, the result is ignored.
1554
+ Implementations do not have the freedom granted under
1555
+ [[algorithms.parallel.exec]] to make arbitrary copies of elements from
1556
+ the input sequence.
1557
 
1558
  ### Find <a id="alg.find">[[alg.find]]</a>
1559
 
1560
  ``` cpp
1561
  template<class InputIterator, class T>
1562
  InputIterator find(InputIterator first, InputIterator last,
1563
  const T& value);
1564
+ template<class ExecutionPolicy, class ForwardIterator, class T>
1565
+ ForwardIterator find(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last,
1566
+ const T& value);
1567
 
1568
  template<class InputIterator, class Predicate>
1569
  InputIterator find_if(InputIterator first, InputIterator last,
1570
  Predicate pred);
1571
+ template<class ExecutionPolicy, class ForwardIterator, class Predicate>
1572
+ ForwardIterator find_if(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last,
1573
+ Predicate pred);
1574
+
1575
  template<class InputIterator, class Predicate>
1576
  InputIterator find_if_not(InputIterator first, InputIterator last,
1577
  Predicate pred);
1578
+ template<class ExecutionPolicy, class ForwardIterator, class Predicate>
1579
+ ForwardIterator find_if_not(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last,
1580
+ Predicate pred);
1581
  ```
1582
 
1583
  *Returns:* The first iterator `i` in the range \[`first`, `last`) for
1584
  which the following corresponding conditions hold: `*i == value`,
1585
  `pred(*i) != false`, `pred(*i) == false`. Returns `last` if no such
 
1593
  ``` cpp
1594
  template<class ForwardIterator1, class ForwardIterator2>
1595
  ForwardIterator1
1596
  find_end(ForwardIterator1 first1, ForwardIterator1 last1,
1597
  ForwardIterator2 first2, ForwardIterator2 last2);
1598
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
1599
+ ForwardIterator1
1600
+ find_end(ExecutionPolicy&& exec,
1601
+ ForwardIterator1 first1, ForwardIterator1 last1,
1602
+ ForwardIterator2 first2, ForwardIterator2 last2);
1603
 
1604
  template<class ForwardIterator1, class ForwardIterator2,
1605
  class BinaryPredicate>
1606
  ForwardIterator1
1607
  find_end(ForwardIterator1 first1, ForwardIterator1 last1,
1608
  ForwardIterator2 first2, ForwardIterator2 last2,
1609
  BinaryPredicate pred);
1610
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
1611
+ class BinaryPredicate>
1612
+ ForwardIterator1
1613
+ find_end(ExecutionPolicy&& exec,
1614
+ ForwardIterator1 first1, ForwardIterator1 last1,
1615
+ ForwardIterator2 first2, ForwardIterator2 last2,
1616
+ BinaryPredicate pred);
1617
  ```
1618
 
1619
  *Effects:* Finds a subsequence of equal values in a sequence.
1620
 
1621
  *Returns:* The last iterator `i` in the range \[`first1`,
 
1634
  ``` cpp
1635
  template<class InputIterator, class ForwardIterator>
1636
  InputIterator
1637
  find_first_of(InputIterator first1, InputIterator last1,
1638
  ForwardIterator first2, ForwardIterator last2);
1639
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
1640
+ ForwardIterator1
1641
+ find_first_of(ExecutionPolicy&& exec,
1642
+ ForwardIterator1 first1, ForwardIterator1 last1,
1643
+ ForwardIterator2 first2, ForwardIterator2 last2);
1644
 
1645
  template<class InputIterator, class ForwardIterator,
1646
  class BinaryPredicate>
1647
  InputIterator
1648
  find_first_of(InputIterator first1, InputIterator last1,
1649
  ForwardIterator first2, ForwardIterator last2,
1650
  BinaryPredicate pred);
1651
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
1652
+ class BinaryPredicate>
1653
+ ForwardIterator1
1654
+ find_first_of(ExecutionPolicy&& exec,
1655
+ ForwardIterator1 first1, ForwardIterator1 last1,
1656
+ ForwardIterator2 first2, ForwardIterator2 last2,
1657
+ BinaryPredicate pred);
1658
  ```
1659
 
1660
  *Effects:* Finds an element that matches one of a set of values.
1661
 
1662
  *Returns:* The first iterator `i` in the range \[`first1`, `last1`) such
 
1671
  ### Adjacent find <a id="alg.adjacent.find">[[alg.adjacent.find]]</a>
1672
 
1673
  ``` cpp
1674
  template<class ForwardIterator>
1675
  ForwardIterator adjacent_find(ForwardIterator first, ForwardIterator last);
1676
+ template<class ExecutionPolicy, class ForwardIterator>
1677
+ ForwardIterator adjacent_find(ExecutionPolicy&& exec,
1678
+ ForwardIterator first, ForwardIterator last);
1679
 
1680
  template<class ForwardIterator, class BinaryPredicate>
1681
  ForwardIterator adjacent_find(ForwardIterator first, ForwardIterator last,
1682
  BinaryPredicate pred);
1683
+ template<class ExecutionPolicy, class ForwardIterator, class BinaryPredicate>
1684
+ ForwardIterator adjacent_find(ExecutionPolicy&& exec,
1685
+ ForwardIterator first, ForwardIterator last,
1686
+ BinaryPredicate pred);
1687
  ```
1688
 
1689
  *Returns:* The first iterator `i` such that both `i` and `i + 1` are in
1690
  the range \[`first`, `last`) for which the following corresponding
1691
  conditions hold: `*i == *(i + 1), pred(*i, *(i + 1)) != false`. Returns
1692
  `last` if no such iterator is found.
1693
 
1694
+ *Complexity:* For the overloads with no `ExecutionPolicy`, exactly
1695
  `min((i - first) + 1, (last - first) - 1)` applications of the
1696
  corresponding predicate, where `i` is `adjacent_find`’s return value.
1697
+ For the overloads with an `ExecutionPolicy`, 𝑂(`last - first`)
1698
+ applications of the corresponding predicate.
1699
 
1700
  ### Count <a id="alg.count">[[alg.count]]</a>
1701
 
1702
  ``` cpp
1703
  template<class InputIterator, class T>
1704
  typename iterator_traits<InputIterator>::difference_type
1705
  count(InputIterator first, InputIterator last, const T& value);
1706
+ template<class ExecutionPolicy, class ForwardIterator, class T>
1707
+ typename iterator_traits<ForwardIterator>::difference_type
1708
+ count(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, const T& value);
1709
 
1710
  template<class InputIterator, class Predicate>
1711
  typename iterator_traits<InputIterator>::difference_type
1712
  count_if(InputIterator first, InputIterator last, Predicate pred);
1713
+ template<class ExecutionPolicy, class ForwardIterator, class Predicate>
1714
+ typename iterator_traits<ForwardIterator>::difference_type
1715
+ count_if(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, Predicate pred);
1716
  ```
1717
 
1718
  *Effects:* Returns the number of iterators `i` in the range \[`first`,
1719
  `last`) for which the following corresponding conditions hold:
1720
  `*i == value, pred(*i) != false`.
 
1727
  ``` cpp
1728
  template<class InputIterator1, class InputIterator2>
1729
  pair<InputIterator1, InputIterator2>
1730
  mismatch(InputIterator1 first1, InputIterator1 last1,
1731
  InputIterator2 first2);
1732
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
1733
+ pair<ForwardIterator1, ForwardIterator2>
1734
+ mismatch(ExecutionPolicy&& exec,
1735
+ ForwardIterator1 first1, ForwardIterator1 last1,
1736
+ ForwardIterator2 first2);
1737
 
1738
  template<class InputIterator1, class InputIterator2,
1739
  class BinaryPredicate>
1740
  pair<InputIterator1, InputIterator2>
1741
  mismatch(InputIterator1 first1, InputIterator1 last1,
1742
  InputIterator2 first2, BinaryPredicate pred);
1743
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
1744
+ class BinaryPredicate>
1745
+ pair<ForwardIterator1, ForwardIterator2>
1746
+ mismatch(ExecutionPolicy&& exec,
1747
+ ForwardIterator1 first1, ForwardIterator1 last1,
1748
+ ForwardIterator2 first2, BinaryPredicate pred);
1749
 
1750
  template<class InputIterator1, class InputIterator2>
1751
  pair<InputIterator1, InputIterator2>
1752
  mismatch(InputIterator1 first1, InputIterator1 last1,
1753
  InputIterator2 first2, InputIterator2 last2);
1754
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
1755
+ pair<ForwardIterator1, ForwardIterator2>
1756
+ mismatch(ExecutionPolicy&& exec,
1757
+ ForwardIterator1 first1, ForwardIterator1 last1,
1758
+ ForwardIterator2 first2, ForwardIterator2 last2);
1759
 
1760
  template<class InputIterator1, class InputIterator2,
1761
  class BinaryPredicate>
1762
  pair<InputIterator1, InputIterator2>
1763
  mismatch(InputIterator1 first1, InputIterator1 last1,
1764
  InputIterator2 first2, InputIterator2 last2,
1765
  BinaryPredicate pred);
1766
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
1767
+ class BinaryPredicate>
1768
+ pair<ForwardIterator1, ForwardIterator2>
1769
+ mismatch(ExecutionPolicy&& exec,
1770
+ ForwardIterator1 first1, ForwardIterator1 last1,
1771
+ ForwardIterator2 first2, ForwardIterator2 last2,
1772
+ BinaryPredicate pred);
1773
  ```
1774
 
1775
  *Remarks:* If `last2` was not given in the argument list, it denotes
1776
  `first2 + (last1 - first1)` below.
1777
 
1778
+ *Returns:* A pair of iterators `first1 + n` and `first2 + n`, where `n`
1779
+ is the smallest integer such that, respectively,
 
 
1780
 
1781
+ - `!(*(first1 + n) == *(first2 + n))` or
1782
+ - `pred(*(first1 + n), *(first2 + n)) == false`,
 
1783
 
1784
+ or `min(last1 - first1, last2 - first2)` if no such integer exists.
 
 
1785
 
1786
+ *Complexity:* At most `min(last1 - first1, last2 - first2)` applications
1787
+ of the corresponding predicate.
1788
 
1789
  ### Equal <a id="alg.equal">[[alg.equal]]</a>
1790
 
1791
  ``` cpp
1792
  template<class InputIterator1, class InputIterator2>
1793
  bool equal(InputIterator1 first1, InputIterator1 last1,
1794
  InputIterator2 first2);
1795
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
1796
+ bool equal(ExecutionPolicy&& exec,
1797
+ ForwardIterator1 first1, ForwardIterator1 last1,
1798
+ ForwardIterator2 first2);
1799
 
1800
  template<class InputIterator1, class InputIterator2,
1801
  class BinaryPredicate>
1802
  bool equal(InputIterator1 first1, InputIterator1 last1,
1803
  InputIterator2 first2, BinaryPredicate pred);
1804
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
1805
+ class BinaryPredicate>
1806
+ bool equal(ExecutionPolicy&& exec,
1807
+ ForwardIterator1 first1, ForwardIterator1 last1,
1808
+ ForwardIterator2 first2, BinaryPredicate pred);
1809
 
1810
  template<class InputIterator1, class InputIterator2>
1811
  bool equal(InputIterator1 first1, InputIterator1 last1,
1812
  InputIterator2 first2, InputIterator2 last2);
1813
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
1814
+ bool equal(ExecutionPolicy&& exec,
1815
+ ForwardIterator1 first1, ForwardIterator1 last1,
1816
+ ForwardIterator2 first2, ForwardIterator2 last2);
1817
 
1818
  template<class InputIterator1, class InputIterator2,
1819
  class BinaryPredicate>
1820
  bool equal(InputIterator1 first1, InputIterator1 last1,
1821
  InputIterator2 first2, InputIterator2 last2,
1822
  BinaryPredicate pred);
1823
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
1824
+ class BinaryPredicate>
1825
+ bool equal(ExecutionPolicy&& exec,
1826
+ ForwardIterator1 first1, ForwardIterator1 last1,
1827
+ ForwardIterator2 first2, ForwardIterator2 last2,
1828
+ BinaryPredicate pred);
1829
  ```
1830
 
1831
  *Remarks:* If `last2` was not given in the argument list, it denotes
1832
  `first2 + (last1 - first1)` below.
1833
 
 
1835
  Otherwise return `true` if for every iterator `i` in the range
1836
  \[`first1`, `last1`) the following corresponding conditions hold:
1837
  `*i == *(first2 + (i - first1)), pred(*i, *(first2 + (i - first1))) != false`.
1838
  Otherwise, returns `false`.
1839
 
1840
+ *Complexity:*
1841
+
1842
+ - For the overloads with no `ExecutionPolicy`,
1843
+ - if `InputIterator1` and `InputIterator2` meet the requirements of
1844
+ random access iterators ([[random.access.iterators]]) and
1845
+ `last1 - first1 != last2 - first2`, then no applications of the
1846
+ corresponding predicate; otherwise,
1847
+ - at most min(`last1 - first1`, `last2 - first2`) applications of the
1848
+ corresponding predicate.
1849
+ - For the overloads with no `ExecutionPolicy`,
1850
+ - if `ForwardIterator1` and `ForwardIterator2` meet the requirements
1851
+ of random access iterators and `last1 - first1 != last2 - first2`,
1852
+ then no applications of the corresponding predicate; otherwise,
1853
+ - 𝑂(min(`last1 - first1`, `last2 - first2`)) applications of the
1854
  corresponding predicate.
1855
 
1856
  ### Is permutation <a id="alg.is_permutation">[[alg.is_permutation]]</a>
1857
 
1858
  ``` cpp
 
1888
  otherwise, returns `false`.
1889
 
1890
  *Complexity:* No applications of the corresponding predicate if
1891
  `ForwardIterator1` and `ForwardIterator2` meet the requirements of
1892
  random access iterators and `last1 - first1 != last2 - first2`.
1893
+ Otherwise, exactly `last1 - first1` applications of the corresponding
1894
+ predicate if `equal(first1, last1, first2, last2)` would return `true`
1895
+ if `pred` was not given in the argument list or
1896
  `equal(first1, last1, first2, last2, pred)` would return `true` if pred
1897
  was given in the argument list; otherwise, at worst 𝑂(N^2), where N has
1898
+ the value `last1 - first1`.
1899
 
1900
  ### Search <a id="alg.search">[[alg.search]]</a>
1901
 
1902
  ``` cpp
1903
  template<class ForwardIterator1, class ForwardIterator2>
1904
  ForwardIterator1
1905
  search(ForwardIterator1 first1, ForwardIterator1 last1,
1906
  ForwardIterator2 first2, ForwardIterator2 last2);
1907
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
1908
+ ForwardIterator1
1909
+ search(ExecutionPolicy&& exec,
1910
+ ForwardIterator1 first1, ForwardIterator1 last1,
1911
+ ForwardIterator2 first2, ForwardIterator2 last2);
1912
 
1913
  template<class ForwardIterator1, class ForwardIterator2,
1914
  class BinaryPredicate>
1915
  ForwardIterator1
1916
  search(ForwardIterator1 first1, ForwardIterator1 last1,
1917
  ForwardIterator2 first2, ForwardIterator2 last2,
1918
  BinaryPredicate pred);
1919
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
1920
+ class BinaryPredicate>
1921
+ ForwardIterator1
1922
+ search(ExecutionPolicy&& exec,
1923
+ ForwardIterator1 first1, ForwardIterator1 last1,
1924
+ ForwardIterator2 first2, ForwardIterator2 last2,
1925
+ BinaryPredicate pred);
1926
  ```
1927
 
1928
  *Effects:* Finds a subsequence of equal values in a sequence.
1929
 
1930
  *Returns:* The first iterator `i` in the range \[`first1`,
 
1946
  template<class ForwardIterator, class Size, class T,
1947
  class BinaryPredicate>
1948
  ForwardIterator
1949
  search_n(ForwardIterator first, ForwardIterator last, Size count,
1950
  const T& value, BinaryPredicate pred);
1951
+
1952
+ template<class ExecutionPolicy, class ForwardIterator, class Size, class T>
1953
+ ForwardIterator
1954
+ search_n(ExecutionPolicy&& exec,
1955
+ ForwardIterator first, ForwardIterator last,
1956
+ Size count, const T& value);
1957
+ template<class ExecutionPolicy, class ForwardIterator, class Size, class T,
1958
+ class BinaryPredicate>
1959
+ ForwardIterator
1960
+ search_n(ExecutionPolicy&& exec,
1961
+ ForwardIterator first, ForwardIterator last,
1962
+ Size count, const T& value,
1963
+ BinaryPredicate pred);
1964
  ```
1965
 
1966
  *Requires:* The type `Size` shall be convertible to integral
1967
  type ([[conv.integral]], [[class.conv]]).
1968
 
 
1975
  such iterator is found.
1976
 
1977
  *Complexity:* At most `last - first` applications of the corresponding
1978
  predicate.
1979
 
1980
+ ``` cpp
1981
+ template<class ForwardIterator, class Searcher>
1982
+ ForwardIterator search(ForwardIterator first, ForwardIterator last,
1983
+ const Searcher& searcher);
1984
+ ```
1985
+
1986
+ *Effects:* Equivalent to: `return searcher(first, last).first;`
1987
+
1988
+ *Remarks:* `Searcher` need not meet the `CopyConstructible`
1989
+ requirements.
1990
+
1991
  ## Mutating sequence operations <a id="alg.modifying.operations">[[alg.modifying.operations]]</a>
1992
 
1993
  ### Copy <a id="alg.copy">[[alg.copy]]</a>
1994
 
1995
  ``` cpp
1996
  template<class InputIterator, class OutputIterator>
1997
  OutputIterator copy(InputIterator first, InputIterator last,
1998
  OutputIterator result);
1999
  ```
2000
 
2001
+ *Requires:* `result` shall not be in the range \[`first`, `last`).
2002
+
2003
  *Effects:* Copies elements in the range \[`first`, `last`) into the
2004
  range \[`result`, `result + (last - first)`) starting from `first` and
2005
  proceeding to `last`. For each non-negative integer
2006
  `n < (last - first)`, performs `*(result + n) = *(first + n)`.
2007
 
2008
  *Returns:* `result + (last - first)`.
2009
 
2010
+ *Complexity:* Exactly `last - first` assignments.
2011
+
2012
+ ``` cpp
2013
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
2014
+ ForwardIterator2 copy(ExecutionPolicy&& policy,
2015
+ ForwardIterator1 first, ForwardIterator1 last,
2016
+ ForwardIterator2 result);
2017
+ ```
2018
+
2019
+ *Requires:* The ranges \[`first`, `last`) and \[`result`,
2020
+ `result + (last - first)`) shall not overlap.
2021
+
2022
+ *Effects:* Copies elements in the range \[`first`, `last`) into the
2023
+ range \[`result`, `result + (last - first)`). For each non-negative
2024
+ integer `n < (last - first)`, performs `*(result + n) = *(first + n)`.
2025
+
2026
+ *Returns:* `result + (last - first)`.
2027
 
2028
  *Complexity:* Exactly `last - first` assignments.
2029
 
2030
  ``` cpp
2031
  template<class InputIterator, class Size, class OutputIterator>
2032
  OutputIterator copy_n(InputIterator first, Size n,
2033
  OutputIterator result);
2034
+ template<class ExecutionPolicy, class ForwardIterator1, class Size, class ForwardIterator2>
2035
+ ForwardIterator2 copy_n(ExecutionPolicy&& exec,
2036
+ ForwardIterator1 first, Size n,
2037
+ ForwardIterator2 result);
2038
  ```
2039
 
2040
  *Effects:* For each non-negative integer i < n, performs
2041
  `*(result + i) = *(first + i)`.
2042
 
 
2046
 
2047
  ``` cpp
2048
  template<class InputIterator, class OutputIterator, class Predicate>
2049
  OutputIterator copy_if(InputIterator first, InputIterator last,
2050
  OutputIterator result, Predicate pred);
2051
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class Predicate>
2052
+ ForwardIterator2 copy_if(ExecutionPolicy&& exec,
2053
+ ForwardIterator1 first, ForwardIterator1 last,
2054
+ ForwardIterator2 result, Predicate pred);
2055
  ```
2056
 
2057
  *Requires:* The ranges \[`first`, `last`) and \[`result`,
2058
  `result + (last - first)`) shall not overlap.
2059
 
2060
+ [*Note 1*: For the overload with an `ExecutionPolicy`, there may be a
2061
+ performance cost if `iterator_traits<ForwardIterator1>::value_type` is
2062
+ not `MoveConstructible`
2063
+ (Table  [[tab:moveconstructible]]). — *end note*]
2064
+
2065
  *Effects:* Copies all of the elements referred to by the iterator `i` in
2066
  the range \[`first`, `last`) for which `pred(*i)` is `true`.
2067
 
2068
  *Returns:* The end of the resulting range.
2069
 
 
2078
  copy_backward(BidirectionalIterator1 first,
2079
  BidirectionalIterator1 last,
2080
  BidirectionalIterator2 result);
2081
  ```
2082
 
2083
+ *Requires:* `result` shall not be in the range (`first`, `last`).
2084
+
2085
  *Effects:* Copies elements in the range \[`first`, `last`) into the
2086
  range \[`result - (last-first)`, `result`) starting from `last - 1` and
2087
  proceeding to `first`.[^2] For each positive integer
2088
  `n <= (last - first)`, performs `*(result - n) = *(last - n)`.
2089
 
 
 
2090
  *Returns:* `result - (last - first)`.
2091
 
2092
  *Complexity:* Exactly `last - first` assignments.
2093
 
2094
  ### Move <a id="alg.move">[[alg.move]]</a>
2095
 
2096
  ``` cpp
2097
  template<class InputIterator, class OutputIterator>
2098
+ OutputIterator move(InputIterator first, InputIterator last, OutputIterator result);
 
2099
  ```
2100
 
2101
+ *Requires:* `result` shall not be in the range \[`first`, `last`).
2102
+
2103
  *Effects:* Moves elements in the range \[`first`, `last`) into the range
2104
  \[`result`, `result + (last - first)`) starting from first and
2105
  proceeding to last. For each non-negative integer `n < (last-first)`,
2106
  performs `*(result + n)` `= std::move(*(first + n))`.
2107
 
2108
  *Returns:* `result + (last - first)`.
2109
 
 
 
2110
  *Complexity:* Exactly `last - first` move assignments.
2111
 
2112
+ ``` cpp
2113
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
2114
+ ForwardIterator2 move(ExecutionPolicy&& policy,
2115
+ ForwardIterator1 first, ForwardIterator1 last,
2116
+ ForwardIterator2 result);
2117
+ ```
2118
+
2119
+ *Requires:* The ranges \[`first`, `last`) and \[`result`,
2120
+ `result + (last - first)`) shall not overlap.
2121
+
2122
+ *Effects:* Moves elements in the range \[`first`, `last`) into the range
2123
+ \[`result`, `result + (last - first)`). For each non-negative integer
2124
+ `n < (last - first)`, performs
2125
+ `*(result + n) = std::move(*(first + n))`.
2126
+
2127
+ *Returns:* `result + (last - first)`.
2128
+
2129
+ *Complexity:* Exactly `last - first` assignments.
2130
+
2131
  ``` cpp
2132
  template<class BidirectionalIterator1, class BidirectionalIterator2>
2133
  BidirectionalIterator2
2134
  move_backward(BidirectionalIterator1 first,
2135
  BidirectionalIterator1 last,
2136
  BidirectionalIterator2 result);
2137
  ```
2138
 
2139
+ *Requires:* `result` shall not be in the range (`first`, `last`).
2140
+
2141
  *Effects:* Moves elements in the range \[`first`, `last`) into the range
2142
  \[`result - (last-first)`, `result`) starting from `last - 1` and
2143
  proceeding to first.[^3] For each positive integer
2144
  `n <= (last - first)`, performs
2145
  `*(result - n) = std::move(*(last - n))`.
2146
 
 
 
2147
  *Returns:* `result - (last - first)`.
2148
 
2149
  *Complexity:* Exactly `last - first` assignments.
2150
 
2151
+ ### Swap <a id="alg.swap">[[alg.swap]]</a>
2152
 
2153
  ``` cpp
2154
  template<class ForwardIterator1, class ForwardIterator2>
2155
  ForwardIterator2
2156
  swap_ranges(ForwardIterator1 first1, ForwardIterator1 last1,
2157
  ForwardIterator2 first2);
2158
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
2159
+ ForwardIterator2
2160
+ swap_ranges(ExecutionPolicy&& exec,
2161
+ ForwardIterator1 first1, ForwardIterator1 last1,
2162
+ ForwardIterator2 first2);
2163
  ```
2164
 
 
 
 
2165
  *Requires:* The two ranges \[`first1`, `last1`) and \[`first2`,
2166
  `first2 + (last1 - first1)`) shall not overlap. `*(first1 + n)` shall be
2167
  swappable with ([[swappable.requirements]]) `*(first2 + n)`.
2168
 
2169
+ *Effects:* For each non-negative integer `n < (last1 - first1)`
2170
+ performs: `swap(*(first1 + n), *(first2 + n))`.
2171
+
2172
  *Returns:* `first2 + (last1 - first1)`.
2173
 
2174
  *Complexity:* Exactly `last1 - first1` swaps.
2175
 
2176
  ``` cpp
2177
  template<class ForwardIterator1, class ForwardIterator2>
2178
  void iter_swap(ForwardIterator1 a, ForwardIterator2 b);
2179
  ```
2180
 
 
 
2181
  *Requires:* `a` and `b` shall be dereferenceable. `*a` shall be
2182
  swappable with ([[swappable.requirements]]) `*b`.
2183
 
2184
+ *Effects:* As if by `swap(*a, *b)`.
2185
+
2186
  ### Transform <a id="alg.transform">[[alg.transform]]</a>
2187
 
2188
  ``` cpp
2189
  template<class InputIterator, class OutputIterator,
2190
  class UnaryOperation>
2191
  OutputIterator
2192
  transform(InputIterator first, InputIterator last,
2193
  OutputIterator result, UnaryOperation op);
2194
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
2195
+ class UnaryOperation>
2196
+ ForwardIterator2
2197
+ transform(ExecutionPolicy&& exec,
2198
+ ForwardIterator1 first, ForwardIterator1 last,
2199
+ ForwardIterator2 result, UnaryOperation op);
2200
 
2201
  template<class InputIterator1, class InputIterator2,
2202
  class OutputIterator, class BinaryOperation>
2203
  OutputIterator
2204
  transform(InputIterator1 first1, InputIterator1 last1,
2205
  InputIterator2 first2, OutputIterator result,
2206
  BinaryOperation binary_op);
2207
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
2208
+ class ForwardIterator, class BinaryOperation>
2209
+ ForwardIterator
2210
+ transform(ExecutionPolicy&& exec,
2211
+ ForwardIterator1 first1, ForwardIterator1 last1,
2212
+ ForwardIterator2 first2, ForwardIterator result,
2213
+ BinaryOperation binary_op);
2214
  ```
2215
 
2216
+ *Requires:* `op` and `binary_op` shall not invalidate iterators or
2217
+ subranges, or modify elements in the ranges
2218
+
2219
+ - \[`first1`, `last1`\],
2220
+ - \[`first2`, `first2 + (last1 - first1)`\], and
2221
+ - \[`result`, `result + (last1 - first1)`\].[^4]
2222
+
2223
  *Effects:* Assigns through every iterator `i` in the range \[`result`,
2224
  `result + (last1 - first1)`) a new corresponding value equal to
2225
+ `op(*(first1 + (i - result)))` or
2226
  `binary_op(*(first1 + (i - result)), *(first2 + (i - result)))`.
2227
 
 
 
 
 
 
2228
  *Returns:* `result + (last1 - first1)`.
2229
 
2230
  *Complexity:* Exactly `last1 - first1` applications of `op` or
2231
+ `binary_op`. This requirement also applies to the overload with an
2232
+ `ExecutionPolicy` .
2233
 
2234
  *Remarks:* `result` may be equal to `first` in case of unary transform,
2235
  or to `first1` or `first2` in case of binary transform.
2236
 
2237
  ### Replace <a id="alg.replace">[[alg.replace]]</a>
2238
 
2239
  ``` cpp
2240
  template<class ForwardIterator, class T>
2241
  void replace(ForwardIterator first, ForwardIterator last,
2242
  const T& old_value, const T& new_value);
2243
+ template<class ExecutionPolicy, class ForwardIterator, class T>
2244
+ void replace(ExecutionPolicy&& exec,
2245
+ ForwardIterator first, ForwardIterator last,
2246
+ const T& old_value, const T& new_value);
2247
 
2248
  template<class ForwardIterator, class Predicate, class T>
2249
  void replace_if(ForwardIterator first, ForwardIterator last,
2250
  Predicate pred, const T& new_value);
2251
+ template<class ExecutionPolicy, class ForwardIterator, class Predicate, class T>
2252
+ void replace_if(ExecutionPolicy&& exec,
2253
+ ForwardIterator first, ForwardIterator last,
2254
+ Predicate pred, const T& new_value);
2255
  ```
2256
 
2257
  *Requires:* The expression `*first = new_value` shall be valid.
2258
 
2259
  *Effects:* Substitutes elements referred by the iterator `i` in the
 
2267
  template<class InputIterator, class OutputIterator, class T>
2268
  OutputIterator
2269
  replace_copy(InputIterator first, InputIterator last,
2270
  OutputIterator result,
2271
  const T& old_value, const T& new_value);
2272
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class T>
2273
+ ForwardIterator2
2274
+ replace_copy(ExecutionPolicy&& exec,
2275
+ ForwardIterator1 first, ForwardIterator1 last,
2276
+ ForwardIterator2 result,
2277
+ const T& old_value, const T& new_value);
2278
 
2279
  template<class InputIterator, class OutputIterator, class Predicate, class T>
2280
  OutputIterator
2281
  replace_copy_if(InputIterator first, InputIterator last,
2282
  OutputIterator result,
2283
  Predicate pred, const T& new_value);
2284
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
2285
+ class Predicate, class T>
2286
+ ForwardIterator2
2287
+ replace_copy_if(ExecutionPolicy&& exec,
2288
+ ForwardIterator1 first, ForwardIterator1 last,
2289
+ ForwardIterator2 result,
2290
+ Predicate pred, const T& new_value);
2291
  ```
2292
 
2293
  *Requires:* The results of the expressions `*first` and `new_value`
2294
+ shall be writable ([[iterator.requirements.general]]) to the `result`
2295
+ output iterator. The ranges \[`first`, `last`) and \[`result`,
2296
+ `result + (last - first)`) shall not overlap.
2297
 
2298
  *Effects:* Assigns to every iterator `i` in the range \[`result`,
2299
  `result + (last - first)`) either `new_value` or
2300
  `*(first + (i - result))` depending on whether the following
2301
  corresponding conditions hold:
 
2313
  ### Fill <a id="alg.fill">[[alg.fill]]</a>
2314
 
2315
  ``` cpp
2316
  template<class ForwardIterator, class T>
2317
  void fill(ForwardIterator first, ForwardIterator last, const T& value);
2318
+ template<class ExecutionPolicy, class ForwardIterator, class T>
2319
+ void fill(ExecutionPolicy&& exec,
2320
+ ForwardIterator first, ForwardIterator last, const T& value);
2321
 
2322
  template<class OutputIterator, class Size, class T>
2323
  OutputIterator fill_n(OutputIterator first, Size n, const T& value);
2324
+ template<class ExecutionPolicy, class ForwardIterator, class Size, class T>
2325
+ ForwardIterator fill_n(ExecutionPolicy&& exec,
2326
+ ForwardIterator first, Size n, const T& value);
2327
  ```
2328
 
2329
+ *Requires:* The expression `value` shall be
2330
+ writable ([[iterator.requirements.general]]) to the output iterator.
2331
+ The type `Size` shall be convertible to an integral
2332
  type ([[conv.integral]], [[class.conv]]).
2333
 
2334
+ *Effects:* The `fill` algorithms assign `value` through all the
2335
+ iterators in the range \[`first`, `last`). The `fill_n` algorithms
2336
+ assign `value` through all the iterators in the range \[`first`,
2337
+ `first + n`) if `n` is positive, otherwise they do nothing.
2338
 
2339
  *Returns:* `fill_n` returns `first + n` for non-negative values of `n`
2340
  and `first` for negative values.
2341
 
2342
  *Complexity:* Exactly `last - first`, `n`, or 0 assignments,
 
2346
 
2347
  ``` cpp
2348
  template<class ForwardIterator, class Generator>
2349
  void generate(ForwardIterator first, ForwardIterator last,
2350
  Generator gen);
2351
+ template<class ExecutionPolicy, class ForwardIterator, class Generator>
2352
+ void generate(ExecutionPolicy&& exec,
2353
+ ForwardIterator first, ForwardIterator last,
2354
+ Generator gen);
2355
 
2356
  template<class OutputIterator, class Size, class Generator>
2357
  OutputIterator generate_n(OutputIterator first, Size n, Generator gen);
2358
+ template<class ExecutionPolicy, class ForwardIterator, class Size, class Generator>
2359
+ ForwardIterator generate_n(ExecutionPolicy&& exec,
2360
+ ForwardIterator first, Size n, Generator gen);
2361
  ```
2362
 
 
 
 
 
 
 
 
2363
  *Requires:* `gen` takes no arguments, `Size` shall be convertible to an
2364
  integral type ([[conv.integral]], [[class.conv]]).
2365
 
2366
+ *Effects:* The `generate` algorithms invoke the function object `gen`
2367
+ and assign the return value of `gen` through all the iterators in the
2368
+ range \[`first`, `last`). The `generate_n` algorithms invoke the
2369
+ function object `gen` and assign the return value of `gen` through all
2370
+ the iterators in the range \[`first`, `first + n`) if `n` is positive,
2371
+ otherwise they do nothing.
2372
+
2373
  *Returns:* `generate_n` returns `first + n` for non-negative values of
2374
  `n` and `first` for negative values.
2375
 
2376
  *Complexity:* Exactly `last - first`, `n`, or 0 invocations of `gen` and
2377
  assignments, respectively.
 
2380
 
2381
  ``` cpp
2382
  template<class ForwardIterator, class T>
2383
  ForwardIterator remove(ForwardIterator first, ForwardIterator last,
2384
  const T& value);
2385
+ template<class ExecutionPolicy, class ForwardIterator, class T>
2386
+ ForwardIterator remove(ExecutionPolicy&& exec,
2387
+ ForwardIterator first, ForwardIterator last,
2388
+ const T& value);
2389
 
2390
  template<class ForwardIterator, class Predicate>
2391
  ForwardIterator remove_if(ForwardIterator first, ForwardIterator last,
2392
  Predicate pred);
2393
+ template<class ExecutionPolicy, class ForwardIterator, class Predicate>
2394
+ ForwardIterator remove_if(ExecutionPolicy&& exec,
2395
+ ForwardIterator first, ForwardIterator last,
2396
+ Predicate pred);
2397
  ```
2398
 
2399
  *Requires:* The type of `*first` shall satisfy the `MoveAssignable`
2400
+ requirements (Table  [[tab:moveassignable]]).
2401
 
2402
  *Effects:* Eliminates all the elements referred to by iterator `i` in
2403
  the range \[`first`, `last`) for which the following corresponding
2404
  conditions hold: `*i == value, pred(*i) != false`.
2405
 
 
2408
  *Remarks:* Stable ([[algorithm.stable]]).
2409
 
2410
  *Complexity:* Exactly `last - first` applications of the corresponding
2411
  predicate.
2412
 
2413
+ [*Note 1*: Each element in the range \[`ret`, `last`), where `ret` is
2414
+ the returned value, has a valid but unspecified state, because the
2415
  algorithms can eliminate elements by moving from elements that were
2416
+ originally in that range. — *end note*]
2417
 
2418
  ``` cpp
2419
  template<class InputIterator, class OutputIterator, class T>
2420
  OutputIterator
2421
  remove_copy(InputIterator first, InputIterator last,
2422
  OutputIterator result, const T& value);
2423
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class T>
2424
+ ForwardIterator2
2425
+ remove_copy(ExecutionPolicy&& exec,
2426
+ ForwardIterator1 first, ForwardIterator1 last,
2427
+ ForwardIterator2 result, const T& value);
2428
 
2429
  template<class InputIterator, class OutputIterator, class Predicate>
2430
  OutputIterator
2431
  remove_copy_if(InputIterator first, InputIterator last,
2432
  OutputIterator result, Predicate pred);
2433
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class Predicate>
2434
+ ForwardIterator2
2435
+ remove_copy_if(ExecutionPolicy&& exec,
2436
+ ForwardIterator1 first, ForwardIterator1 last,
2437
+ ForwardIterator2 result, Predicate pred);
2438
  ```
2439
 
2440
  *Requires:* The ranges \[`first`, `last`) and \[`result`,
2441
  `result + (last - first)`) shall not overlap. The expression
2442
  `*result = *first` shall be valid.
2443
 
2444
+ [*Note 2*: For the overloads with an `ExecutionPolicy`, there may be a
2445
+ performance cost if `iterator_traits<ForwardIterator1>::value_type` is
2446
+ not `MoveConstructible`
2447
+ (Table  [[tab:moveconstructible]]). — *end note*]
2448
+
2449
  *Effects:* Copies all the elements referred to by the iterator `i` in
2450
  the range \[`first`, `last`) for which the following corresponding
2451
  conditions do not hold: `*i == value, pred(*i) != false`.
2452
 
2453
  *Returns:* The end of the resulting range.
 
2460
  ### Unique <a id="alg.unique">[[alg.unique]]</a>
2461
 
2462
  ``` cpp
2463
  template<class ForwardIterator>
2464
  ForwardIterator unique(ForwardIterator first, ForwardIterator last);
2465
+ template<class ExecutionPolicy, class ForwardIterator>
2466
+ ForwardIterator unique(ExecutionPolicy&& exec,
2467
+ ForwardIterator first, ForwardIterator last);
2468
 
2469
  template<class ForwardIterator, class BinaryPredicate>
2470
  ForwardIterator unique(ForwardIterator first, ForwardIterator last,
2471
  BinaryPredicate pred);
2472
+ template<class ExecutionPolicy, class ForwardIterator, class BinaryPredicate>
2473
+ ForwardIterator unique(ExecutionPolicy&& exec,
2474
+ ForwardIterator first, ForwardIterator last,
2475
+ BinaryPredicate pred);
2476
  ```
2477
 
2478
+ *Requires:* The comparison function shall be an equivalence relation.
2479
+ The type of `*first` shall satisfy the `MoveAssignable` requirements
2480
+ (Table  [[tab:moveassignable]]).
2481
+
2482
  *Effects:* For a nonempty range, eliminates all but the first element
2483
  from every consecutive group of equivalent elements referred to by the
2484
  iterator `i` in the range \[`first + 1`, `last`) for which the following
2485
  conditions hold: `*(i - 1) == *i` or `pred(*(i - 1), *i) != false`.
2486
 
 
 
 
 
2487
  *Returns:* The end of the resulting range.
2488
 
2489
  *Complexity:* For nonempty ranges, exactly `(last - first) - 1`
2490
  applications of the corresponding predicate.
2491
 
2492
  ``` cpp
2493
  template<class InputIterator, class OutputIterator>
2494
  OutputIterator
2495
  unique_copy(InputIterator first, InputIterator last,
2496
  OutputIterator result);
2497
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
2498
+ ForwardIterator2
2499
+ unique_copy(ExecutionPolicy&& exec,
2500
+ ForwardIterator1 first, ForwardIterator1 last,
2501
+ ForwardIterator2 result);
2502
 
2503
  template<class InputIterator, class OutputIterator,
2504
  class BinaryPredicate>
2505
  OutputIterator
2506
  unique_copy(InputIterator first, InputIterator last,
2507
  OutputIterator result, BinaryPredicate pred);
2508
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
2509
+ class BinaryPredicate>
2510
+ ForwardIterator2
2511
+ unique_copy(ExecutionPolicy&& exec,
2512
+ ForwardIterator1 first, ForwardIterator1 last,
2513
+ ForwardIterator2 result, BinaryPredicate pred);
2514
  ```
2515
 
2516
+ *Requires:*
2517
+
2518
+ - The comparison function shall be an equivalence relation.
2519
+ - The ranges \[`first`, `last`) and \[`result`, `result+(last-first)`)
2520
+ shall not overlap.
2521
+ - The expression `*result = *first` shall be valid.
2522
+ - For the overloads with no `ExecutionPolicy`, let `T` be the value type
2523
+ of `InputIterator`. If `InputIterator` meets the forward iterator
2524
+ requirements, then there are no additional requirements for `T`.
2525
+ Otherwise, if `OutputIterator` meets the forward iterator requirements
2526
+ and its value type is the same as `T`, then `T` shall be
2527
+ `CopyAssignable` (Table  [[tab:copyassignable]]). Otherwise, `T` shall
2528
+ be both `CopyConstructible` (Table  [[tab:copyconstructible]]) and
2529
+ `CopyAssignable`. \[*Note 1*: For the overloads with an
2530
+ `ExecutionPolicy`, there may be a performance cost if the value type
2531
+ of `ForwardIterator1` is not both `CopyConstructible` and
2532
+ `CopyAssignable`. — *end note*]
2533
 
2534
  *Effects:* Copies only the first element from every consecutive group of
2535
  equal elements referred to by the iterator `i` in the range \[`first`,
2536
  `last`) for which the following corresponding conditions hold:
2537
  `*i == *(i - 1)` or `pred(*i, *(i - 1)) != false`.
 
2544
  ### Reverse <a id="alg.reverse">[[alg.reverse]]</a>
2545
 
2546
  ``` cpp
2547
  template<class BidirectionalIterator>
2548
  void reverse(BidirectionalIterator first, BidirectionalIterator last);
2549
+ template<class ExecutionPolicy, class BidirectionalIterator>
2550
+ void reverse(ExecutionPolicy&& exec,
2551
+ BidirectionalIterator first, BidirectionalIterator last);
2552
  ```
2553
 
 
 
 
2554
  *Requires:* `*first` shall be swappable ([[swappable.requirements]]).
2555
 
2556
+ *Effects:* For each non-negative integer `i < (last - first) / 2`,
2557
+ applies `iter_swap` to all pairs of iterators
2558
+ `first + i, (last - i) - 1`.
2559
+
2560
+ *Requires:* `BidirectionalIterator` shall satisfy the requirements of
2561
+ `ValueSwappable` ([[swappable.requirements]]).
2562
+
2563
  *Complexity:* Exactly `(last - first)/2` swaps.
2564
 
2565
  ``` cpp
2566
  template<class BidirectionalIterator, class OutputIterator>
2567
  OutputIterator
2568
+ reverse_copy(BidirectionalIterator first, BidirectionalIterator last,
2569
+ OutputIterator result);
2570
+ template<class ExecutionPolicy, class BidirectionalIterator, class ForwardIterator>
2571
+ ForwardIterator
2572
+ reverse_copy(ExecutionPolicy&& exec,
2573
+ BidirectionalIterator first, BidirectionalIterator last,
2574
+ ForwardIterator result);
2575
  ```
2576
 
2577
+ *Requires:* The ranges \[`first`, `last`) and \[`result`,
2578
+ `result + (last - first)`) shall not overlap.
2579
+
2580
  *Effects:* Copies the range \[`first`, `last`) to the range \[`result`,
2581
  `result + (last - first)`) such that for every non-negative integer
2582
  `i < (last - first)` the following assignment takes place:
2583
  `*(result + (last - first) - 1 - i) = *(first + i)`.
2584
 
 
 
 
2585
  *Returns:* `result + (last - first)`.
2586
 
2587
  *Complexity:* Exactly `last - first` assignments.
2588
 
2589
  ### Rotate <a id="alg.rotate">[[alg.rotate]]</a>
2590
 
2591
  ``` cpp
2592
  template<class ForwardIterator>
2593
+ ForwardIterator
2594
+ rotate(ForwardIterator first, ForwardIterator middle, ForwardIterator last);
2595
+ template<class ExecutionPolicy, class ForwardIterator>
2596
+ ForwardIterator
2597
+ rotate(ExecutionPolicy&& exec,
2598
+ ForwardIterator first, ForwardIterator middle, ForwardIterator last);
2599
  ```
2600
 
2601
+ *Requires:* \[`first`, `middle`) and \[`middle`, `last`) shall be valid
2602
+ ranges. `ForwardIterator` shall satisfy the requirements of
2603
+ `ValueSwappable` ([[swappable.requirements]]). The type of `*first`
2604
+ shall satisfy the requirements of `MoveConstructible`
2605
+ (Table  [[tab:moveconstructible]]) and the requirements of
2606
+ `MoveAssignable` (Table  [[tab:moveassignable]]).
2607
+
2608
  *Effects:* For each non-negative integer `i < (last - first)`, places
2609
  the element from the position `first + i` into position
2610
  `first + (i + (last - middle)) % (last - first)`.
2611
 
2612
  *Returns:* `first + (last - middle)`.
2613
 
2614
  *Remarks:* This is a left rotate.
2615
 
 
 
 
 
 
 
 
2616
  *Complexity:* At most `last - first` swaps.
2617
 
2618
  ``` cpp
2619
  template<class ForwardIterator, class OutputIterator>
2620
  OutputIterator
2621
+ rotate_copy(ForwardIterator first, ForwardIterator middle, ForwardIterator last,
2622
+ OutputIterator result);
2623
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
2624
+ ForwardIterator2
2625
+ rotate_copy(ExecutionPolicy&& exec,
2626
+ ForwardIterator1 first, ForwardIterator1 middle, ForwardIterator1 last,
2627
+ ForwardIterator2 result);
2628
  ```
2629
 
2630
+ *Requires:* The ranges \[`first`, `last`) and \[`result`,
2631
+ `result + (last - first)`) shall not overlap.
2632
+
2633
  *Effects:* Copies the range \[`first`, `last`) to the range \[`result`,
2634
  `result + (last - first)`) such that for each non-negative integer
2635
  `i < (last - first)` the following assignment takes place:
2636
  `*(result + i) = *(first + (i + (middle - first)) % (last - first))`.
2637
 
2638
  *Returns:* `result + (last - first)`.
2639
 
 
 
 
2640
  *Complexity:* Exactly `last - first` assignments.
2641
 
2642
+ ### Sample <a id="alg.random.sample">[[alg.random.sample]]</a>
2643
+
2644
+ ``` cpp
2645
+ template<class PopulationIterator, class SampleIterator,
2646
+ class Distance, class UniformRandomBitGenerator>
2647
+ SampleIterator sample(PopulationIterator first, PopulationIterator last,
2648
+ SampleIterator out, Distance n,
2649
+ UniformRandomBitGenerator&& g);
2650
+ ```
2651
+
2652
+ *Requires:*
2653
+
2654
+ - `PopulationIterator` shall satisfy the requirements of an input
2655
+ iterator ([[input.iterators]]).
2656
+ - `SampleIterator` shall satisfy the requirements of an output
2657
+ iterator ([[output.iterators]]).
2658
+ - `SampleIterator` shall satisfy the additional requirements of a random
2659
+ access iterator ([[random.access.iterators]]) unless
2660
+ `PopulationIterator` satisfies the additional requirements of a
2661
+ forward iterator ([[forward.iterators]]).
2662
+ - `PopulationIterator`’s value type shall be
2663
+ writable ([[iterator.requirements.general]]) to `out`.
2664
+ - `Distance` shall be an integer type.
2665
+ - `remove_reference_t<UniformRandomBitGenerator>` shall meet the
2666
+ requirements of a uniform random bit generator type
2667
+ ([[rand.req.urng]]) whose return type is convertible to `Distance`.
2668
+ - `out` shall not be in the range \[`first`, `last`).
2669
+
2670
+ *Effects:* Copies `min(last - first, n)` elements (the *sample*) from
2671
+ \[`first`, `last`) (the *population*) to `out` such that each possible
2672
+ sample has equal probability of appearance.
2673
+
2674
+ [*Note 1*: Algorithms that obtain such effects include *selection
2675
+ sampling* and *reservoir sampling*. — *end note*]
2676
+
2677
+ *Returns:* The end of the resulting sample range.
2678
+
2679
+ *Complexity:* 𝑂(`last - first`).
2680
+
2681
+ *Remarks:*
2682
+
2683
+ - Stable if and only if `PopulationIterator` satisfies the requirements
2684
+ of a forward iterator.
2685
+ - To the extent that the implementation of this function makes use of
2686
+ random numbers, the object `g` shall serve as the implementation’s
2687
+ source of randomness.
2688
+
2689
  ### Shuffle <a id="alg.random.shuffle">[[alg.random.shuffle]]</a>
2690
 
2691
  ``` cpp
2692
+ template<class RandomAccessIterator, class UniformRandomBitGenerator>
2693
  void shuffle(RandomAccessIterator first,
2694
  RandomAccessIterator last,
2695
+ UniformRandomBitGenerator&& g);
2696
  ```
2697
 
2698
+ *Requires:* `RandomAccessIterator` shall satisfy the requirements of
2699
+ `ValueSwappable` ([[swappable.requirements]]). The type
2700
+ `remove_reference_t<UniformRandomBitGenerator>` shall meet the
2701
+ requirements of a uniform random bit generator ([[rand.req.urng]]) type
2702
+ whose return type is convertible to
2703
+ `iterator_traits<RandomAccessIterator>::difference_type`.
2704
+
2705
  *Effects:* Permutes the elements in the range \[`first`, `last`) such
2706
  that each possible permutation of those elements has equal probability
2707
  of appearance.
2708
 
 
 
 
 
 
 
2709
  *Complexity:* Exactly `(last - first) - 1` swaps.
2710
 
2711
  *Remarks:* To the extent that the implementation of this function makes
2712
  use of random numbers, the object `g` shall serve as the
2713
  implementation’s source of randomness.
2714
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2715
  ## Sorting and related operations <a id="alg.sorting">[[alg.sorting]]</a>
2716
 
2717
  All the operations in  [[alg.sorting]] have two versions: one that takes
2718
  a function object of type `Compare` and one that uses an `operator<`.
2719
 
 
2728
  non-constant function through the dereferenced iterator.
2729
 
2730
  For all algorithms that take `Compare`, there is a version that uses
2731
  `operator<` instead. That is, `comp(*i, *j) != false` defaults to
2732
  `*i < *j != false`. For algorithms other than those described in 
2733
+ [[alg.binary.search]], `comp` shall induce a strict weak ordering on the
2734
+ values.
2735
 
2736
  The term *strict* refers to the requirement of an irreflexive relation
2737
  (`!comp(x, x)` for all `x`), and the term *weak* to requirements that
2738
  are not as strong as those for a total ordering, but stronger than those
2739
  for a partial ordering. If we define `equiv(a, b)` as
2740
  `!comp(a, b) && !comp(b, a)`, then the requirements are that `comp` and
2741
  `equiv` both be transitive relations:
2742
 
2743
  - `comp(a, b) && comp(b, c)` implies `comp(a, c)`
2744
+ - `equiv(a, b) && equiv(b, c)` implies `equiv(a, c)`
2745
+
2746
+ [*Note 1*:
2747
+
2748
+ Under these conditions, it can be shown that
2749
+
2750
  - `equiv` is an equivalence relation
2751
  - `comp` induces a well-defined relation on the equivalence classes
2752
  determined by `equiv`
2753
  - The induced relation is a strict total ordering.
2754
 
2755
+ — *end note*]
2756
+
2757
  A sequence is *sorted with respect to a comparator* `comp` if for every
2758
  iterator `i` pointing to the sequence and every non-negative integer `n`
2759
  such that `i + n` is a valid iterator pointing to an element of the
2760
  sequence, `comp(*(i + n), *i) == false`.
2761
 
2762
  A sequence \[`start`, `finish`) is *partitioned with respect to an
2763
  expression* `f(e)` if there exists an integer `n` such that for all
2764
+ `0 <= i < (finish - start)`, `f(*(start + i))` is `true` if and only if
2765
+ `i < n`.
2766
 
2767
  In the descriptions of the functions that deal with ordering
2768
  relationships we frequently use a notion of equivalence to describe
2769
  concepts such as stability. The equivalence to which we refer is not
2770
  necessarily an `operator==`, but an equivalence relation induced by the
 
2776
  #### `sort` <a id="sort">[[sort]]</a>
2777
 
2778
  ``` cpp
2779
  template<class RandomAccessIterator>
2780
  void sort(RandomAccessIterator first, RandomAccessIterator last);
2781
+ template<class ExecutionPolicy, class RandomAccessIterator>
2782
+ void sort(ExecutionPolicy&& exec,
2783
+ RandomAccessIterator first, RandomAccessIterator last);
2784
 
2785
  template<class RandomAccessIterator, class Compare>
2786
  void sort(RandomAccessIterator first, RandomAccessIterator last,
2787
  Compare comp);
2788
+ template<class ExecutionPolicy, class RandomAccessIterator, class Compare>
2789
+ void sort(ExecutionPolicy&& exec,
2790
+ RandomAccessIterator first, RandomAccessIterator last,
2791
+ Compare comp);
2792
  ```
2793
 
 
 
2794
  *Requires:* `RandomAccessIterator` shall satisfy the requirements of
2795
  `ValueSwappable` ([[swappable.requirements]]). The type of `*first`
2796
  shall satisfy the requirements of `MoveConstructible`
2797
+ (Table  [[tab:moveconstructible]]) and of `MoveAssignable`
2798
+ (Table  [[tab:moveassignable]]).
2799
 
2800
+ *Effects:* Sorts the elements in the range \[`first`, `last`).
2801
+
2802
+ *Complexity:* 𝑂(N log N) comparisons, where N = `last - first`.
2803
 
2804
  #### `stable_sort` <a id="stable.sort">[[stable.sort]]</a>
2805
 
2806
  ``` cpp
2807
  template<class RandomAccessIterator>
2808
  void stable_sort(RandomAccessIterator first, RandomAccessIterator last);
2809
+ template<class ExecutionPolicy, class RandomAccessIterator>
2810
+ void stable_sort(ExecutionPolicy&& exec,
2811
+ RandomAccessIterator first, RandomAccessIterator last);
2812
 
2813
  template<class RandomAccessIterator, class Compare>
2814
  void stable_sort(RandomAccessIterator first, RandomAccessIterator last,
2815
  Compare comp);
2816
+ template<class ExecutionPolicy, class RandomAccessIterator, class Compare>
2817
+ void stable_sort(ExecutionPolicy&& exec,
2818
+ RandomAccessIterator first, RandomAccessIterator last,
2819
+ Compare comp);
2820
  ```
2821
 
 
 
2822
  *Requires:* `RandomAccessIterator` shall satisfy the requirements of
2823
  `ValueSwappable` ([[swappable.requirements]]). The type of `*first`
2824
  shall satisfy the requirements of `MoveConstructible`
2825
+ (Table  [[tab:moveconstructible]]) and of `MoveAssignable`
2826
+ (Table  [[tab:moveassignable]]).
2827
 
2828
+ *Effects:* Sorts the elements in the range \[`first`, `last`).
2829
+
2830
+ *Complexity:* At most N log²(N) comparisons, where N = `last - first`,
2831
+ but only N log N comparisons if there is enough extra memory.
2832
 
2833
  *Remarks:* Stable ([[algorithm.stable]]).
2834
 
2835
  #### `partial_sort` <a id="partial.sort">[[partial.sort]]</a>
2836
 
2837
  ``` cpp
2838
  template<class RandomAccessIterator>
2839
  void partial_sort(RandomAccessIterator first,
2840
  RandomAccessIterator middle,
2841
  RandomAccessIterator last);
2842
+ template<class ExecutionPolicy, class RandomAccessIterator>
2843
+ void partial_sort(ExecutionPolicy&& exec,
2844
+ RandomAccessIterator first,
2845
+ RandomAccessIterator middle,
2846
+ RandomAccessIterator last);
2847
 
2848
  template<class RandomAccessIterator, class Compare>
2849
  void partial_sort(RandomAccessIterator first,
2850
  RandomAccessIterator middle,
2851
  RandomAccessIterator last,
2852
  Compare comp);
2853
+ template<class ExecutionPolicy, class RandomAccessIterator, class Compare>
2854
+ void partial_sort(ExecutionPolicy&& exec,
2855
+ RandomAccessIterator first,
2856
+ RandomAccessIterator middle,
2857
+ RandomAccessIterator last,
2858
+ Compare comp);
2859
  ```
2860
 
2861
+ *Requires:* `RandomAccessIterator` shall satisfy the requirements of
2862
+ `ValueSwappable` ([[swappable.requirements]]). The type of `*first`
2863
+ shall satisfy the requirements of `MoveConstructible`
2864
+ (Table  [[tab:moveconstructible]]) and of `MoveAssignable`
2865
+ (Table  [[tab:moveassignable]]).
2866
+
2867
  *Effects:* Places the first `middle - first` sorted elements from the
2868
  range \[`first`, `last`) into the range \[`first`, `middle`). The rest
2869
  of the elements in the range \[`middle`, `last`) are placed in an
2870
  unspecified order.
2871
 
2872
+ *Complexity:* Approximately `(last - first) * log(middle - first)`
2873
+ comparisons.
 
 
 
 
 
 
2874
 
2875
  #### `partial_sort_copy` <a id="partial.sort.copy">[[partial.sort.copy]]</a>
2876
 
2877
  ``` cpp
2878
  template<class InputIterator, class RandomAccessIterator>
2879
  RandomAccessIterator
2880
  partial_sort_copy(InputIterator first, InputIterator last,
2881
  RandomAccessIterator result_first,
2882
  RandomAccessIterator result_last);
2883
+ template<class ExecutionPolicy, class ForwardIterator, class RandomAccessIterator>
2884
+ RandomAccessIterator
2885
+ partial_sort_copy(ExecutionPolicy&& exec,
2886
+ ForwardIterator first, ForwardIterator last,
2887
+ RandomAccessIterator result_first,
2888
+ RandomAccessIterator result_last);
2889
 
2890
  template<class InputIterator, class RandomAccessIterator,
2891
  class Compare>
2892
  RandomAccessIterator
2893
  partial_sort_copy(InputIterator first, InputIterator last,
2894
  RandomAccessIterator result_first,
2895
  RandomAccessIterator result_last,
2896
  Compare comp);
2897
+ template<class ExecutionPolicy, class ForwardIterator, class RandomAccessIterator,
2898
+ class Compare>
2899
+ RandomAccessIterator
2900
+ partial_sort_copy(ExecutionPolicy&& exec,
2901
+ ForwardIterator first, ForwardIterator last,
2902
+ RandomAccessIterator result_first,
2903
+ RandomAccessIterator result_last,
2904
+ Compare comp);
2905
  ```
2906
 
2907
+ *Requires:* `RandomAccessIterator` shall satisfy the requirements of
2908
+ `ValueSwappable` ([[swappable.requirements]]). The type of
2909
+ `*result_first` shall satisfy the requirements of `MoveConstructible`
2910
+ (Table  [[tab:moveconstructible]]) and of `MoveAssignable`
2911
+ (Table  [[tab:moveassignable]]).
2912
+
2913
  *Effects:* Places the first
2914
  `min(last - first, result_last - result_first)` sorted elements into the
2915
  range \[`result_first`,
2916
  `result_first + min(last - first, result_last - result_first)`).
2917
 
2918
  *Returns:* The smaller of: `result_last` or
2919
  `result_first + (last - first)`.
2920
 
 
 
 
 
 
 
2921
  *Complexity:* Approximately
2922
  `(last - first) * log(min(last - first, result_last - result_first))`
2923
  comparisons.
2924
 
2925
  #### `is_sorted` <a id="is.sorted">[[is.sorted]]</a>
 
2929
  bool is_sorted(ForwardIterator first, ForwardIterator last);
2930
  ```
2931
 
2932
  *Returns:* `is_sorted_until(first, last) == last`
2933
 
2934
+ ``` cpp
2935
+ template<class ExecutionPolicy, class ForwardIterator>
2936
+ bool is_sorted(ExecutionPolicy&& exec,
2937
+ ForwardIterator first, ForwardIterator last);
2938
+ ```
2939
+
2940
+ *Returns:*
2941
+ `is_sorted_until(std::forward<ExecutionPolicy>(exec), first, last) == last`
2942
+
2943
  ``` cpp
2944
  template<class ForwardIterator, class Compare>
2945
  bool is_sorted(ForwardIterator first, ForwardIterator last,
2946
  Compare comp);
2947
  ```
2948
 
2949
  *Returns:* `is_sorted_until(first, last, comp) == last`
2950
 
2951
+ ``` cpp
2952
+ template<class ExecutionPolicy, class ForwardIterator, class Compare>
2953
+ bool is_sorted(ExecutionPolicy&& exec,
2954
+ ForwardIterator first, ForwardIterator last,
2955
+ Compare comp);
2956
+ ```
2957
+
2958
+ *Returns:*
2959
+
2960
+ ``` cpp
2961
+ is_sorted_until(std::forward<ExecutionPolicy>(exec), first, last, comp) == last
2962
+ ```
2963
+
2964
  ``` cpp
2965
  template<class ForwardIterator>
2966
  ForwardIterator is_sorted_until(ForwardIterator first, ForwardIterator last);
2967
+ template<class ExecutionPolicy, class ForwardIterator>
2968
+ ForwardIterator is_sorted_until(ExecutionPolicy&& exec,
2969
+ ForwardIterator first, ForwardIterator last);
2970
+
2971
  template<class ForwardIterator, class Compare>
2972
  ForwardIterator is_sorted_until(ForwardIterator first, ForwardIterator last,
2973
  Compare comp);
2974
+ template<class ExecutionPolicy, class ForwardIterator, class Compare>
2975
+ ForwardIterator is_sorted_until(ExecutionPolicy&& exec,
2976
+ ForwardIterator first, ForwardIterator last,
2977
+ Compare comp);
2978
  ```
2979
 
2980
+ *Returns:* If `(last - first) < 2`, returns `last`. Otherwise, returns
2981
+ the last iterator `i` in \[`first`, `last`\] for which the range
2982
  \[`first`, `i`) is sorted.
2983
 
2984
  *Complexity:* Linear.
2985
 
2986
  ### Nth element <a id="alg.nth.element">[[alg.nth.element]]</a>
2987
 
2988
  ``` cpp
2989
  template<class RandomAccessIterator>
2990
  void nth_element(RandomAccessIterator first, RandomAccessIterator nth,
2991
  RandomAccessIterator last);
2992
+ template<class ExecutionPolicy, class RandomAccessIterator>
2993
+ void nth_element(ExecutionPolicy&& exec,
2994
+ RandomAccessIterator first, RandomAccessIterator nth,
2995
+ RandomAccessIterator last);
2996
 
2997
  template<class RandomAccessIterator, class Compare>
2998
  void nth_element(RandomAccessIterator first, RandomAccessIterator nth,
2999
  RandomAccessIterator last, Compare comp);
3000
+ template<class ExecutionPolicy, class RandomAccessIterator, class Compare>
3001
+ void nth_element(ExecutionPolicy&& exec,
3002
+ RandomAccessIterator first, RandomAccessIterator nth,
3003
+ RandomAccessIterator last, Compare comp);
3004
  ```
3005
 
 
 
 
 
 
 
3006
  *Requires:* `RandomAccessIterator` shall satisfy the requirements of
3007
  `ValueSwappable` ([[swappable.requirements]]). The type of `*first`
3008
  shall satisfy the requirements of `MoveConstructible`
3009
+ (Table  [[tab:moveconstructible]]) and of `MoveAssignable`
3010
+ (Table  [[tab:moveassignable]]).
3011
 
3012
+ *Effects:* After `nth_element` the element in the position pointed to by
3013
+ `nth` is the element that would be in that position if the whole range
3014
+ were sorted, unless `nth == last`. Also for every iterator `i` in the
3015
+ range \[`first`, `nth`) and every iterator `j` in the range \[`nth`,
3016
+ `last`) it holds that: `!(*j < *i)` or `comp(*j, *i) == false`.
3017
+
3018
+ *Complexity:* For the overloads with no `ExecutionPolicy`, linear on
3019
+ average. For the overloads with an `ExecutionPolicy`, 𝑂(N) applications
3020
+ of the predicate, and 𝑂(N log N) swaps, where N = `last - first`.
3021
 
3022
  ### Binary search <a id="alg.binary.search">[[alg.binary.search]]</a>
3023
 
3024
  All of the algorithms in this section are versions of binary search and
3025
  assume that the sequence being searched is partitioned with respect to
 
3139
  `!(*i < value) && !(value < *i)` or
3140
  `comp(*i, value) == false && comp(value, *i) == false`.
3141
 
3142
  *Complexity:* At most log₂(`last - first`) + 𝑂(1) comparisons.
3143
 
3144
+ ### Partitions <a id="alg.partitions">[[alg.partitions]]</a>
3145
+
3146
+ ``` cpp
3147
+ template <class InputIterator, class Predicate>
3148
+ bool is_partitioned(InputIterator first, InputIterator last, Predicate pred);
3149
+ template <class ExecutionPolicy, class ForwardIterator, class Predicate>
3150
+ bool is_partitioned(ExecutionPolicy&& exec,
3151
+ ForwardIterator first, ForwardIterator last, Predicate pred);
3152
+ ```
3153
+
3154
+ *Requires:* For the overload with no `ExecutionPolicy`,
3155
+ `InputIterator`’s value type shall be convertible to `Predicate`’s
3156
+ argument type. For the overload with an `ExecutionPolicy`,
3157
+ `ForwardIterator`’s value type shall be convertible to `Predicate`’s
3158
+ argument type.
3159
+
3160
+ *Returns:* `true` if \[`first`, `last`) is empty or if \[`first`,
3161
+ `last`) is partitioned by `pred`, i.e. if all elements that satisfy
3162
+ `pred` appear before those that do not.
3163
+
3164
+ *Complexity:* Linear. At most `last - first` applications of `pred`.
3165
+
3166
+ ``` cpp
3167
+ template<class ForwardIterator, class Predicate>
3168
+ ForwardIterator
3169
+ partition(ForwardIterator first, ForwardIterator last, Predicate pred);
3170
+ template<class ExecutionPolicy, class ForwardIterator, class Predicate>
3171
+ ForwardIterator
3172
+ partition(ExecutionPolicy&& exec,
3173
+ ForwardIterator first, ForwardIterator last, Predicate pred);
3174
+ ```
3175
+
3176
+ *Requires:* `ForwardIterator` shall satisfy the requirements of
3177
+ `ValueSwappable` ([[swappable.requirements]]).
3178
+
3179
+ *Effects:* Places all the elements in the range \[`first`, `last`) that
3180
+ satisfy `pred` before all the elements that do not satisfy it.
3181
+
3182
+ *Returns:* An iterator `i` such that for every iterator `j` in the range
3183
+ \[`first`, `i`) `pred(*j) != false`, and for every iterator `k` in the
3184
+ range \[`i`, `last`), `pred(*k) == false`.
3185
+
3186
+ *Complexity:* Let N = `last - first`:
3187
+
3188
+ - For the overload with no `ExecutionPolicy`, exactly N applications of
3189
+ the predicate. At most N / 2 swaps if `ForwardIterator` meets the
3190
+ `BidirectionalIterator` requirements and at most N swaps otherwise.
3191
+ - For the overload with an `ExecutionPolicy`, 𝑂(N log N) swaps and 𝑂(N)
3192
+ applications of the predicate.
3193
+
3194
+ ``` cpp
3195
+ template<class BidirectionalIterator, class Predicate>
3196
+ BidirectionalIterator
3197
+ stable_partition(BidirectionalIterator first, BidirectionalIterator last,
3198
+ Predicate pred);
3199
+ template<class ExecutionPolicy, class BidirectionalIterator, class Predicate>
3200
+ BidirectionalIterator
3201
+ stable_partition(ExecutionPolicy&& exec,
3202
+ BidirectionalIterator first, BidirectionalIterator last,
3203
+ Predicate pred);
3204
+ ```
3205
+
3206
+ *Requires:* `BidirectionalIterator` shall satisfy the requirements of
3207
+ `ValueSwappable` ([[swappable.requirements]]). The type of `*first`
3208
+ shall satisfy the requirements of `MoveConstructible`
3209
+ (Table  [[tab:moveconstructible]]) and of `MoveAssignable`
3210
+ (Table  [[tab:moveassignable]]).
3211
+
3212
+ *Effects:* Places all the elements in the range \[`first`, `last`) that
3213
+ satisfy `pred` before all the elements that do not satisfy it.
3214
+
3215
+ *Returns:* An iterator `i` such that for every iterator `j` in the range
3216
+ \[`first`, `i`), `pred(*j) != false`, and for every iterator `k` in the
3217
+ range \[`i`, `last`), `pred(*k) == false`. The relative order of the
3218
+ elements in both groups is preserved.
3219
+
3220
+ *Complexity:* Let N = `last - first`:
3221
+
3222
+ - For the overload with no `ExecutionPolicy`, at most N log N swaps, but
3223
+ only 𝑂(N) swaps if there is enough extra memory. Exactly N
3224
+ applications of the predicate.
3225
+ - For the overload with an `ExecutionPolicy`, 𝑂(N log N) swaps and 𝑂(N)
3226
+ applications of the predicate.
3227
+
3228
+ ``` cpp
3229
+ template <class InputIterator, class OutputIterator1,
3230
+ class OutputIterator2, class Predicate>
3231
+ pair<OutputIterator1, OutputIterator2>
3232
+ partition_copy(InputIterator first, InputIterator last,
3233
+ OutputIterator1 out_true, OutputIterator2 out_false,
3234
+ Predicate pred);
3235
+ template <class ExecutionPolicy, class ForwardIterator, class ForwardIterator1,
3236
+ class ForwardIterator2, class Predicate>
3237
+ pair<ForwardIterator1, ForwardIterator2>
3238
+ partition_copy(ExecutionPolicy&& exec,
3239
+ ForwardIterator first, ForwardIterator last,
3240
+ ForwardIterator1 out_true, ForwardIterator2 out_false,
3241
+ Predicate pred);
3242
+ ```
3243
+
3244
+ *Requires:*
3245
+
3246
+ - For the overload with no `ExecutionPolicy`, `InputIterator`’s value
3247
+ type shall be `CopyAssignable` (Table  [[tab:copyassignable]]), and
3248
+ shall be writable ([[iterator.requirements.general]]) to the
3249
+ `out_true` and `out_false` `OutputIterator`s, and shall be convertible
3250
+ to `Predicate`’s argument type.
3251
+ - For the overload with an `ExecutionPolicy`, `ForwardIterator`’s value
3252
+ type shall be `CopyAssignable`, and shall be writable to the
3253
+ `out_true` and `out_false` `ForwardIterator`s, and shall be
3254
+ convertible to `Predicate`’s argument type. \[*Note 1*: There may be a
3255
+ performance cost if `ForwardIterator`’s value type is not
3256
+ `CopyConstructible`. — *end note*]
3257
+ - For both overloads, the input range shall not overlap with either of
3258
+ the output ranges.
3259
+
3260
+ *Effects:* For each iterator `i` in \[`first`, `last`), copies `*i` to
3261
+ the output range beginning with `out_true` if `pred(*i)` is `true`, or
3262
+ to the output range beginning with `out_false` otherwise.
3263
+
3264
+ *Returns:* A pair `p` such that `p.first` is the end of the output range
3265
+ beginning at `out_true` and `p.second` is the end of the output range
3266
+ beginning at `out_false`.
3267
+
3268
+ *Complexity:* Exactly `last - first` applications of `pred`.
3269
+
3270
+ ``` cpp
3271
+ template<class ForwardIterator, class Predicate>
3272
+ ForwardIterator partition_point(ForwardIterator first,
3273
+ ForwardIterator last,
3274
+ Predicate pred);
3275
+ ```
3276
+
3277
+ *Requires:* `ForwardIterator`’s value type shall be convertible to
3278
+ `Predicate`’s argument type. \[`first`, `last`) shall be partitioned by
3279
+ `pred`, i.e. all elements that satisfy `pred` shall appear before those
3280
+ that do not.
3281
+
3282
+ *Returns:* An iterator `mid` such that `all_of(first, mid, pred)` and
3283
+ `none_of(mid, last, pred)` are both `true`.
3284
+
3285
+ *Complexity:* 𝑂(log(`last - first`)) applications of `pred`.
3286
+
3287
  ### Merge <a id="alg.merge">[[alg.merge]]</a>
3288
 
3289
  ``` cpp
3290
  template<class InputIterator1, class InputIterator2,
3291
  class OutputIterator>
3292
  OutputIterator
3293
  merge(InputIterator1 first1, InputIterator1 last1,
3294
  InputIterator2 first2, InputIterator2 last2,
3295
  OutputIterator result);
3296
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
3297
+ class ForwardIterator>
3298
+ ForwardIterator
3299
+ merge(ExecutionPolicy&& exec,
3300
+ ForwardIterator1 first1, ForwardIterator1 last1,
3301
+ ForwardIterator2 first2, ForwardIterator2 last2,
3302
+ ForwardIterator result);
3303
 
3304
  template<class InputIterator1, class InputIterator2,
3305
  class OutputIterator, class Compare>
3306
  OutputIterator
3307
  merge(InputIterator1 first1, InputIterator1 last1,
3308
  InputIterator2 first2, InputIterator2 last2,
3309
  OutputIterator result, Compare comp);
3310
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
3311
+ class ForwardIterator, class Compare>
3312
+ ForwardIterator
3313
+ merge(ExecutionPolicy&& exec,
3314
+ ForwardIterator1 first1, ForwardIterator1 last1,
3315
+ ForwardIterator2 first2, ForwardIterator2 last2,
3316
+ ForwardIterator result, Compare comp);
3317
  ```
3318
 
3319
+ *Requires:* The ranges \[`first1`, `last1`) and \[`first2`, `last2`)
3320
+ shall be sorted with respect to `operator<` or `comp`. The resulting
3321
+ range shall not overlap with either of the original ranges.
3322
+
3323
  *Effects:*  Copies all the elements of the two ranges \[`first1`,
3324
  `last1`) and \[`first2`, `last2`) into the range \[`result`,
3325
  `result_last`), where `result_last` is
3326
  `result + (last1 - first1) + (last2 - first2)`, such that the resulting
3327
  range satisfies `is_sorted(result, result_last)` or
3328
  `is_sorted(result, result_last, comp)`, respectively.
3329
 
 
 
 
 
3330
  *Returns:* `result + (last1 - first1) + (last2 - first2)`.
3331
 
3332
+ *Complexity:* Let N = `(last1 - first1) + (last2 - first2)`:
3333
+
3334
+ - For the overloads with no `ExecutionPolicy`, at most N - 1
3335
  comparisons.
3336
+ - For the overloads with an `ExecutionPolicy`, 𝑂(N) comparisons.
3337
 
3338
  *Remarks:* Stable ([[algorithm.stable]]).
3339
 
3340
  ``` cpp
3341
  template<class BidirectionalIterator>
3342
  void inplace_merge(BidirectionalIterator first,
3343
  BidirectionalIterator middle,
3344
  BidirectionalIterator last);
3345
+ template<class ExecutionPolicy, class BidirectionalIterator>
3346
+ void inplace_merge(ExecutionPolicy&& exec,
3347
+ BidirectionalIterator first,
3348
+ BidirectionalIterator middle,
3349
+ BidirectionalIterator last);
3350
 
3351
  template<class BidirectionalIterator, class Compare>
3352
  void inplace_merge(BidirectionalIterator first,
3353
  BidirectionalIterator middle,
3354
  BidirectionalIterator last, Compare comp);
3355
+ template<class ExecutionPolicy, class BidirectionalIterator, class Compare>
3356
+ void inplace_merge(ExecutionPolicy&& exec,
3357
+ BidirectionalIterator first,
3358
+ BidirectionalIterator middle,
3359
+ BidirectionalIterator last, Compare comp);
3360
  ```
3361
 
3362
+ *Requires:* The ranges \[`first`, `middle`) and \[`middle`, `last`)
3363
+ shall be sorted with respect to `operator<` or `comp`.
3364
+ `BidirectionalIterator` shall satisfy the requirements of
3365
+ `ValueSwappable` ([[swappable.requirements]]). The type of `*first`
3366
+ shall satisfy the requirements of `MoveConstructible`
3367
+ (Table  [[tab:moveconstructible]]) and of `MoveAssignable`
3368
+ (Table  [[tab:moveassignable]]).
3369
+
3370
  *Effects:* Merges two sorted consecutive ranges \[`first`, `middle`) and
3371
  \[`middle`, `last`), putting the result of the merge into the range
3372
  \[`first`, `last`). The resulting range will be in non-decreasing order;
3373
  that is, for every iterator `i` in \[`first`, `last`) other than
3374
  `first`, the condition `*i < *(i - 1)` or, respectively,
3375
+ `comp(*i, *(i - 1))` will be `false`.
3376
 
3377
+ *Complexity:* Let N = `last - first`:
 
 
 
 
 
 
3378
 
3379
+ - For the overloads with no `ExecutionPolicy`, if enough additional
3380
+ memory is available, exactly N - 1 comparisons.
3381
+ - For the overloads with no `ExecutionPolicy` if no additional memory is
3382
+ available, 𝑂(N log N) comparisons.
3383
+ - For the overloads with an `ExecutionPolicy`, 𝑂(N log N) comparisons.
3384
 
3385
  *Remarks:* Stable ([[algorithm.stable]]).
3386
 
3387
  ### Set operations on sorted structures <a id="alg.set.operations">[[alg.set.operations]]</a>
3388
 
 
3397
 
3398
  ``` cpp
3399
  template<class InputIterator1, class InputIterator2>
3400
  bool includes(InputIterator1 first1, InputIterator1 last1,
3401
  InputIterator2 first2, InputIterator2 last2);
3402
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
3403
+ bool includes(ExecutionPolicy&& exec,
3404
+ ForwardIterator1 first1, ForwardIterator1 last1,
3405
+ ForwardIterator2 first2, ForwardIterator2 last2);
3406
 
3407
  template<class InputIterator1, class InputIterator2, class Compare>
3408
  bool includes(InputIterator1 first1, InputIterator1 last1,
3409
  InputIterator2 first2, InputIterator2 last2,
3410
  Compare comp);
3411
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class Compare>
3412
+ bool includes(ExecutionPolicy&& exec,
3413
+ ForwardIterator1 first1, ForwardIterator1 last1,
3414
+ ForwardIterator2 first2, ForwardIterator2 last2,
3415
+ Compare comp);
3416
  ```
3417
 
3418
  *Returns:* `true` if \[`first2`, `last2`) is empty or if every element
3419
  in the range \[`first2`, `last2`) is contained in the range \[`first1`,
3420
  `last1`). Returns `false` otherwise.
 
3429
  class OutputIterator>
3430
  OutputIterator
3431
  set_union(InputIterator1 first1, InputIterator1 last1,
3432
  InputIterator2 first2, InputIterator2 last2,
3433
  OutputIterator result);
3434
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
3435
+ class ForwardIterator>
3436
+ ForwardIterator
3437
+ set_union(ExecutionPolicy&& exec,
3438
+ ForwardIterator1 first1, ForwardIterator1 last1,
3439
+ ForwardIterator2 first2, ForwardIterator2 last2,
3440
+ ForwardIterator result);
3441
 
3442
  template<class InputIterator1, class InputIterator2,
3443
  class OutputIterator, class Compare>
3444
  OutputIterator
3445
  set_union(InputIterator1 first1, InputIterator1 last1,
3446
  InputIterator2 first2, InputIterator2 last2,
3447
  OutputIterator result, Compare comp);
3448
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
3449
+ class ForwardIterator, class Compare>
3450
+ ForwardIterator
3451
+ set_union(ExecutionPolicy&& exec,
3452
+ ForwardIterator1 first1, ForwardIterator1 last1,
3453
+ ForwardIterator2 first2, ForwardIterator2 last2,
3454
+ ForwardIterator result, Compare comp);
3455
  ```
3456
 
3457
+ *Requires:* The resulting range shall not overlap with either of the
3458
+ original ranges.
3459
+
3460
  *Effects:* Constructs a sorted union of the elements from the two
3461
  ranges; that is, the set of elements that are present in one or both of
3462
  the ranges.
3463
 
 
 
 
3464
  *Returns:* The end of the constructed range.
3465
 
3466
  *Complexity:* At most `2 * ((last1 - first1) + (last2 - first2)) - 1`
3467
  comparisons.
3468
 
 
3480
  class OutputIterator>
3481
  OutputIterator
3482
  set_intersection(InputIterator1 first1, InputIterator1 last1,
3483
  InputIterator2 first2, InputIterator2 last2,
3484
  OutputIterator result);
3485
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
3486
+ class ForwardIterator>
3487
+ ForwardIterator
3488
+ set_intersection(ExecutionPolicy&& exec,
3489
+ ForwardIterator1 first1, ForwardIterator1 last1,
3490
+ ForwardIterator2 first2, ForwardIterator2 last2,
3491
+ ForwardIterator result);
3492
 
3493
  template<class InputIterator1, class InputIterator2,
3494
  class OutputIterator, class Compare>
3495
  OutputIterator
3496
  set_intersection(InputIterator1 first1, InputIterator1 last1,
3497
  InputIterator2 first2, InputIterator2 last2,
3498
  OutputIterator result, Compare comp);
3499
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
3500
+ class ForwardIterator, class Compare>
3501
+ ForwardIterator
3502
+ set_intersection(ExecutionPolicy&& exec,
3503
+ ForwardIterator1 first1, ForwardIterator1 last1,
3504
+ ForwardIterator2 first2, ForwardIterator2 last2,
3505
+ ForwardIterator result, Compare comp);
3506
  ```
3507
 
3508
+ *Requires:* The resulting range shall not overlap with either of the
3509
+ original ranges.
3510
+
3511
  *Effects:* Constructs a sorted intersection of the elements from the two
3512
  ranges; that is, the set of elements that are present in both of the
3513
  ranges.
3514
 
 
 
 
3515
  *Returns:* The end of the constructed range.
3516
 
3517
  *Complexity:* At most `2 * ((last1 - first1) + (last2 - first2)) - 1`
3518
  comparisons.
3519
 
 
3529
  class OutputIterator>
3530
  OutputIterator
3531
  set_difference(InputIterator1 first1, InputIterator1 last1,
3532
  InputIterator2 first2, InputIterator2 last2,
3533
  OutputIterator result);
3534
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
3535
+ class ForwardIterator>
3536
+ ForwardIterator
3537
+ set_difference(ExecutionPolicy&& exec,
3538
+ ForwardIterator1 first1, ForwardIterator1 last1,
3539
+ ForwardIterator2 first2, ForwardIterator2 last2,
3540
+ ForwardIterator result);
3541
 
3542
  template<class InputIterator1, class InputIterator2,
3543
  class OutputIterator, class Compare>
3544
  OutputIterator
3545
  set_difference(InputIterator1 first1, InputIterator1 last1,
3546
  InputIterator2 first2, InputIterator2 last2,
3547
  OutputIterator result, Compare comp);
3548
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
3549
+ class ForwardIterator, class Compare>
3550
+ ForwardIterator
3551
+ set_difference(ExecutionPolicy&& exec,
3552
+ ForwardIterator1 first1, ForwardIterator1 last1,
3553
+ ForwardIterator2 first2, ForwardIterator2 last2,
3554
+ ForwardIterator result, Compare comp);
3555
  ```
3556
 
3557
+ *Requires:* The resulting range shall not overlap with either of the
3558
+ original ranges.
3559
+
3560
  *Effects:* Copies the elements of the range \[`first1`, `last1`) which
3561
  are not present in the range \[`first2`, `last2`) to the range beginning
3562
  at `result`. The elements in the constructed range are sorted.
3563
 
 
 
 
3564
  *Returns:* The end of the constructed range.
3565
 
3566
  *Complexity:* At most `2 * ((last1 - first1) + (last2 - first2)) - 1`
3567
  comparisons.
3568
 
 
3578
  class OutputIterator>
3579
  OutputIterator
3580
  set_symmetric_difference(InputIterator1 first1, InputIterator1 last1,
3581
  InputIterator2 first2, InputIterator2 last2,
3582
  OutputIterator result);
3583
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
3584
+ class ForwardIterator>
3585
+ ForwardIterator
3586
+ set_symmetric_difference(ExecutionPolicy&& exec,
3587
+ ForwardIterator1 first1, ForwardIterator1 last1,
3588
+ ForwardIterator2 first2, ForwardIterator2 last2,
3589
+ ForwardIterator result);
3590
 
3591
  template<class InputIterator1, class InputIterator2,
3592
  class OutputIterator, class Compare>
3593
  OutputIterator
3594
  set_symmetric_difference(InputIterator1 first1, InputIterator1 last1,
3595
  InputIterator2 first2, InputIterator2 last2,
3596
  OutputIterator result, Compare comp);
3597
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
3598
+ class ForwardIterator, class Compare>
3599
+ ForwardIterator
3600
+ set_symmetric_difference(ExecutionPolicy&& exec,
3601
+ ForwardIterator1 first1, ForwardIterator1 last1,
3602
+ ForwardIterator2 first2, ForwardIterator2 last2,
3603
+ ForwardIterator result, Compare comp);
3604
  ```
3605
 
3606
+ *Requires:* The resulting range shall not overlap with either of the
3607
+ original ranges.
3608
+
3609
  *Effects:* Copies the elements of the range \[`first1`, `last1`) that
3610
  are not present in the range \[`first2`, `last2`), and the elements of
3611
  the range \[`first2`, `last2`) that are not present in the range
3612
  \[`first1`, `last1`) to the range beginning at `result`. The elements in
3613
  the constructed range are sorted.
3614
 
 
 
 
3615
  *Returns:* The end of the constructed range.
3616
 
3617
  *Complexity:* At most `2 * ((last1 - first1) + (last2 - first2)) - 1`
3618
  comparisons.
3619
 
 
3625
  \[`first2`, `last2`) if m < n.
3626
 
3627
  ### Heap operations <a id="alg.heap.operations">[[alg.heap.operations]]</a>
3628
 
3629
  A *heap* is a particular organization of elements in a range between two
3630
+ random access iterators \[`a`, `b`) such that:
3631
 
3632
+ - With `N = b - a`, for all i, 0 < i < N,
3633
+ `comp(a[\left \lfloor{\frac{i - 1}{2}}\right \rfloor], a[i])` is
3634
+ `false`.
3635
+ - `*a` may be removed by `pop_heap()`, or a new element added by
3636
+ `push_heap()`, in 𝑂(log N) time.
 
 
 
 
 
 
 
3637
 
3638
  These properties make heaps useful as priority queues.
3639
 
3640
  `make_heap()`
3641
 
 
3651
  template<class RandomAccessIterator, class Compare>
3652
  void push_heap(RandomAccessIterator first, RandomAccessIterator last,
3653
  Compare comp);
3654
  ```
3655
 
 
 
 
3656
  *Requires:* The range \[`first`, `last - 1`) shall be a valid heap. The
3657
  type of `*first` shall satisfy the `MoveConstructible` requirements
3658
+ (Table  [[tab:moveconstructible]]) and the `MoveAssignable` requirements
3659
+ (Table  [[tab:moveassignable]]).
3660
 
3661
+ *Effects:* Places the value in the location `last - 1` into the
3662
+ resulting heap \[`first`, `last`).
3663
+
3664
+ *Complexity:* At most log(`last - first`) comparisons.
3665
 
3666
  #### `pop_heap` <a id="pop.heap">[[pop.heap]]</a>
3667
 
3668
  ``` cpp
3669
  template<class RandomAccessIterator>
 
3676
 
3677
  *Requires:* The range \[`first`, `last`) shall be a valid non-empty
3678
  heap. `RandomAccessIterator` shall satisfy the requirements of
3679
  `ValueSwappable` ([[swappable.requirements]]). The type of `*first`
3680
  shall satisfy the requirements of `MoveConstructible`
3681
+ (Table  [[tab:moveconstructible]]) and of `MoveAssignable`
3682
+ (Table  [[tab:moveassignable]]).
3683
 
3684
  *Effects:* Swaps the value in the location `first` with the value in the
3685
  location `last - 1` and makes \[`first`, `last - 1`) into a heap.
3686
 
3687
+ *Complexity:* At most 2 log(`last - first`) comparisons.
3688
 
3689
  #### `make_heap` <a id="make.heap">[[make.heap]]</a>
3690
 
3691
  ``` cpp
3692
  template<class RandomAccessIterator>
 
3695
  template<class RandomAccessIterator, class Compare>
3696
  void make_heap(RandomAccessIterator first, RandomAccessIterator last,
3697
  Compare comp);
3698
  ```
3699
 
 
 
3700
  *Requires:* The type of `*first` shall satisfy the `MoveConstructible`
3701
+ requirements (Table  [[tab:moveconstructible]]) and the `MoveAssignable`
3702
+ requirements (Table  [[tab:moveassignable]]).
3703
 
3704
+ *Effects:* Constructs a heap out of the range \[`first`, `last`).
3705
+
3706
+ *Complexity:* At most 3(`last - first`) comparisons.
3707
 
3708
  #### `sort_heap` <a id="sort.heap">[[sort.heap]]</a>
3709
 
3710
  ``` cpp
3711
  template<class RandomAccessIterator>
 
3714
  template<class RandomAccessIterator, class Compare>
3715
  void sort_heap(RandomAccessIterator first, RandomAccessIterator last,
3716
  Compare comp);
3717
  ```
3718
 
 
 
3719
  *Requires:* The range \[`first`, `last`) shall be a valid heap.
3720
  `RandomAccessIterator` shall satisfy the requirements of
3721
  `ValueSwappable` ([[swappable.requirements]]). The type of `*first`
3722
  shall satisfy the requirements of `MoveConstructible`
3723
+ (Table  [[tab:moveconstructible]]) and of `MoveAssignable`
3724
+ (Table  [[tab:moveassignable]]).
3725
 
3726
+ *Effects:* Sorts elements in the heap \[`first`, `last`).
3727
+
3728
+ *Complexity:* At most N log N comparisons, where N = `last - first`.
3729
 
3730
  #### `is_heap` <a id="is.heap">[[is.heap]]</a>
3731
 
3732
  ``` cpp
3733
  template<class RandomAccessIterator>
3734
  bool is_heap(RandomAccessIterator first, RandomAccessIterator last);
3735
  ```
3736
 
3737
  *Returns:* `is_heap_until(first, last) == last`
3738
 
3739
+ ``` cpp
3740
+ template<class ExecutionPolicy, class RandomAccessIterator>
3741
+ bool is_heap(ExecutionPolicy&& exec,
3742
+ RandomAccessIterator first, RandomAccessIterator last);
3743
+ ```
3744
+
3745
+ *Returns:*
3746
+ `is_heap_until(std::forward<ExecutionPolicy>(exec), first, last) == last`
3747
+
3748
  ``` cpp
3749
  template<class RandomAccessIterator, class Compare>
3750
  bool is_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
3751
  ```
3752
 
3753
  *Returns:* `is_heap_until(first, last, comp) == last`
3754
 
3755
+ ``` cpp
3756
+ template<class ExecutionPolicy, class RandomAccessIterator, class Compare>
3757
+ bool is_heap(ExecutionPolicy&& exec,
3758
+ RandomAccessIterator first, RandomAccessIterator last, Compare comp);
3759
+ ```
3760
+
3761
+ *Returns:*
3762
+
3763
+ ``` cpp
3764
+ is_heap_until(std::forward<ExecutionPolicy>(exec), first, last, comp) == last
3765
+ ```
3766
+
3767
  ``` cpp
3768
  template<class RandomAccessIterator>
3769
  RandomAccessIterator is_heap_until(RandomAccessIterator first, RandomAccessIterator last);
3770
+ template<class ExecutionPolicy, class RandomAccessIterator>
3771
+ RandomAccessIterator is_heap_until(ExecutionPolicy&& exec,
3772
+ RandomAccessIterator first, RandomAccessIterator last);
3773
+
3774
  template<class RandomAccessIterator, class Compare>
3775
  RandomAccessIterator is_heap_until(RandomAccessIterator first, RandomAccessIterator last,
3776
  Compare comp);
3777
+ template<class ExecutionPolicy, class RandomAccessIterator, class Compare>
3778
+ RandomAccessIterator is_heap_until(ExecutionPolicy&& exec,
3779
+ RandomAccessIterator first, RandomAccessIterator last,
3780
+ Compare comp);
3781
  ```
3782
 
3783
+ *Returns:* If `(last - first) < 2`, returns `last`. Otherwise, returns
3784
+ the last iterator `i` in \[`first`, `last`\] for which the range
3785
  \[`first`, `i`) is a heap.
3786
 
3787
  *Complexity:* Linear.
3788
 
3789
  ### Minimum and maximum <a id="alg.min.max">[[alg.min.max]]</a>
 
3792
  template<class T> constexpr const T& min(const T& a, const T& b);
3793
  template<class T, class Compare>
3794
  constexpr const T& min(const T& a, const T& b, Compare comp);
3795
  ```
3796
 
3797
+ *Requires:* For the first form, type `T` shall be `LessThanComparable`
3798
+ (Table  [[tab:lessthancomparable]]).
3799
 
3800
  *Returns:* The smaller value.
3801
 
3802
  *Remarks:* Returns the first argument when the arguments are equivalent.
3803
 
3804
+ *Complexity:* Exactly one comparison.
3805
+
3806
  ``` cpp
3807
  template<class T>
3808
  constexpr T min(initializer_list<T> t);
3809
  template<class T, class Compare>
3810
  constexpr T min(initializer_list<T> t, Compare comp);
3811
  ```
3812
 
3813
+ *Requires:* `T` shall be `CopyConstructible` and `t.size() > 0`. For the
3814
+ first form, type `T` shall be `LessThanComparable`.
3815
 
3816
  *Returns:* The smallest value in the initializer_list.
3817
 
3818
  *Remarks:* Returns a copy of the leftmost argument when several
3819
  arguments are equivalent to the smallest. 
3820
 
3821
+ *Complexity:* Exactly `t.size() - 1` comparisons.
3822
+
3823
  ``` cpp
3824
  template<class T> constexpr const T& max(const T& a, const T& b);
3825
  template<class T, class Compare>
3826
  constexpr const T& max(const T& a, const T& b, Compare comp);
3827
  ```
3828
 
3829
+ *Requires:* For the first form, type `T` shall be `LessThanComparable`
3830
+ (Table  [[tab:lessthancomparable]]).
3831
 
3832
  *Returns:* The larger value.
3833
 
3834
  *Remarks:* Returns the first argument when the arguments are equivalent.
3835
 
3836
+ *Complexity:* Exactly one comparison.
3837
+
3838
  ``` cpp
3839
  template<class T>
3840
  constexpr T max(initializer_list<T> t);
3841
  template<class T, class Compare>
3842
  constexpr T max(initializer_list<T> t, Compare comp);
3843
  ```
3844
 
3845
+ *Requires:* `T` shall be `CopyConstructible` and `t.size() > 0`. For the
3846
+ first form, type `T` shall be `LessThanComparable`.
3847
 
3848
  *Returns:* The largest value in the initializer_list.
3849
 
3850
  *Remarks:* Returns a copy of the leftmost argument when several
3851
  arguments are equivalent to the largest.
3852
 
3853
+ *Complexity:* Exactly `t.size() - 1` comparisons.
3854
+
3855
  ``` cpp
3856
  template<class T> constexpr pair<const T&, const T&> minmax(const T& a, const T& b);
3857
  template<class T, class Compare>
3858
  constexpr pair<const T&, const T&> minmax(const T& a, const T& b, Compare comp);
3859
  ```
3860
 
3861
+ *Requires:* For the first form, type `T` shall be `LessThanComparable`
3862
+ (Table  [[tab:lessthancomparable]]).
3863
 
3864
  *Returns:* `pair<const T&, const T&>(b, a)` if `b` is smaller than `a`,
3865
  and `pair<const T&, const T&>(a, b)` otherwise.
3866
 
3867
  *Remarks:* Returns `pair<const T&, const T&>(a, b)` when the arguments
 
3874
  constexpr pair<T, T> minmax(initializer_list<T> t);
3875
  template<class T, class Compare>
3876
  constexpr pair<T, T> minmax(initializer_list<T> t, Compare comp);
3877
  ```
3878
 
3879
+ *Requires:* `T` shall be `CopyConstructible` and `t.size() > 0`. For the
3880
+ first form, type `T` shall be `LessThanComparable`.
3881
 
3882
  *Returns:* `pair<T, T>(x, y)`, where `x` has the smallest and `y` has
3883
  the largest value in the initializer list.
3884
 
3885
  *Remarks:* `x` is a copy of the leftmost argument when several arguments
3886
  are equivalent to the smallest. `y` is a copy of the rightmost argument
3887
  when several arguments are equivalent to the largest.
3888
 
3889
+ *Complexity:* At most (3/2)`t.size()` applications of the corresponding
3890
+ predicate.
3891
 
3892
  ``` cpp
3893
  template<class ForwardIterator>
3894
+ constexpr ForwardIterator min_element(ForwardIterator first, ForwardIterator last);
3895
+
3896
+ template<class ExecutionPolicy, class ForwardIterator>
3897
+ ForwardIterator min_element(ExecutionPolicy&& exec,
3898
+ ForwardIterator first, ForwardIterator last);
3899
 
3900
  template<class ForwardIterator, class Compare>
3901
+ constexpr ForwardIterator min_element(ForwardIterator first, ForwardIterator last,
3902
+ Compare comp);
3903
+ template<class ExecutionPolicy, class ForwardIterator, class Compare>
3904
+ ForwardIterator min_element(ExecutionPolicy&& exec,
3905
+ ForwardIterator first, ForwardIterator last,
3906
  Compare comp);
3907
  ```
3908
 
3909
  *Returns:* The first iterator `i` in the range \[`first`, `last`) such
3910
  that for every iterator `j` in the range \[`first`, `last`) the
3911
  following corresponding conditions hold: `!(*j < *i)` or
3912
  `comp(*j, *i) == false`. Returns `last` if `first == last`.
3913
 
3914
+ *Complexity:* Exactly max(`last - first - 1`, 0) applications of the
3915
  corresponding comparisons.
3916
 
3917
  ``` cpp
3918
  template<class ForwardIterator>
3919
+ constexpr ForwardIterator max_element(ForwardIterator first, ForwardIterator last);
3920
+ template<class ExecutionPolicy, class ForwardIterator>
3921
+ ForwardIterator max_element(ExecutionPolicy&& exec,
3922
+ ForwardIterator first, ForwardIterator last);
3923
+
3924
  template<class ForwardIterator, class Compare>
3925
+ constexpr ForwardIterator max_element(ForwardIterator first, ForwardIterator last,
3926
+ Compare comp);
3927
+ template<class ExecutionPolicy, class ForwardIterator, class Compare>
3928
+ ForwardIterator max_element(ExecutionPolicy&& exec,
3929
+ ForwardIterator first, ForwardIterator last,
3930
  Compare comp);
3931
  ```
3932
 
3933
  *Returns:* The first iterator `i` in the range \[`first`, `last`) such
3934
  that for every iterator `j` in the range \[`first`, `last`) the
3935
  following corresponding conditions hold: `!(*i < *j)` or
3936
  `comp(*i, *j) == false`. Returns `last` if `first == last`.
3937
 
3938
+ *Complexity:* Exactly max(`last - first - 1`, 0) applications of the
3939
  corresponding comparisons.
3940
 
3941
  ``` cpp
3942
  template<class ForwardIterator>
3943
+ constexpr pair<ForwardIterator, ForwardIterator>
3944
  minmax_element(ForwardIterator first, ForwardIterator last);
3945
+ template<class ExecutionPolicy, class ForwardIterator>
3946
+ pair<ForwardIterator, ForwardIterator>
3947
+ minmax_element(ExecutionPolicy&& exec,
3948
+ ForwardIterator first, ForwardIterator last);
3949
+
3950
  template<class ForwardIterator, class Compare>
3951
+ constexpr pair<ForwardIterator, ForwardIterator>
3952
  minmax_element(ForwardIterator first, ForwardIterator last, Compare comp);
3953
+ template<class ExecutionPolicy, class ForwardIterator, class Compare>
3954
+ pair<ForwardIterator, ForwardIterator>
3955
+ minmax_element(ExecutionPolicy&& exec,
3956
+ ForwardIterator first, ForwardIterator last, Compare comp);
3957
  ```
3958
 
3959
  *Returns:* `make_pair(first, first)` if \[`first`, `last`) is empty,
3960
  otherwise `make_pair(m, M)`, where `m` is the first iterator in
3961
  \[`first`, `last`) such that no iterator in the range refers to a
3962
+ smaller element, and where `M` is the last iterator[^5] in \[`first`,
3963
  `last`) such that no iterator in the range refers to a larger element.
3964
 
3965
+ *Complexity:* At most
3966
+ $\max(\bigl\lfloor{\frac{3}{2}} (N-1)\bigr\rfloor, 0)$ applications of
3967
+ the corresponding predicate, where N is `last - first`.
3968
+
3969
+ ### Bounded value <a id="alg.clamp">[[alg.clamp]]</a>
3970
+
3971
+ ``` cpp
3972
+ template<class T>
3973
+ constexpr const T& clamp(const T& v, const T& lo, const T& hi);
3974
+ template<class T, class Compare>
3975
+ constexpr const T& clamp(const T& v, const T& lo, const T& hi, Compare comp);
3976
+ ```
3977
+
3978
+ *Requires:* The value of `lo` shall be no greater than `hi`. For the
3979
+ first form, type `T` shall be `LessThanComparable`
3980
+ (Table  [[tab:lessthancomparable]]).
3981
+
3982
+ *Returns:* `lo` if `v` is less than `lo`, `hi` if `hi` is less than `v`,
3983
+ otherwise `v`.
3984
+
3985
+ [*Note 1*: If NaN is avoided, `T` can be a floating-point
3986
+ type. — *end note*]
3987
+
3988
+ *Complexity:* At most two comparisons.
3989
 
3990
  ### Lexicographical comparison <a id="alg.lex.comparison">[[alg.lex.comparison]]</a>
3991
 
3992
  ``` cpp
3993
  template<class InputIterator1, class InputIterator2>
3994
  bool
3995
  lexicographical_compare(InputIterator1 first1, InputIterator1 last1,
3996
  InputIterator2 first2, InputIterator2 last2);
3997
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
3998
+ bool
3999
+ lexicographical_compare(ExecutionPolicy&& exec,
4000
+ ForwardIterator1 first1, ForwardIterator1 last1,
4001
+ ForwardIterator2 first2, ForwardIterator2 last2);
4002
 
4003
  template<class InputIterator1, class InputIterator2, class Compare>
4004
  bool
4005
  lexicographical_compare(InputIterator1 first1, InputIterator1 last1,
4006
  InputIterator2 first2, InputIterator2 last2,
4007
  Compare comp);
4008
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class Compare>
4009
+ bool
4010
+ lexicographical_compare(ExecutionPolicy&& exec,
4011
+ ForwardIterator1 first1, ForwardIterator1 last1,
4012
+ ForwardIterator2 first2, ForwardIterator2 last2,
4013
+ Compare comp);
4014
  ```
4015
 
4016
  *Returns:* `true` if the sequence of elements defined by the range
4017
  \[`first1`, `last1`) is lexicographically less than the sequence of
4018
  elements defined by the range \[`first2`, `last2`) and `false`
4019
  otherwise.
4020
 
4021
+ *Complexity:* At most 2 min(`last1 - first1`, `last2 - first2`)
4022
  applications of the corresponding comparison.
4023
 
4024
  *Remarks:* If two sequences have the same number of elements and their
4025
+ corresponding elements (if any) are equivalent, then neither sequence is
4026
  lexicographically less than the other. If one sequence is a prefix of
4027
  the other, then the shorter sequence is lexicographically less than the
4028
  longer sequence. Otherwise, the lexicographical comparison of the
4029
  sequences yields the same result as the comparison of the first
4030
  corresponding pair of elements that are not equivalent.
4031
 
4032
+ [*Example 1*:
4033
+
4034
+ The following sample implementation satisfies these requirements:
4035
+
4036
  ``` cpp
4037
+ for ( ; first1 != last1 && first2 != last2 ; ++first1, (void) ++first2) {
4038
  if (*first1 < *first2) return true;
4039
  if (*first2 < *first1) return false;
4040
  }
4041
  return first1 == last1 && first2 != last2;
4042
  ```
4043
 
4044
+ *end example*]
4045
+
4046
+ [*Note 1*: An empty sequence is lexicographically less than any
4047
+ non-empty sequence, but not less than any empty sequence. — *end note*]
4048
 
4049
  ### Permutation generators <a id="alg.permutation.generators">[[alg.permutation.generators]]</a>
4050
 
4051
  ``` cpp
4052
  template<class BidirectionalIterator>
 
4056
  template<class BidirectionalIterator, class Compare>
4057
  bool next_permutation(BidirectionalIterator first,
4058
  BidirectionalIterator last, Compare comp);
4059
  ```
4060
 
4061
+ *Requires:* `BidirectionalIterator` shall satisfy the requirements of
4062
+ `ValueSwappable` ([[swappable.requirements]]).
4063
+
4064
  *Effects:* Takes a sequence defined by the range \[`first`, `last`) and
4065
  transforms it into the next permutation. The next permutation is found
4066
  by assuming that the set of all permutations is lexicographically sorted
4067
+ with respect to `operator<` or `comp`.
 
 
4068
 
4069
+ *Returns:* `true` if such a permutation exists. Otherwise, it transforms
4070
+ the sequence into the smallest permutation, that is, the ascendingly
4071
+ sorted one, and returns `false`.
4072
 
4073
  *Complexity:* At most `(last - first) / 2` swaps.
4074
 
4075
  ``` cpp
4076
  template<class BidirectionalIterator>
 
4080
  template<class BidirectionalIterator, class Compare>
4081
  bool prev_permutation(BidirectionalIterator first,
4082
  BidirectionalIterator last, Compare comp);
4083
  ```
4084
 
4085
+ *Requires:* `BidirectionalIterator` shall satisfy the requirements of
4086
+ `ValueSwappable` ([[swappable.requirements]]).
4087
+
4088
  *Effects:* Takes a sequence defined by the range \[`first`, `last`) and
4089
  transforms it into the previous permutation. The previous permutation is
4090
  found by assuming that the set of all permutations is lexicographically
4091
  sorted with respect to `operator<` or `comp`.
4092
 
4093
  *Returns:* `true` if such a permutation exists. Otherwise, it transforms
4094
  the sequence into the largest permutation, that is, the descendingly
4095
  sorted one, and returns `false`.
4096
 
 
 
 
4097
  *Complexity:* At most `(last - first) / 2` swaps.
4098
 
4099
  ## C library algorithms <a id="alg.c.library">[[alg.c.library]]</a>
4100
 
4101
+ [*Note 1*: The header `<cstdlib>` ([[cstdlib.syn]]) declares the
4102
+ functions described in this subclause. — *end note*]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4103
 
4104
  ``` cpp
4105
+ void* bsearch(const void* key, const void* base, size_t nmemb, size_t size,
4106
+ c-compare-pred* compar);
4107
+ void* bsearch(const void* key, const void* base, size_t nmemb, size_t size,
4108
+ compare-pred* compar);
4109
+ void qsort(void* base, size_t nmemb, size_t size, c-compare-pred* compar);
4110
+ void qsort(void* base, size_t nmemb, size_t size, compare-pred* compar);
4111
  ```
4112
 
4113
+ *Effects:* These functions have the semantics specified in the C
4114
+ standard library.
 
 
 
 
 
 
4115
 
4116
+ *Remarks:* The behavior is undefined unless the objects in the array
4117
+ pointed to by `base` are of trivial type.
 
4118
 
4119
+ *Throws:* Any exception thrown by
4120
+ `compar()` ([[res.on.exception.handling]]).
 
4121
 
4122
+ ISO C 7.22.5.
4123
 
4124
  <!-- Link reference definitions -->
4125
  [alg.adjacent.find]: #alg.adjacent.find
4126
  [alg.all_of]: #alg.all_of
4127
  [alg.any_of]: #alg.any_of
4128
  [alg.binary.search]: #alg.binary.search
4129
  [alg.c.library]: #alg.c.library
4130
+ [alg.clamp]: #alg.clamp
4131
  [alg.copy]: #alg.copy
4132
  [alg.count]: #alg.count
4133
  [alg.equal]: #alg.equal
4134
  [alg.fill]: #alg.fill
4135
  [alg.find]: #alg.find
 
4147
  [alg.none_of]: #alg.none_of
4148
  [alg.nonmodifying]: #alg.nonmodifying
4149
  [alg.nth.element]: #alg.nth.element
4150
  [alg.partitions]: #alg.partitions
4151
  [alg.permutation.generators]: #alg.permutation.generators
4152
+ [alg.random.sample]: #alg.random.sample
4153
  [alg.random.shuffle]: #alg.random.shuffle
4154
  [alg.remove]: #alg.remove
4155
  [alg.replace]: #alg.replace
4156
  [alg.reverse]: #alg.reverse
4157
  [alg.rotate]: #alg.rotate
 
4161
  [alg.sorting]: #alg.sorting
4162
  [alg.swap]: #alg.swap
4163
  [alg.transform]: #alg.transform
4164
  [alg.unique]: #alg.unique
4165
  [algorithm.stable]: library.md#algorithm.stable
4166
+ [algorithm.syn]: #algorithm.syn
4167
  [algorithms]: #algorithms
4168
  [algorithms.general]: #algorithms.general
4169
+ [algorithms.parallel]: #algorithms.parallel
4170
+ [algorithms.parallel.defns]: #algorithms.parallel.defns
4171
+ [algorithms.parallel.exceptions]: #algorithms.parallel.exceptions
4172
+ [algorithms.parallel.exec]: #algorithms.parallel.exec
4173
+ [algorithms.parallel.overloads]: #algorithms.parallel.overloads
4174
+ [algorithms.parallel.user]: #algorithms.parallel.user
4175
+ [algorithms.requirements]: #algorithms.requirements
4176
  [bidirectional.iterators]: iterators.md#bidirectional.iterators
4177
  [binary.search]: #binary.search
4178
  [class.conv]: special.md#class.conv
4179
  [containers]: containers.md#containers
4180
  [conv]: conv.md#conv
4181
  [conv.integral]: conv.md#conv.integral
4182
+ [cstdlib.syn]: language.md#cstdlib.syn
 
4183
  [equal.range]: #equal.range
4184
+ [execpol]: utilities.md#execpol
4185
  [forward.iterators]: iterators.md#forward.iterators
4186
  [function.objects]: utilities.md#function.objects
4187
  [includes]: #includes
4188
  [input.iterators]: iterators.md#input.iterators
4189
+ [intro.execution]: intro.md#intro.execution
4190
+ [intro.progress]: intro.md#intro.progress
4191
  [is.heap]: #is.heap
4192
  [is.sorted]: #is.sorted
4193
  [iterator.requirements]: iterators.md#iterator.requirements
4194
+ [iterator.requirements.general]: iterators.md#iterator.requirements.general
4195
  [lower.bound]: #lower.bound
4196
  [make.heap]: #make.heap
4197
  [mismatch]: #mismatch
 
 
4198
  [multiset]: containers.md#multiset
4199
  [output.iterators]: iterators.md#output.iterators
4200
  [partial.sort]: #partial.sort
4201
  [partial.sort.copy]: #partial.sort.copy
4202
  [pop.heap]: #pop.heap
 
4211
  [set.union]: #set.union
4212
  [sort]: #sort
4213
  [sort.heap]: #sort.heap
4214
  [stable.sort]: #stable.sort
4215
  [swappable.requirements]: library.md#swappable.requirements
 
4216
  [tab:algorithms.summary]: #tab:algorithms.summary
4217
+ [tab:copyassignable]: #tab:copyassignable
4218
+ [tab:copyconstructible]: #tab:copyconstructible
4219
+ [tab:lessthancomparable]: #tab:lessthancomparable
4220
+ [tab:moveassignable]: #tab:moveassignable
4221
+ [tab:moveconstructible]: #tab:moveconstructible
4222
+ [thread.thread.class]: thread.md#thread.thread.class
4223
  [upper.bound]: #upper.bound
4224
 
4225
  [^1]: The decision whether to include a copying version was usually
4226
  based on complexity considerations. When the cost of doing the
4227
  operation dominates the cost of copy, the copying version is not
 
4234
 
4235
  [^3]: `move_backward` should be used instead of move when last is in the
4236
  range \[`result - (last - first)`, `result`).
4237
 
4238
  [^4]: The use of fully closed ranges is intentional.
4239
+
4240
+ [^5]: This behavior intentionally differs from `max_element()`.