- tmp/tmpl4g22fvv/{from.md → to.md} +754 -245
tmp/tmpl4g22fvv/{from.md → to.md}
RENAMED
|
@@ -2,34 +2,46 @@
|
|
| 2 |
|
| 3 |
### Copy <a id="alg.copy">[[alg.copy]]</a>
|
| 4 |
|
| 5 |
``` cpp
|
| 6 |
template<class InputIterator, class OutputIterator>
|
| 7 |
-
OutputIterator copy(InputIterator first, InputIterator last,
|
| 8 |
OutputIterator result);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
```
|
| 10 |
|
| 11 |
-
|
|
|
|
|
|
|
| 12 |
|
| 13 |
*Effects:* Copies elements in the range \[`first`, `last`) into the
|
| 14 |
-
range \[`result`, `result +
|
| 15 |
-
|
| 16 |
-
`
|
| 17 |
|
| 18 |
-
*Returns:*
|
| 19 |
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
``` cpp
|
| 23 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 24 |
ForwardIterator2 copy(ExecutionPolicy&& policy,
|
| 25 |
ForwardIterator1 first, ForwardIterator1 last,
|
| 26 |
ForwardIterator2 result);
|
| 27 |
```
|
| 28 |
|
| 29 |
-
*
|
| 30 |
-
`result + (last - first)`)
|
| 31 |
|
| 32 |
*Effects:* Copies elements in the range \[`first`, `last`) into the
|
| 33 |
range \[`result`, `result + (last - first)`). For each non-negative
|
| 34 |
integer `n < (last - first)`, performs `*(result + n) = *(first + n)`.
|
| 35 |
|
|
@@ -37,247 +49,436 @@ integer `n < (last - first)`, performs `*(result + n) = *(first + n)`.
|
|
| 37 |
|
| 38 |
*Complexity:* Exactly `last - first` assignments.
|
| 39 |
|
| 40 |
``` cpp
|
| 41 |
template<class InputIterator, class Size, class OutputIterator>
|
| 42 |
-
OutputIterator copy_n(InputIterator first, Size n,
|
| 43 |
OutputIterator result);
|
| 44 |
template<class ExecutionPolicy, class ForwardIterator1, class Size, class ForwardIterator2>
|
| 45 |
ForwardIterator2 copy_n(ExecutionPolicy&& exec,
|
| 46 |
ForwardIterator1 first, Size n,
|
| 47 |
ForwardIterator2 result);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
```
|
| 49 |
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
`*(result + i) = *(first + i)`.
|
| 52 |
|
| 53 |
-
*Returns:*
|
| 54 |
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
``` cpp
|
| 58 |
template<class InputIterator, class OutputIterator, class Predicate>
|
| 59 |
-
OutputIterator copy_if(InputIterator first, InputIterator last,
|
| 60 |
OutputIterator result, Predicate pred);
|
| 61 |
-
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
|
|
|
| 62 |
ForwardIterator2 copy_if(ExecutionPolicy&& exec,
|
| 63 |
ForwardIterator1 first, ForwardIterator1 last,
|
| 64 |
ForwardIterator2 result, Predicate pred);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
```
|
| 66 |
|
| 67 |
-
|
| 68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
[*Note 1*: For the overload with an `ExecutionPolicy`, there may be a
|
| 71 |
performance cost if `iterator_traits<ForwardIterator1>::value_type` is
|
| 72 |
-
not
|
| 73 |
-
(
|
| 74 |
|
| 75 |
*Effects:* Copies all of the elements referred to by the iterator `i` in
|
| 76 |
-
the range \[`first`, `last`) for which
|
| 77 |
|
| 78 |
-
*Returns:*
|
|
|
|
|
|
|
|
|
|
| 79 |
|
| 80 |
*Complexity:* Exactly `last - first` applications of the corresponding
|
| 81 |
-
predicate.
|
| 82 |
|
| 83 |
-
*Remarks:* Stable
|
| 84 |
|
| 85 |
``` cpp
|
| 86 |
template<class BidirectionalIterator1, class BidirectionalIterator2>
|
| 87 |
-
BidirectionalIterator2
|
| 88 |
copy_backward(BidirectionalIterator1 first,
|
| 89 |
BidirectionalIterator1 last,
|
| 90 |
BidirectionalIterator2 result);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
```
|
| 92 |
|
| 93 |
-
|
|
|
|
|
|
|
| 94 |
|
| 95 |
*Effects:* Copies elements in the range \[`first`, `last`) into the
|
| 96 |
-
range \[`result -
|
| 97 |
-
|
| 98 |
-
`
|
| 99 |
|
| 100 |
-
*Returns:*
|
| 101 |
|
| 102 |
-
|
|
|
|
|
|
|
|
|
|
| 103 |
|
| 104 |
### Move <a id="alg.move">[[alg.move]]</a>
|
| 105 |
|
| 106 |
``` cpp
|
| 107 |
template<class InputIterator, class OutputIterator>
|
| 108 |
-
OutputIterator move(InputIterator first, InputIterator last,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
```
|
| 110 |
|
| 111 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
|
| 113 |
*Effects:* Moves elements in the range \[`first`, `last`) into the range
|
| 114 |
-
\[`result`, `result +
|
| 115 |
-
|
| 116 |
-
|
| 117 |
|
| 118 |
-
*Returns:*
|
| 119 |
|
| 120 |
-
|
|
|
|
|
|
|
|
|
|
| 121 |
|
| 122 |
``` cpp
|
| 123 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 124 |
ForwardIterator2 move(ExecutionPolicy&& policy,
|
| 125 |
ForwardIterator1 first, ForwardIterator1 last,
|
| 126 |
ForwardIterator2 result);
|
| 127 |
```
|
| 128 |
|
| 129 |
-
|
| 130 |
-
|
|
|
|
|
|
|
| 131 |
|
| 132 |
*Effects:* Moves elements in the range \[`first`, `last`) into the range
|
| 133 |
-
\[`result`, `result +
|
| 134 |
-
`n
|
| 135 |
-
`*(result + n) = std::move(*(first + n))`.
|
| 136 |
|
| 137 |
-
*Returns:* `result +
|
| 138 |
|
| 139 |
-
*Complexity:* Exactly
|
| 140 |
|
| 141 |
``` cpp
|
| 142 |
template<class BidirectionalIterator1, class BidirectionalIterator2>
|
| 143 |
-
BidirectionalIterator2
|
| 144 |
-
move_backward(BidirectionalIterator1 first,
|
| 145 |
-
BidirectionalIterator1 last,
|
| 146 |
BidirectionalIterator2 result);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
```
|
| 148 |
|
| 149 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
|
| 151 |
*Effects:* Moves elements in the range \[`first`, `last`) into the range
|
| 152 |
-
\[`result -
|
| 153 |
-
|
| 154 |
-
`
|
| 155 |
-
`*(result - n) = std::move(*(last - n))`.
|
| 156 |
|
| 157 |
-
*Returns:*
|
| 158 |
|
| 159 |
-
|
|
|
|
|
|
|
|
|
|
| 160 |
|
| 161 |
### Swap <a id="alg.swap">[[alg.swap]]</a>
|
| 162 |
|
| 163 |
``` cpp
|
| 164 |
template<class ForwardIterator1, class ForwardIterator2>
|
| 165 |
-
ForwardIterator2
|
| 166 |
swap_ranges(ForwardIterator1 first1, ForwardIterator1 last1,
|
| 167 |
ForwardIterator2 first2);
|
| 168 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 169 |
ForwardIterator2
|
| 170 |
swap_ranges(ExecutionPolicy&& exec,
|
| 171 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 172 |
ForwardIterator2 first2);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
```
|
| 174 |
|
| 175 |
-
|
| 176 |
-
`first2 + (last1 - first1)`) shall not overlap. `*(first1 + n)` shall be
|
| 177 |
-
swappable with ([[swappable.requirements]]) `*(first2 + n)`.
|
| 178 |
|
| 179 |
-
|
| 180 |
-
|
|
|
|
| 181 |
|
| 182 |
-
*
|
|
|
|
|
|
|
|
|
|
| 183 |
|
| 184 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 185 |
|
| 186 |
``` cpp
|
| 187 |
template<class ForwardIterator1, class ForwardIterator2>
|
| 188 |
-
void iter_swap(ForwardIterator1 a, ForwardIterator2 b);
|
| 189 |
```
|
| 190 |
|
| 191 |
-
*
|
| 192 |
-
|
| 193 |
|
| 194 |
*Effects:* As if by `swap(*a, *b)`.
|
| 195 |
|
| 196 |
### Transform <a id="alg.transform">[[alg.transform]]</a>
|
| 197 |
|
| 198 |
``` cpp
|
| 199 |
template<class InputIterator, class OutputIterator,
|
| 200 |
class UnaryOperation>
|
| 201 |
-
OutputIterator
|
| 202 |
-
transform(InputIterator
|
| 203 |
OutputIterator result, UnaryOperation op);
|
| 204 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 205 |
class UnaryOperation>
|
| 206 |
ForwardIterator2
|
| 207 |
transform(ExecutionPolicy&& exec,
|
| 208 |
-
ForwardIterator1
|
| 209 |
ForwardIterator2 result, UnaryOperation op);
|
| 210 |
|
| 211 |
template<class InputIterator1, class InputIterator2,
|
| 212 |
class OutputIterator, class BinaryOperation>
|
| 213 |
-
OutputIterator
|
| 214 |
transform(InputIterator1 first1, InputIterator1 last1,
|
| 215 |
InputIterator2 first2, OutputIterator result,
|
| 216 |
BinaryOperation binary_op);
|
| 217 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 218 |
class ForwardIterator, class BinaryOperation>
|
| 219 |
ForwardIterator
|
| 220 |
transform(ExecutionPolicy&& exec,
|
| 221 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 222 |
ForwardIterator2 first2, ForwardIterator result,
|
| 223 |
BinaryOperation binary_op);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 224 |
```
|
| 225 |
|
| 226 |
-
|
| 227 |
-
subranges, or modify elements in the ranges
|
| 228 |
|
| 229 |
-
-
|
| 230 |
-
|
| 231 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 232 |
|
| 233 |
*Effects:* Assigns through every iterator `i` in the range \[`result`,
|
| 234 |
-
`result +
|
| 235 |
-
`op(*(first1 + (i - result)))` or
|
| 236 |
-
`binary_op(*(first1 + (i - result)), *(first2 + (i - result)))`.
|
| 237 |
|
| 238 |
-
*Returns:*
|
| 239 |
|
| 240 |
-
|
| 241 |
-
`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 242 |
`ExecutionPolicy`.
|
| 243 |
|
| 244 |
-
*Remarks:* `result` may be equal to `
|
| 245 |
-
or to `first1` or `first2` in case of binary transform.
|
| 246 |
|
| 247 |
### Replace <a id="alg.replace">[[alg.replace]]</a>
|
| 248 |
|
| 249 |
``` cpp
|
| 250 |
template<class ForwardIterator, class T>
|
| 251 |
-
void replace(ForwardIterator first, ForwardIterator last,
|
| 252 |
const T& old_value, const T& new_value);
|
| 253 |
template<class ExecutionPolicy, class ForwardIterator, class T>
|
| 254 |
void replace(ExecutionPolicy&& exec,
|
| 255 |
ForwardIterator first, ForwardIterator last,
|
| 256 |
const T& old_value, const T& new_value);
|
| 257 |
|
| 258 |
template<class ForwardIterator, class Predicate, class T>
|
| 259 |
-
void replace_if(ForwardIterator first, ForwardIterator last,
|
| 260 |
Predicate pred, const T& new_value);
|
| 261 |
template<class ExecutionPolicy, class ForwardIterator, class Predicate, class T>
|
| 262 |
void replace_if(ExecutionPolicy&& exec,
|
| 263 |
ForwardIterator first, ForwardIterator last,
|
| 264 |
Predicate pred, const T& new_value);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 265 |
```
|
| 266 |
|
| 267 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 268 |
|
| 269 |
*Effects:* Substitutes elements referred by the iterator `i` in the
|
| 270 |
-
range \[`first`, `last`) with `new_value`, when
|
| 271 |
-
|
|
|
|
| 272 |
|
| 273 |
*Complexity:* Exactly `last - first` applications of the corresponding
|
| 274 |
-
predicate.
|
| 275 |
|
| 276 |
``` cpp
|
| 277 |
template<class InputIterator, class OutputIterator, class T>
|
| 278 |
-
OutputIterator
|
| 279 |
replace_copy(InputIterator first, InputIterator last,
|
| 280 |
OutputIterator result,
|
| 281 |
const T& old_value, const T& new_value);
|
| 282 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class T>
|
| 283 |
ForwardIterator2
|
|
@@ -285,401 +486,642 @@ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
|
| 285 |
ForwardIterator1 first, ForwardIterator1 last,
|
| 286 |
ForwardIterator2 result,
|
| 287 |
const T& old_value, const T& new_value);
|
| 288 |
|
| 289 |
template<class InputIterator, class OutputIterator, class Predicate, class T>
|
| 290 |
-
OutputIterator
|
| 291 |
replace_copy_if(InputIterator first, InputIterator last,
|
| 292 |
OutputIterator result,
|
| 293 |
Predicate pred, const T& new_value);
|
| 294 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 295 |
class Predicate, class T>
|
| 296 |
ForwardIterator2
|
| 297 |
replace_copy_if(ExecutionPolicy&& exec,
|
| 298 |
ForwardIterator1 first, ForwardIterator1 last,
|
| 299 |
ForwardIterator2 result,
|
| 300 |
Predicate pred, const T& new_value);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 301 |
```
|
| 302 |
|
| 303 |
-
|
| 304 |
-
shall be writable ([[iterator.requirements.general]]) to the `result`
|
| 305 |
-
output iterator. The ranges \[`first`, `last`) and \[`result`,
|
| 306 |
-
`result + (last - first)`) shall not overlap.
|
| 307 |
|
| 308 |
-
*
|
| 309 |
-
`
|
| 310 |
-
`*(first + (i - result))
|
| 311 |
-
|
|
|
|
|
|
|
| 312 |
|
| 313 |
-
```
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 317 |
|
| 318 |
-
|
|
|
|
|
|
|
| 319 |
|
| 320 |
*Complexity:* Exactly `last - first` applications of the corresponding
|
| 321 |
-
predicate.
|
| 322 |
|
| 323 |
### Fill <a id="alg.fill">[[alg.fill]]</a>
|
| 324 |
|
| 325 |
``` cpp
|
| 326 |
template<class ForwardIterator, class T>
|
| 327 |
-
void fill(ForwardIterator first, ForwardIterator last, const T& value);
|
| 328 |
template<class ExecutionPolicy, class ForwardIterator, class T>
|
| 329 |
void fill(ExecutionPolicy&& exec,
|
| 330 |
ForwardIterator first, ForwardIterator last, const T& value);
|
| 331 |
|
| 332 |
template<class OutputIterator, class Size, class T>
|
| 333 |
-
OutputIterator fill_n(OutputIterator first, Size n, const T& value);
|
| 334 |
template<class ExecutionPolicy, class ForwardIterator, class Size, class T>
|
| 335 |
ForwardIterator fill_n(ExecutionPolicy&& exec,
|
| 336 |
ForwardIterator first, Size n, const T& value);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 337 |
```
|
| 338 |
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
The type `Size` shall be convertible to an integral
|
| 342 |
-
type ([[conv.integral]], [[class.conv]]).
|
| 343 |
|
| 344 |
-
*
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
|
| 349 |
-
*
|
| 350 |
-
|
| 351 |
|
| 352 |
-
*
|
| 353 |
-
|
|
|
|
| 354 |
|
| 355 |
### Generate <a id="alg.generate">[[alg.generate]]</a>
|
| 356 |
|
| 357 |
``` cpp
|
| 358 |
template<class ForwardIterator, class Generator>
|
| 359 |
-
void generate(ForwardIterator first, ForwardIterator last,
|
| 360 |
Generator gen);
|
| 361 |
template<class ExecutionPolicy, class ForwardIterator, class Generator>
|
| 362 |
void generate(ExecutionPolicy&& exec,
|
| 363 |
ForwardIterator first, ForwardIterator last,
|
| 364 |
Generator gen);
|
| 365 |
|
| 366 |
template<class OutputIterator, class Size, class Generator>
|
| 367 |
-
OutputIterator generate_n(OutputIterator first, Size n, Generator gen);
|
| 368 |
template<class ExecutionPolicy, class ForwardIterator, class Size, class Generator>
|
| 369 |
ForwardIterator generate_n(ExecutionPolicy&& exec,
|
| 370 |
ForwardIterator first, Size n, Generator gen);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 371 |
```
|
| 372 |
|
| 373 |
-
|
| 374 |
-
|
| 375 |
|
| 376 |
-
*
|
| 377 |
-
|
| 378 |
-
range \[`first`, `last`). The `generate_n` algorithms invoke the
|
| 379 |
-
function object `gen` and assign the return value of `gen` through all
|
| 380 |
-
the iterators in the range \[`first`, `first + n`) if `n` is positive,
|
| 381 |
-
otherwise they do nothing.
|
| 382 |
|
| 383 |
-
*
|
| 384 |
-
|
| 385 |
|
| 386 |
-
*
|
| 387 |
-
|
|
|
|
| 388 |
|
| 389 |
### Remove <a id="alg.remove">[[alg.remove]]</a>
|
| 390 |
|
| 391 |
``` cpp
|
| 392 |
template<class ForwardIterator, class T>
|
| 393 |
-
ForwardIterator remove(ForwardIterator first, ForwardIterator last,
|
| 394 |
const T& value);
|
| 395 |
template<class ExecutionPolicy, class ForwardIterator, class T>
|
| 396 |
ForwardIterator remove(ExecutionPolicy&& exec,
|
| 397 |
ForwardIterator first, ForwardIterator last,
|
| 398 |
const T& value);
|
| 399 |
|
| 400 |
template<class ForwardIterator, class Predicate>
|
| 401 |
-
ForwardIterator remove_if(ForwardIterator first, ForwardIterator last,
|
| 402 |
Predicate pred);
|
| 403 |
template<class ExecutionPolicy, class ForwardIterator, class Predicate>
|
| 404 |
ForwardIterator remove_if(ExecutionPolicy&& exec,
|
| 405 |
ForwardIterator first, ForwardIterator last,
|
| 406 |
Predicate pred);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 407 |
```
|
| 408 |
|
| 409 |
-
|
| 410 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 411 |
|
| 412 |
*Effects:* Eliminates all the elements referred to by iterator `i` in
|
| 413 |
-
the range \[`first`, `last`) for which
|
| 414 |
-
conditions hold: `*i == value, pred(*i) != false`.
|
| 415 |
|
| 416 |
-
*Returns:*
|
| 417 |
|
| 418 |
-
|
|
|
|
|
|
|
|
|
|
| 419 |
|
| 420 |
*Complexity:* Exactly `last - first` applications of the corresponding
|
| 421 |
-
predicate.
|
| 422 |
|
| 423 |
[*Note 1*: Each element in the range \[`ret`, `last`), where `ret` is
|
| 424 |
the returned value, has a valid but unspecified state, because the
|
| 425 |
algorithms can eliminate elements by moving from elements that were
|
| 426 |
originally in that range. — *end note*]
|
| 427 |
|
| 428 |
``` cpp
|
| 429 |
template<class InputIterator, class OutputIterator, class T>
|
| 430 |
-
OutputIterator
|
| 431 |
remove_copy(InputIterator first, InputIterator last,
|
| 432 |
OutputIterator result, const T& value);
|
| 433 |
-
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
|
|
|
| 434 |
ForwardIterator2
|
| 435 |
remove_copy(ExecutionPolicy&& exec,
|
| 436 |
ForwardIterator1 first, ForwardIterator1 last,
|
| 437 |
ForwardIterator2 result, const T& value);
|
| 438 |
|
| 439 |
template<class InputIterator, class OutputIterator, class Predicate>
|
| 440 |
-
OutputIterator
|
| 441 |
remove_copy_if(InputIterator first, InputIterator last,
|
| 442 |
OutputIterator result, Predicate pred);
|
| 443 |
-
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
|
|
|
| 444 |
ForwardIterator2
|
| 445 |
remove_copy_if(ExecutionPolicy&& exec,
|
| 446 |
ForwardIterator1 first, ForwardIterator1 last,
|
| 447 |
ForwardIterator2 result, Predicate pred);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 448 |
```
|
| 449 |
|
| 450 |
-
|
| 451 |
-
|
| 452 |
-
`*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 453 |
|
| 454 |
[*Note 2*: For the overloads with an `ExecutionPolicy`, there may be a
|
| 455 |
-
performance cost if `iterator_traits<ForwardIterator1>::value_type`
|
| 456 |
-
not
|
| 457 |
-
|
| 458 |
|
| 459 |
*Effects:* Copies all the elements referred to by the iterator `i` in
|
| 460 |
-
the range \[`first`, `last`) for which
|
| 461 |
-
conditions do not hold: `*i == value, pred(*i) != false`.
|
| 462 |
|
| 463 |
-
*Returns:*
|
|
|
|
|
|
|
|
|
|
| 464 |
|
| 465 |
*Complexity:* Exactly `last - first` applications of the corresponding
|
| 466 |
-
predicate.
|
| 467 |
|
| 468 |
-
*Remarks:* Stable
|
| 469 |
|
| 470 |
### Unique <a id="alg.unique">[[alg.unique]]</a>
|
| 471 |
|
| 472 |
``` cpp
|
| 473 |
template<class ForwardIterator>
|
| 474 |
-
ForwardIterator unique(ForwardIterator first, ForwardIterator last);
|
| 475 |
template<class ExecutionPolicy, class ForwardIterator>
|
| 476 |
ForwardIterator unique(ExecutionPolicy&& exec,
|
| 477 |
ForwardIterator first, ForwardIterator last);
|
| 478 |
|
| 479 |
template<class ForwardIterator, class BinaryPredicate>
|
| 480 |
-
ForwardIterator unique(ForwardIterator first, ForwardIterator last,
|
| 481 |
BinaryPredicate pred);
|
| 482 |
template<class ExecutionPolicy, class ForwardIterator, class BinaryPredicate>
|
| 483 |
ForwardIterator unique(ExecutionPolicy&& exec,
|
| 484 |
ForwardIterator first, ForwardIterator last,
|
| 485 |
BinaryPredicate pred);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 486 |
```
|
| 487 |
|
| 488 |
-
|
| 489 |
-
|
| 490 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 491 |
|
| 492 |
*Effects:* For a nonempty range, eliminates all but the first element
|
| 493 |
from every consecutive group of equivalent elements referred to by the
|
| 494 |
-
iterator `i` in the range \[`first + 1`, `last`) for which
|
| 495 |
-
conditions hold: `*(i - 1) == *i` or `pred(*(i - 1), *i) != false`.
|
| 496 |
|
| 497 |
-
*Returns:*
|
|
|
|
|
|
|
|
|
|
| 498 |
|
| 499 |
*Complexity:* For nonempty ranges, exactly `(last - first) - 1`
|
| 500 |
-
applications of the corresponding predicate
|
|
|
|
| 501 |
|
| 502 |
``` cpp
|
| 503 |
template<class InputIterator, class OutputIterator>
|
| 504 |
-
OutputIterator
|
| 505 |
unique_copy(InputIterator first, InputIterator last,
|
| 506 |
OutputIterator result);
|
| 507 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 508 |
ForwardIterator2
|
| 509 |
unique_copy(ExecutionPolicy&& exec,
|
| 510 |
ForwardIterator1 first, ForwardIterator1 last,
|
| 511 |
ForwardIterator2 result);
|
| 512 |
|
| 513 |
template<class InputIterator, class OutputIterator,
|
| 514 |
class BinaryPredicate>
|
| 515 |
-
OutputIterator
|
| 516 |
unique_copy(InputIterator first, InputIterator last,
|
| 517 |
OutputIterator result, BinaryPredicate pred);
|
| 518 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 519 |
class BinaryPredicate>
|
| 520 |
ForwardIterator2
|
| 521 |
unique_copy(ExecutionPolicy&& exec,
|
| 522 |
ForwardIterator1 first, ForwardIterator1 last,
|
| 523 |
ForwardIterator2 result, BinaryPredicate pred);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 524 |
```
|
| 525 |
|
| 526 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 527 |
|
| 528 |
-
- The comparison function shall be an equivalence relation.
|
| 529 |
- The ranges \[`first`, `last`) and \[`result`, `result+(last-first)`)
|
| 530 |
-
|
| 531 |
-
-
|
| 532 |
-
-
|
| 533 |
-
|
| 534 |
-
|
| 535 |
-
|
| 536 |
-
|
| 537 |
-
|
| 538 |
-
|
| 539 |
-
|
| 540 |
-
|
| 541 |
-
|
| 542 |
-
|
|
|
|
|
|
|
|
|
|
| 543 |
|
| 544 |
*Effects:* Copies only the first element from every consecutive group of
|
| 545 |
equal elements referred to by the iterator `i` in the range \[`first`,
|
| 546 |
-
`last`) for which
|
| 547 |
-
`*i == *(i - 1)` or `pred(*i, *(i - 1)) != false`.
|
| 548 |
|
| 549 |
-
*Returns:*
|
| 550 |
|
| 551 |
-
|
| 552 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 553 |
|
| 554 |
### Reverse <a id="alg.reverse">[[alg.reverse]]</a>
|
| 555 |
|
| 556 |
``` cpp
|
| 557 |
template<class BidirectionalIterator>
|
| 558 |
-
void reverse(BidirectionalIterator first, BidirectionalIterator last);
|
| 559 |
template<class ExecutionPolicy, class BidirectionalIterator>
|
| 560 |
void reverse(ExecutionPolicy&& exec,
|
| 561 |
BidirectionalIterator first, BidirectionalIterator last);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 562 |
```
|
| 563 |
|
| 564 |
-
*
|
|
|
|
|
|
|
| 565 |
|
| 566 |
*Effects:* For each non-negative integer `i < (last - first) / 2`,
|
| 567 |
-
applies `iter_swap`
|
|
|
|
| 568 |
`first + i, (last - i) - 1`.
|
| 569 |
|
| 570 |
-
*
|
| 571 |
-
`ValueSwappable` ([[swappable.requirements]]).
|
| 572 |
|
| 573 |
*Complexity:* Exactly `(last - first)/2` swaps.
|
| 574 |
|
| 575 |
``` cpp
|
| 576 |
template<class BidirectionalIterator, class OutputIterator>
|
| 577 |
-
OutputIterator
|
| 578 |
reverse_copy(BidirectionalIterator first, BidirectionalIterator last,
|
| 579 |
OutputIterator result);
|
| 580 |
template<class ExecutionPolicy, class BidirectionalIterator, class ForwardIterator>
|
| 581 |
ForwardIterator
|
| 582 |
reverse_copy(ExecutionPolicy&& exec,
|
| 583 |
BidirectionalIterator first, BidirectionalIterator last,
|
| 584 |
ForwardIterator result);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 585 |
```
|
| 586 |
|
| 587 |
-
|
| 588 |
-
|
|
|
|
|
|
|
| 589 |
|
| 590 |
*Effects:* Copies the range \[`first`, `last`) to the range \[`result`,
|
| 591 |
-
`result +
|
| 592 |
-
|
| 593 |
-
`*(result +
|
| 594 |
|
| 595 |
-
*Returns:*
|
| 596 |
|
| 597 |
-
|
|
|
|
|
|
|
|
|
|
| 598 |
|
| 599 |
### Rotate <a id="alg.rotate">[[alg.rotate]]</a>
|
| 600 |
|
| 601 |
``` cpp
|
| 602 |
template<class ForwardIterator>
|
| 603 |
-
ForwardIterator
|
| 604 |
rotate(ForwardIterator first, ForwardIterator middle, ForwardIterator last);
|
| 605 |
template<class ExecutionPolicy, class ForwardIterator>
|
| 606 |
ForwardIterator
|
| 607 |
rotate(ExecutionPolicy&& exec,
|
| 608 |
ForwardIterator first, ForwardIterator middle, ForwardIterator last);
|
|
|
|
|
|
|
|
|
|
| 609 |
```
|
| 610 |
|
| 611 |
-
*
|
| 612 |
-
ranges.
|
| 613 |
-
|
| 614 |
-
|
| 615 |
-
(
|
| 616 |
-
|
| 617 |
|
| 618 |
*Effects:* For each non-negative integer `i < (last - first)`, places
|
| 619 |
the element from the position `first + i` into position
|
| 620 |
`first + (i + (last - middle)) % (last - first)`.
|
| 621 |
|
| 622 |
-
*
|
| 623 |
|
| 624 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
| 625 |
|
| 626 |
*Complexity:* At most `last - first` swaps.
|
| 627 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 628 |
``` cpp
|
| 629 |
template<class ForwardIterator, class OutputIterator>
|
| 630 |
-
OutputIterator
|
| 631 |
rotate_copy(ForwardIterator first, ForwardIterator middle, ForwardIterator last,
|
| 632 |
OutputIterator result);
|
| 633 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 634 |
ForwardIterator2
|
| 635 |
rotate_copy(ExecutionPolicy&& exec,
|
| 636 |
ForwardIterator1 first, ForwardIterator1 middle, ForwardIterator1 last,
|
| 637 |
ForwardIterator2 result);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 638 |
```
|
| 639 |
|
| 640 |
-
|
| 641 |
-
|
|
|
|
|
|
|
|
|
|
| 642 |
|
| 643 |
*Effects:* Copies the range \[`first`, `last`) to the range \[`result`,
|
| 644 |
-
`result +
|
| 645 |
-
|
| 646 |
-
`*(result + i) = *(first + (i + (middle - first)) %
|
| 647 |
|
| 648 |
-
*Returns:*
|
| 649 |
|
| 650 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 651 |
|
| 652 |
### Sample <a id="alg.random.sample">[[alg.random.sample]]</a>
|
| 653 |
|
| 654 |
``` cpp
|
| 655 |
template<class PopulationIterator, class SampleIterator,
|
| 656 |
class Distance, class UniformRandomBitGenerator>
|
| 657 |
SampleIterator sample(PopulationIterator first, PopulationIterator last,
|
| 658 |
SampleIterator out, Distance n,
|
| 659 |
UniformRandomBitGenerator&& g);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 660 |
```
|
| 661 |
|
| 662 |
-
*
|
|
|
|
|
|
|
| 663 |
|
| 664 |
-
|
| 665 |
-
|
| 666 |
-
- `SampleIterator` shall satisfy the requirements of an output
|
| 667 |
-
iterator ([[output.iterators]]).
|
| 668 |
-
- `SampleIterator` shall satisfy the additional requirements of a random
|
| 669 |
-
access iterator ([[random.access.iterators]]) unless
|
| 670 |
-
`PopulationIterator` satisfies the additional requirements of a
|
| 671 |
-
forward iterator ([[forward.iterators]]).
|
| 672 |
-
- `PopulationIterator`’s value type shall be
|
| 673 |
-
writable ([[iterator.requirements.general]]) to `out`.
|
| 674 |
-
- `Distance` shall be an integer type.
|
| 675 |
-
- `remove_reference_t<UniformRandomBitGenerator>` shall meet the
|
| 676 |
-
requirements of a uniform random bit generator type
|
| 677 |
-
([[rand.req.urng]]) whose return type is convertible to `Distance`.
|
| 678 |
-
- `out` shall not be in the range \[`first`, `last`).
|
| 679 |
|
| 680 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 681 |
\[`first`, `last`) (the *population*) to `out` such that each possible
|
| 682 |
sample has equal probability of appearance.
|
| 683 |
|
| 684 |
[*Note 1*: Algorithms that obtain such effects include *selection
|
| 685 |
sampling* and *reservoir sampling*. — *end note*]
|
|
@@ -688,37 +1130,104 @@ sampling* and *reservoir sampling*. — *end note*]
|
|
| 688 |
|
| 689 |
*Complexity:* 𝑂(`last - first`).
|
| 690 |
|
| 691 |
*Remarks:*
|
| 692 |
|
| 693 |
-
-
|
| 694 |
-
|
|
|
|
|
|
|
| 695 |
- To the extent that the implementation of this function makes use of
|
| 696 |
-
random numbers, the object `g`
|
| 697 |
-
|
| 698 |
|
| 699 |
### Shuffle <a id="alg.random.shuffle">[[alg.random.shuffle]]</a>
|
| 700 |
|
| 701 |
``` cpp
|
| 702 |
template<class RandomAccessIterator, class UniformRandomBitGenerator>
|
| 703 |
void shuffle(RandomAccessIterator first,
|
| 704 |
RandomAccessIterator last,
|
| 705 |
UniformRandomBitGenerator&& g);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 706 |
```
|
| 707 |
|
| 708 |
-
*
|
| 709 |
-
|
| 710 |
-
`
|
| 711 |
-
requirements
|
| 712 |
-
|
| 713 |
-
|
| 714 |
|
| 715 |
*Effects:* Permutes the elements in the range \[`first`, `last`) such
|
| 716 |
that each possible permutation of those elements has equal probability
|
| 717 |
of appearance.
|
| 718 |
|
|
|
|
|
|
|
| 719 |
*Complexity:* Exactly `(last - first) - 1` swaps.
|
| 720 |
|
| 721 |
*Remarks:* To the extent that the implementation of this function makes
|
| 722 |
-
use of random numbers, the object `g` shall serve as the
|
| 723 |
implementation’s source of randomness.
|
| 724 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
### Copy <a id="alg.copy">[[alg.copy]]</a>
|
| 4 |
|
| 5 |
``` cpp
|
| 6 |
template<class InputIterator, class OutputIterator>
|
| 7 |
+
constexpr OutputIterator copy(InputIterator first, InputIterator last,
|
| 8 |
OutputIterator result);
|
| 9 |
+
|
| 10 |
+
template<input_iterator I, sentinel_for<I> S, weakly_incrementable O>
|
| 11 |
+
requires indirectly_copyable<I, O>
|
| 12 |
+
constexpr ranges::copy_result<I, O> ranges::copy(I first, S last, O result);
|
| 13 |
+
template<input_range R, weakly_incrementable O>
|
| 14 |
+
requires indirectly_copyable<iterator_t<R>, O>
|
| 15 |
+
constexpr ranges::copy_result<borrowed_iterator_t<R>, O> ranges::copy(R&& r, O result);
|
| 16 |
```
|
| 17 |
|
| 18 |
+
Let N be `last - first`.
|
| 19 |
+
|
| 20 |
+
*Preconditions:* `result` is not in the range \[`first`, `last`).
|
| 21 |
|
| 22 |
*Effects:* Copies elements in the range \[`first`, `last`) into the
|
| 23 |
+
range \[`result`, `result + `N) starting from `first` and proceeding to
|
| 24 |
+
`last`. For each non-negative integer n < N, performs
|
| 25 |
+
`*(result + `n`) = *(first + `n`)`.
|
| 26 |
|
| 27 |
+
*Returns:*
|
| 28 |
|
| 29 |
+
- `result + `N for the overload in namespace `std`.
|
| 30 |
+
- `{last, result + `N`}` for the overloads in namespace `ranges`.
|
| 31 |
+
|
| 32 |
+
*Complexity:* Exactly N assignments.
|
| 33 |
|
| 34 |
``` cpp
|
| 35 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 36 |
ForwardIterator2 copy(ExecutionPolicy&& policy,
|
| 37 |
ForwardIterator1 first, ForwardIterator1 last,
|
| 38 |
ForwardIterator2 result);
|
| 39 |
```
|
| 40 |
|
| 41 |
+
*Preconditions:* The ranges \[`first`, `last`) and \[`result`,
|
| 42 |
+
`result + (last - first)`) do not overlap.
|
| 43 |
|
| 44 |
*Effects:* Copies elements in the range \[`first`, `last`) into the
|
| 45 |
range \[`result`, `result + (last - first)`). For each non-negative
|
| 46 |
integer `n < (last - first)`, performs `*(result + n) = *(first + n)`.
|
| 47 |
|
|
|
|
| 49 |
|
| 50 |
*Complexity:* Exactly `last - first` assignments.
|
| 51 |
|
| 52 |
``` cpp
|
| 53 |
template<class InputIterator, class Size, class OutputIterator>
|
| 54 |
+
constexpr OutputIterator copy_n(InputIterator first, Size n,
|
| 55 |
OutputIterator result);
|
| 56 |
template<class ExecutionPolicy, class ForwardIterator1, class Size, class ForwardIterator2>
|
| 57 |
ForwardIterator2 copy_n(ExecutionPolicy&& exec,
|
| 58 |
ForwardIterator1 first, Size n,
|
| 59 |
ForwardIterator2 result);
|
| 60 |
+
|
| 61 |
+
template<input_iterator I, weakly_incrementable O>
|
| 62 |
+
requires indirectly_copyable<I, O>
|
| 63 |
+
constexpr ranges::copy_n_result<I, O>
|
| 64 |
+
ranges::copy_n(I first, iter_difference_t<I> n, O result);
|
| 65 |
```
|
| 66 |
|
| 67 |
+
Let N be max(0, `n`).
|
| 68 |
+
|
| 69 |
+
*Mandates:* The type `Size` is convertible to an integral
|
| 70 |
+
type ([[conv.integral]], [[class.conv]]).
|
| 71 |
+
|
| 72 |
+
*Effects:* For each non-negative integer i < N, performs
|
| 73 |
`*(result + i) = *(first + i)`.
|
| 74 |
|
| 75 |
+
*Returns:*
|
| 76 |
|
| 77 |
+
- `result + `N for the overloads in namespace `std`.
|
| 78 |
+
- `{first + `N`, result + `N`}` for the overload in namespace `ranges`.
|
| 79 |
+
|
| 80 |
+
*Complexity:* Exactly N assignments.
|
| 81 |
|
| 82 |
``` cpp
|
| 83 |
template<class InputIterator, class OutputIterator, class Predicate>
|
| 84 |
+
constexpr OutputIterator copy_if(InputIterator first, InputIterator last,
|
| 85 |
OutputIterator result, Predicate pred);
|
| 86 |
+
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 87 |
+
class Predicate>
|
| 88 |
ForwardIterator2 copy_if(ExecutionPolicy&& exec,
|
| 89 |
ForwardIterator1 first, ForwardIterator1 last,
|
| 90 |
ForwardIterator2 result, Predicate pred);
|
| 91 |
+
|
| 92 |
+
template<input_iterator I, sentinel_for<I> S, weakly_incrementable O, class Proj = identity,
|
| 93 |
+
indirect_unary_predicate<projected<I, Proj>> Pred>
|
| 94 |
+
requires indirectly_copyable<I, O>
|
| 95 |
+
constexpr ranges::copy_if_result<I, O>
|
| 96 |
+
ranges::copy_if(I first, S last, O result, Pred pred, Proj proj = {});
|
| 97 |
+
template<input_range R, weakly_incrementable O, class Proj = identity,
|
| 98 |
+
indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
|
| 99 |
+
requires indirectly_copyable<iterator_t<R>, O>
|
| 100 |
+
constexpr ranges::copy_if_result<borrowed_iterator_t<R>, O>
|
| 101 |
+
ranges::copy_if(R&& r, O result, Pred pred, Proj proj = {});
|
| 102 |
```
|
| 103 |
|
| 104 |
+
Let E be:
|
| 105 |
+
|
| 106 |
+
- `bool(pred(*i))` for the overloads in namespace `std`;
|
| 107 |
+
- `bool(invoke(pred, invoke(proj, *i)))` for the overloads in namespace
|
| 108 |
+
`ranges`,
|
| 109 |
+
|
| 110 |
+
and N be the number of iterators `i` in the range \[`first`, `last`) for
|
| 111 |
+
which the condition E holds.
|
| 112 |
+
|
| 113 |
+
*Preconditions:* The ranges \[`first`, `last`) and \[`result`,
|
| 114 |
+
`result + (last - first)`) do not overlap.
|
| 115 |
|
| 116 |
[*Note 1*: For the overload with an `ExecutionPolicy`, there may be a
|
| 117 |
performance cost if `iterator_traits<ForwardIterator1>::value_type` is
|
| 118 |
+
not *Cpp17MoveConstructible*
|
| 119 |
+
([[cpp17.moveconstructible]]). — *end note*]
|
| 120 |
|
| 121 |
*Effects:* Copies all of the elements referred to by the iterator `i` in
|
| 122 |
+
the range \[`first`, `last`) for which E is `true`.
|
| 123 |
|
| 124 |
+
*Returns:*
|
| 125 |
+
|
| 126 |
+
- `result + `N for the overloads in namespace `std`.
|
| 127 |
+
- `{last, result + `N`}` for the overloads in namespace `ranges`.
|
| 128 |
|
| 129 |
*Complexity:* Exactly `last - first` applications of the corresponding
|
| 130 |
+
predicate and any projection.
|
| 131 |
|
| 132 |
+
*Remarks:* Stable [[algorithm.stable]].
|
| 133 |
|
| 134 |
``` cpp
|
| 135 |
template<class BidirectionalIterator1, class BidirectionalIterator2>
|
| 136 |
+
constexpr BidirectionalIterator2
|
| 137 |
copy_backward(BidirectionalIterator1 first,
|
| 138 |
BidirectionalIterator1 last,
|
| 139 |
BidirectionalIterator2 result);
|
| 140 |
+
|
| 141 |
+
template<bidirectional_iterator I1, sentinel_for<I1> S1, bidirectional_iterator I2>
|
| 142 |
+
requires indirectly_copyable<I1, I2>
|
| 143 |
+
constexpr ranges::copy_backward_result<I1, I2>
|
| 144 |
+
ranges::copy_backward(I1 first, S1 last, I2 result);
|
| 145 |
+
template<bidirectional_range R, bidirectional_iterator I>
|
| 146 |
+
requires indirectly_copyable<iterator_t<R>, I>
|
| 147 |
+
constexpr ranges::copy_backward_result<borrowed_iterator_t<R>, I>
|
| 148 |
+
ranges::copy_backward(R&& r, I result);
|
| 149 |
```
|
| 150 |
|
| 151 |
+
Let N be `last - first`.
|
| 152 |
+
|
| 153 |
+
*Preconditions:* `result` is not in the range (`first`, `last`).
|
| 154 |
|
| 155 |
*Effects:* Copies elements in the range \[`first`, `last`) into the
|
| 156 |
+
range \[`result - `N, `result`) starting from `last - 1` and proceeding
|
| 157 |
+
to `first`. [^2] For each positive integer n ≤ N, performs
|
| 158 |
+
`*(result - `n`) = *(last - `n`)`.
|
| 159 |
|
| 160 |
+
*Returns:*
|
| 161 |
|
| 162 |
+
- `result - `N for the overload in namespace `std`.
|
| 163 |
+
- `{last, result - `N`}` for the overloads in namespace `ranges`.
|
| 164 |
+
|
| 165 |
+
*Complexity:* Exactly N assignments.
|
| 166 |
|
| 167 |
### Move <a id="alg.move">[[alg.move]]</a>
|
| 168 |
|
| 169 |
``` cpp
|
| 170 |
template<class InputIterator, class OutputIterator>
|
| 171 |
+
constexpr OutputIterator move(InputIterator first, InputIterator last,
|
| 172 |
+
OutputIterator result);
|
| 173 |
+
|
| 174 |
+
template<input_iterator I, sentinel_for<I> S, weakly_incrementable O>
|
| 175 |
+
requires indirectly_movable<I, O>
|
| 176 |
+
constexpr ranges::move_result<I, O>
|
| 177 |
+
ranges::move(I first, S last, O result);
|
| 178 |
+
template<input_range R, weakly_incrementable O>
|
| 179 |
+
requires indirectly_movable<iterator_t<R>, O>
|
| 180 |
+
constexpr ranges::move_result<borrowed_iterator_t<R>, O>
|
| 181 |
+
ranges::move(R&& r, O result);
|
| 182 |
```
|
| 183 |
|
| 184 |
+
Let E be
|
| 185 |
+
|
| 186 |
+
- `std::move(*(first + `n`))` for the overload in namespace `std`;
|
| 187 |
+
- `ranges::iter_move(first + `n`)` for the overloads in namespace
|
| 188 |
+
`ranges`.
|
| 189 |
+
|
| 190 |
+
Let N be `last - first`.
|
| 191 |
+
|
| 192 |
+
*Preconditions:* `result` is not in the range \[`first`, `last`).
|
| 193 |
|
| 194 |
*Effects:* Moves elements in the range \[`first`, `last`) into the range
|
| 195 |
+
\[`result`, `result + `N) starting from `first` and proceeding to
|
| 196 |
+
`last`. For each non-negative integer n < N, performs
|
| 197 |
+
`*(result + `n`) = `E.
|
| 198 |
|
| 199 |
+
*Returns:*
|
| 200 |
|
| 201 |
+
- `result + `N for the overload in namespace `std`.
|
| 202 |
+
- `{last, result + `N`}` for the overloads in namespace `ranges`.
|
| 203 |
+
|
| 204 |
+
*Complexity:* Exactly N assignments.
|
| 205 |
|
| 206 |
``` cpp
|
| 207 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 208 |
ForwardIterator2 move(ExecutionPolicy&& policy,
|
| 209 |
ForwardIterator1 first, ForwardIterator1 last,
|
| 210 |
ForwardIterator2 result);
|
| 211 |
```
|
| 212 |
|
| 213 |
+
Let N be `last - first`.
|
| 214 |
+
|
| 215 |
+
*Preconditions:* The ranges \[`first`, `last`) and \[`result`,
|
| 216 |
+
`result + `N) do not overlap.
|
| 217 |
|
| 218 |
*Effects:* Moves elements in the range \[`first`, `last`) into the range
|
| 219 |
+
\[`result`, `result + `N). For each non-negative integer n < N, performs
|
| 220 |
+
`*(result + `n`) = std::move(*(first + `n`))`.
|
|
|
|
| 221 |
|
| 222 |
+
*Returns:* `result + `N.
|
| 223 |
|
| 224 |
+
*Complexity:* Exactly N assignments.
|
| 225 |
|
| 226 |
``` cpp
|
| 227 |
template<class BidirectionalIterator1, class BidirectionalIterator2>
|
| 228 |
+
constexpr BidirectionalIterator2
|
| 229 |
+
move_backward(BidirectionalIterator1 first, BidirectionalIterator1 last,
|
|
|
|
| 230 |
BidirectionalIterator2 result);
|
| 231 |
+
|
| 232 |
+
template<bidirectional_iterator I1, sentinel_for<I1> S1, bidirectional_iterator I2>
|
| 233 |
+
requires indirectly_movable<I1, I2>
|
| 234 |
+
constexpr ranges::move_backward_result<I1, I2>
|
| 235 |
+
ranges::move_backward(I1 first, S1 last, I2 result);
|
| 236 |
+
template<bidirectional_range R, bidirectional_iterator I>
|
| 237 |
+
requires indirectly_movable<iterator_t<R>, I>
|
| 238 |
+
constexpr ranges::move_backward_result<borrowed_iterator_t<R>, I>
|
| 239 |
+
ranges::move_backward(R&& r, I result);
|
| 240 |
```
|
| 241 |
|
| 242 |
+
Let E be
|
| 243 |
+
|
| 244 |
+
- `std::move(*(last - `n`))` for the overload in namespace `std`;
|
| 245 |
+
- `ranges::iter_move(last - `n`)` for the overloads in namespace
|
| 246 |
+
`ranges`.
|
| 247 |
+
|
| 248 |
+
Let N be `last - first`.
|
| 249 |
+
|
| 250 |
+
*Preconditions:* `result` is not in the range (`first`, `last`).
|
| 251 |
|
| 252 |
*Effects:* Moves elements in the range \[`first`, `last`) into the range
|
| 253 |
+
\[`result - `N, `result`) starting from `last - 1` and proceeding to
|
| 254 |
+
`first`. [^3] For each positive integer n ≤ N, performs
|
| 255 |
+
`*(result - `n`) = `E.
|
|
|
|
| 256 |
|
| 257 |
+
*Returns:*
|
| 258 |
|
| 259 |
+
- `result - `N for the overload in namespace `std`.
|
| 260 |
+
- `{last, result - `N`}` for the overloads in namespace `ranges`.
|
| 261 |
+
|
| 262 |
+
*Complexity:* Exactly N assignments.
|
| 263 |
|
| 264 |
### Swap <a id="alg.swap">[[alg.swap]]</a>
|
| 265 |
|
| 266 |
``` cpp
|
| 267 |
template<class ForwardIterator1, class ForwardIterator2>
|
| 268 |
+
constexpr ForwardIterator2
|
| 269 |
swap_ranges(ForwardIterator1 first1, ForwardIterator1 last1,
|
| 270 |
ForwardIterator2 first2);
|
| 271 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 272 |
ForwardIterator2
|
| 273 |
swap_ranges(ExecutionPolicy&& exec,
|
| 274 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 275 |
ForwardIterator2 first2);
|
| 276 |
+
|
| 277 |
+
template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2>
|
| 278 |
+
requires indirectly_swappable<I1, I2>
|
| 279 |
+
constexpr ranges::swap_ranges_result<I1, I2>
|
| 280 |
+
ranges::swap_ranges(I1 first1, S1 last1, I2 first2, S2 last2);
|
| 281 |
+
template<input_range R1, input_range R2>
|
| 282 |
+
requires indirectly_swappable<iterator_t<R1>, iterator_t<R2>>
|
| 283 |
+
constexpr ranges::swap_ranges_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>>
|
| 284 |
+
ranges::swap_ranges(R1&& r1, R2&& r2);
|
| 285 |
```
|
| 286 |
|
| 287 |
+
Let:
|
|
|
|
|
|
|
| 288 |
|
| 289 |
+
- `last2` be `first2 + (last1 - first1)` for the overloads with no
|
| 290 |
+
parameter named `last2`;
|
| 291 |
+
- M be min(`last1 - first1`, `last2 - first2`).
|
| 292 |
|
| 293 |
+
*Preconditions:* The two ranges \[`first1`, `last1`) and \[`first2`,
|
| 294 |
+
`last2`) do not overlap. For the overloads in namespace `std`,
|
| 295 |
+
`*(first1 + `n`)` is swappable with [[swappable.requirements]]
|
| 296 |
+
`*(first2 + `n`)`.
|
| 297 |
|
| 298 |
+
*Effects:* For each non-negative integer n < M performs:
|
| 299 |
+
|
| 300 |
+
- `swap(*(first1 + `n`), *(first2 + `n`))` for the overloads in
|
| 301 |
+
namespace `std`;
|
| 302 |
+
- `ranges::iter_swap(first1 + `n`, first2 + `n`)` for the overloads in
|
| 303 |
+
namespace `ranges`.
|
| 304 |
+
|
| 305 |
+
*Returns:*
|
| 306 |
+
|
| 307 |
+
- `last2` for the overloads in namespace `std`.
|
| 308 |
+
- `{first1 + `M`, first2 + `M`}` for the overloads in namespace
|
| 309 |
+
`ranges`.
|
| 310 |
+
|
| 311 |
+
*Complexity:* Exactly M swaps.
|
| 312 |
|
| 313 |
``` cpp
|
| 314 |
template<class ForwardIterator1, class ForwardIterator2>
|
| 315 |
+
constexpr void iter_swap(ForwardIterator1 a, ForwardIterator2 b);
|
| 316 |
```
|
| 317 |
|
| 318 |
+
*Preconditions:* `a` and `b` are dereferenceable. `*a` is swappable
|
| 319 |
+
with [[swappable.requirements]] `*b`.
|
| 320 |
|
| 321 |
*Effects:* As if by `swap(*a, *b)`.
|
| 322 |
|
| 323 |
### Transform <a id="alg.transform">[[alg.transform]]</a>
|
| 324 |
|
| 325 |
``` cpp
|
| 326 |
template<class InputIterator, class OutputIterator,
|
| 327 |
class UnaryOperation>
|
| 328 |
+
constexpr OutputIterator
|
| 329 |
+
transform(InputIterator first1, InputIterator last1,
|
| 330 |
OutputIterator result, UnaryOperation op);
|
| 331 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 332 |
class UnaryOperation>
|
| 333 |
ForwardIterator2
|
| 334 |
transform(ExecutionPolicy&& exec,
|
| 335 |
+
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 336 |
ForwardIterator2 result, UnaryOperation op);
|
| 337 |
|
| 338 |
template<class InputIterator1, class InputIterator2,
|
| 339 |
class OutputIterator, class BinaryOperation>
|
| 340 |
+
constexpr OutputIterator
|
| 341 |
transform(InputIterator1 first1, InputIterator1 last1,
|
| 342 |
InputIterator2 first2, OutputIterator result,
|
| 343 |
BinaryOperation binary_op);
|
| 344 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 345 |
class ForwardIterator, class BinaryOperation>
|
| 346 |
ForwardIterator
|
| 347 |
transform(ExecutionPolicy&& exec,
|
| 348 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 349 |
ForwardIterator2 first2, ForwardIterator result,
|
| 350 |
BinaryOperation binary_op);
|
| 351 |
+
|
| 352 |
+
template<input_iterator I, sentinel_for<I> S, weakly_incrementable O,
|
| 353 |
+
copy_constructible F, class Proj = identity>
|
| 354 |
+
requires indirectly_writable<O, indirect_result_t<F&, projected<I, Proj>>>
|
| 355 |
+
constexpr ranges::unary_transform_result<I, O>
|
| 356 |
+
ranges::transform(I first1, S last1, O result, F op, Proj proj = {});
|
| 357 |
+
template<input_range R, weakly_incrementable O, copy_constructible F,
|
| 358 |
+
class Proj = identity>
|
| 359 |
+
requires indirectly_writable<O, indirect_result_t<F&, projected<iterator_t<R>, Proj>>>
|
| 360 |
+
constexpr ranges::unary_transform_result<borrowed_iterator_t<R>, O>
|
| 361 |
+
ranges::transform(R&& r, O result, F op, Proj proj = {});
|
| 362 |
+
template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2,
|
| 363 |
+
weakly_incrementable O, copy_constructible F, class Proj1 = identity,
|
| 364 |
+
class Proj2 = identity>
|
| 365 |
+
requires indirectly_writable<O, indirect_result_t<F&, projected<I1, Proj1>,
|
| 366 |
+
projected<I2, Proj2>>>
|
| 367 |
+
constexpr ranges::binary_transform_result<I1, I2, O>
|
| 368 |
+
ranges::transform(I1 first1, S1 last1, I2 first2, S2 last2, O result,
|
| 369 |
+
F binary_op, Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 370 |
+
template<input_range R1, input_range R2, weakly_incrementable O,
|
| 371 |
+
copy_constructible F, class Proj1 = identity, class Proj2 = identity>
|
| 372 |
+
requires indirectly_writable<O, indirect_result_t<F&, projected<iterator_t<R1>, Proj1>,
|
| 373 |
+
projected<iterator_t<R2>, Proj2>>>
|
| 374 |
+
constexpr ranges::binary_transform_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>, O>
|
| 375 |
+
ranges::transform(R1&& r1, R2&& r2, O result,
|
| 376 |
+
F binary_op, Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 377 |
```
|
| 378 |
|
| 379 |
+
Let:
|
|
|
|
| 380 |
|
| 381 |
+
- `last2` be `first2 + (last1 - first1)` for the overloads with
|
| 382 |
+
parameter `first2` but no parameter `last2`;
|
| 383 |
+
- N be `last1 - first1` for unary transforms, or
|
| 384 |
+
min(`last1 - first1`, `last2 - first2`) for binary transforms;
|
| 385 |
+
- E be
|
| 386 |
+
- `op(*(first1 + (i - result)))` for unary transforms defined in
|
| 387 |
+
namespace `std`;
|
| 388 |
+
- `binary_op(*(first1 + (i - result)), *(first2 + (i - result)))` for
|
| 389 |
+
binary transforms defined in namespace `std`;
|
| 390 |
+
- `invoke(op, invoke(proj, *(first1 + (i - result))))` for unary
|
| 391 |
+
transforms defined in namespace `ranges`;
|
| 392 |
+
- `invoke(binary_op, invoke(proj1, *(first1 + (i - result))), invoke(proj2,*(first2 + (i - result))))`
|
| 393 |
+
for binary transforms defined in namespace `ranges`.
|
| 394 |
+
|
| 395 |
+
*Preconditions:* `op` and `binary_op` do not invalidate iterators or
|
| 396 |
+
subranges, nor modify elements in the ranges
|
| 397 |
+
|
| 398 |
+
- \[`first1`, `first1 + `N\],
|
| 399 |
+
- \[`first2`, `first2 + `N\], and
|
| 400 |
+
- \[`result`, `result + `N\]. [^4]
|
| 401 |
|
| 402 |
*Effects:* Assigns through every iterator `i` in the range \[`result`,
|
| 403 |
+
`result + `N) a new corresponding value equal to E.
|
|
|
|
|
|
|
| 404 |
|
| 405 |
+
*Returns:*
|
| 406 |
|
| 407 |
+
- `result + `N for the overloads defined in namespace `std`.
|
| 408 |
+
- `{first1 + `N`, result + `N`}` for unary transforms defined in
|
| 409 |
+
namespace `ranges`.
|
| 410 |
+
- `{first1 + `N`, first2 + `N`, result + `N`}` for binary transforms
|
| 411 |
+
defined in namespace `ranges`.
|
| 412 |
+
|
| 413 |
+
*Complexity:* Exactly N applications of `op` or `binary_op`, and any
|
| 414 |
+
projections. This requirement also applies to the overload with an
|
| 415 |
`ExecutionPolicy`.
|
| 416 |
|
| 417 |
+
*Remarks:* `result` may be equal to `first1` or `first2`.
|
|
|
|
| 418 |
|
| 419 |
### Replace <a id="alg.replace">[[alg.replace]]</a>
|
| 420 |
|
| 421 |
``` cpp
|
| 422 |
template<class ForwardIterator, class T>
|
| 423 |
+
constexpr void replace(ForwardIterator first, ForwardIterator last,
|
| 424 |
const T& old_value, const T& new_value);
|
| 425 |
template<class ExecutionPolicy, class ForwardIterator, class T>
|
| 426 |
void replace(ExecutionPolicy&& exec,
|
| 427 |
ForwardIterator first, ForwardIterator last,
|
| 428 |
const T& old_value, const T& new_value);
|
| 429 |
|
| 430 |
template<class ForwardIterator, class Predicate, class T>
|
| 431 |
+
constexpr void replace_if(ForwardIterator first, ForwardIterator last,
|
| 432 |
Predicate pred, const T& new_value);
|
| 433 |
template<class ExecutionPolicy, class ForwardIterator, class Predicate, class T>
|
| 434 |
void replace_if(ExecutionPolicy&& exec,
|
| 435 |
ForwardIterator first, ForwardIterator last,
|
| 436 |
Predicate pred, const T& new_value);
|
| 437 |
+
|
| 438 |
+
template<input_iterator I, sentinel_for<I> S, class T1, class T2, class Proj = identity>
|
| 439 |
+
requires indirectly_writable<I, const T2&> &&
|
| 440 |
+
indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T1*>
|
| 441 |
+
constexpr I
|
| 442 |
+
ranges::replace(I first, S last, const T1& old_value, const T2& new_value, Proj proj = {});
|
| 443 |
+
template<input_range R, class T1, class T2, class Proj = identity>
|
| 444 |
+
requires indirectly_writable<iterator_t<R>, const T2&> &&
|
| 445 |
+
indirect_binary_predicate<ranges::equal_to, projected<iterator_t<R>, Proj>, const T1*>
|
| 446 |
+
constexpr borrowed_iterator_t<R>
|
| 447 |
+
ranges::replace(R&& r, const T1& old_value, const T2& new_value, Proj proj = {});
|
| 448 |
+
template<input_iterator I, sentinel_for<I> S, class T, class Proj = identity,
|
| 449 |
+
indirect_unary_predicate<projected<I, Proj>> Pred>
|
| 450 |
+
requires indirectly_writable<I, const T&>
|
| 451 |
+
constexpr I ranges::replace_if(I first, S last, Pred pred, const T& new_value, Proj proj = {});
|
| 452 |
+
template<input_range R, class T, class Proj = identity,
|
| 453 |
+
indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
|
| 454 |
+
requires indirectly_writable<iterator_t<R>, const T&>
|
| 455 |
+
constexpr borrowed_iterator_t<R>
|
| 456 |
+
ranges::replace_if(R&& r, Pred pred, const T& new_value, Proj proj = {});
|
| 457 |
```
|
| 458 |
|
| 459 |
+
Let E be
|
| 460 |
+
|
| 461 |
+
- `bool(*i == old_value)` for `replace`;
|
| 462 |
+
- `bool(pred(*i))` for `replace_if`;
|
| 463 |
+
- `bool(invoke(proj, *i) == old_value)` for `ranges::replace`;
|
| 464 |
+
- `bool(invoke(pred, invoke(proj, *i)))` for `ranges::replace_if`.
|
| 465 |
+
|
| 466 |
+
*Mandates:* `new_value` is writable [[iterator.requirements.general]] to
|
| 467 |
+
`first`.
|
| 468 |
|
| 469 |
*Effects:* Substitutes elements referred by the iterator `i` in the
|
| 470 |
+
range \[`first`, `last`) with `new_value`, when E is `true`.
|
| 471 |
+
|
| 472 |
+
*Returns:* `last` for the overloads in namespace `ranges`.
|
| 473 |
|
| 474 |
*Complexity:* Exactly `last - first` applications of the corresponding
|
| 475 |
+
predicate and any projection.
|
| 476 |
|
| 477 |
``` cpp
|
| 478 |
template<class InputIterator, class OutputIterator, class T>
|
| 479 |
+
constexpr OutputIterator
|
| 480 |
replace_copy(InputIterator first, InputIterator last,
|
| 481 |
OutputIterator result,
|
| 482 |
const T& old_value, const T& new_value);
|
| 483 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class T>
|
| 484 |
ForwardIterator2
|
|
|
|
| 486 |
ForwardIterator1 first, ForwardIterator1 last,
|
| 487 |
ForwardIterator2 result,
|
| 488 |
const T& old_value, const T& new_value);
|
| 489 |
|
| 490 |
template<class InputIterator, class OutputIterator, class Predicate, class T>
|
| 491 |
+
constexpr OutputIterator
|
| 492 |
replace_copy_if(InputIterator first, InputIterator last,
|
| 493 |
OutputIterator result,
|
| 494 |
Predicate pred, const T& new_value);
|
| 495 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 496 |
class Predicate, class T>
|
| 497 |
ForwardIterator2
|
| 498 |
replace_copy_if(ExecutionPolicy&& exec,
|
| 499 |
ForwardIterator1 first, ForwardIterator1 last,
|
| 500 |
ForwardIterator2 result,
|
| 501 |
Predicate pred, const T& new_value);
|
| 502 |
+
|
| 503 |
+
template<input_iterator I, sentinel_for<I> S, class T1, class T2, output_iterator<const T2&> O,
|
| 504 |
+
class Proj = identity>
|
| 505 |
+
requires indirectly_copyable<I, O> &&
|
| 506 |
+
indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T1*>
|
| 507 |
+
constexpr ranges::replace_copy_result<I, O>
|
| 508 |
+
ranges::replace_copy(I first, S last, O result, const T1& old_value, const T2& new_value,
|
| 509 |
+
Proj proj = {});
|
| 510 |
+
template<input_range R, class T1, class T2, output_iterator<const T2&> O,
|
| 511 |
+
class Proj = identity>
|
| 512 |
+
requires indirectly_copyable<iterator_t<R>, O> &&
|
| 513 |
+
indirect_binary_predicate<ranges::equal_to, projected<iterator_t<R>, Proj>, const T1*>
|
| 514 |
+
constexpr ranges::replace_copy_result<borrowed_iterator_t<R>, O>
|
| 515 |
+
ranges::replace_copy(R&& r, O result, const T1& old_value, const T2& new_value,
|
| 516 |
+
Proj proj = {});
|
| 517 |
+
|
| 518 |
+
template<input_iterator I, sentinel_for<I> S, class T, output_iterator<const T&> O,
|
| 519 |
+
class Proj = identity, indirect_unary_predicate<projected<I, Proj>> Pred>
|
| 520 |
+
requires indirectly_copyable<I, O>
|
| 521 |
+
constexpr ranges::replace_copy_if_result<I, O>
|
| 522 |
+
ranges::replace_copy_if(I first, S last, O result, Pred pred, const T& new_value,
|
| 523 |
+
Proj proj = {});
|
| 524 |
+
template<input_range R, class T, output_iterator<const T&> O, class Proj = identity,
|
| 525 |
+
indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
|
| 526 |
+
requires indirectly_copyable<iterator_t<R>, O>
|
| 527 |
+
constexpr ranges::replace_copy_if_result<borrowed_iterator_t<R>, O>
|
| 528 |
+
ranges::replace_copy_if(R&& r, O result, Pred pred, const T& new_value,
|
| 529 |
+
Proj proj = {});
|
| 530 |
```
|
| 531 |
|
| 532 |
+
Let E be
|
|
|
|
|
|
|
|
|
|
| 533 |
|
| 534 |
+
- `bool(*(first + (i - result)) == old_value)` for `replace_copy`;
|
| 535 |
+
- `bool(pred(*(first + (i - result))))` for `replace_copy_if`;
|
| 536 |
+
- `bool(invoke(proj, *(first + (i - result))) == old_value)` for
|
| 537 |
+
`ranges::replace_copy`;
|
| 538 |
+
- `bool(invoke(pred, invoke(proj, *(first + (i - result)))))` for
|
| 539 |
+
`ranges::replace_copy_if`.
|
| 540 |
|
| 541 |
+
*Mandates:* The results of the expressions `*first` and `new_value` are
|
| 542 |
+
writable [[iterator.requirements.general]] to `result`.
|
| 543 |
+
|
| 544 |
+
*Preconditions:* The ranges \[`first`, `last`) and \[`result`,
|
| 545 |
+
`result + (last - first)`) do not overlap.
|
| 546 |
+
|
| 547 |
+
*Effects:* Assigns through every iterator `i` in the range \[`result`,
|
| 548 |
+
`result + (last - first)`) a new corresponding value
|
| 549 |
+
|
| 550 |
+
- `new_value` if E is `true` or
|
| 551 |
+
- `*(first + (i - result))` otherwise.
|
| 552 |
+
|
| 553 |
+
*Returns:*
|
| 554 |
|
| 555 |
+
- `result + (last - first)` for the overloads in namespace `std`.
|
| 556 |
+
- `{last, result + (last - first)}` for the overloads in namespace
|
| 557 |
+
`ranges`.
|
| 558 |
|
| 559 |
*Complexity:* Exactly `last - first` applications of the corresponding
|
| 560 |
+
predicate and any projection.
|
| 561 |
|
| 562 |
### Fill <a id="alg.fill">[[alg.fill]]</a>
|
| 563 |
|
| 564 |
``` cpp
|
| 565 |
template<class ForwardIterator, class T>
|
| 566 |
+
constexpr void fill(ForwardIterator first, ForwardIterator last, const T& value);
|
| 567 |
template<class ExecutionPolicy, class ForwardIterator, class T>
|
| 568 |
void fill(ExecutionPolicy&& exec,
|
| 569 |
ForwardIterator first, ForwardIterator last, const T& value);
|
| 570 |
|
| 571 |
template<class OutputIterator, class Size, class T>
|
| 572 |
+
constexpr OutputIterator fill_n(OutputIterator first, Size n, const T& value);
|
| 573 |
template<class ExecutionPolicy, class ForwardIterator, class Size, class T>
|
| 574 |
ForwardIterator fill_n(ExecutionPolicy&& exec,
|
| 575 |
ForwardIterator first, Size n, const T& value);
|
| 576 |
+
|
| 577 |
+
|
| 578 |
+
template<class T, output_iterator<const T&> O, sentinel_for<O> S>
|
| 579 |
+
constexpr O ranges::fill(O first, S last, const T& value);
|
| 580 |
+
template<class T, output_range<const T&> R>
|
| 581 |
+
constexpr borrowed_iterator_t<R> ranges::fill(R&& r, const T& value);
|
| 582 |
+
template<class T, output_iterator<const T&> O>
|
| 583 |
+
constexpr O ranges::fill_n(O first, iter_difference_t<O> n, const T& value);
|
| 584 |
```
|
| 585 |
|
| 586 |
+
Let N be max(0, `n`) for the `fill_n` algorithms, and `last - first` for
|
| 587 |
+
the `fill` algorithms.
|
|
|
|
|
|
|
| 588 |
|
| 589 |
+
*Mandates:* The expression `value` is
|
| 590 |
+
writable [[iterator.requirements.general]] to the output iterator. The
|
| 591 |
+
type `Size` is convertible to an integral type ([[conv.integral]],
|
| 592 |
+
[[class.conv]]).
|
| 593 |
|
| 594 |
+
*Effects:* Assigns `value` through all the iterators in the range
|
| 595 |
+
\[`first`, `first + `N).
|
| 596 |
|
| 597 |
+
*Returns:* `first + `N.
|
| 598 |
+
|
| 599 |
+
*Complexity:* Exactly N assignments.
|
| 600 |
|
| 601 |
### Generate <a id="alg.generate">[[alg.generate]]</a>
|
| 602 |
|
| 603 |
``` cpp
|
| 604 |
template<class ForwardIterator, class Generator>
|
| 605 |
+
constexpr void generate(ForwardIterator first, ForwardIterator last,
|
| 606 |
Generator gen);
|
| 607 |
template<class ExecutionPolicy, class ForwardIterator, class Generator>
|
| 608 |
void generate(ExecutionPolicy&& exec,
|
| 609 |
ForwardIterator first, ForwardIterator last,
|
| 610 |
Generator gen);
|
| 611 |
|
| 612 |
template<class OutputIterator, class Size, class Generator>
|
| 613 |
+
constexpr OutputIterator generate_n(OutputIterator first, Size n, Generator gen);
|
| 614 |
template<class ExecutionPolicy, class ForwardIterator, class Size, class Generator>
|
| 615 |
ForwardIterator generate_n(ExecutionPolicy&& exec,
|
| 616 |
ForwardIterator first, Size n, Generator gen);
|
| 617 |
+
|
| 618 |
+
template<input_or_output_iterator O, sentinel_for<O> S, copy_constructible F>
|
| 619 |
+
requires invocable<F&> && indirectly_writable<O, invoke_result_t<F&>>
|
| 620 |
+
constexpr O ranges::generate(O first, S last, F gen);
|
| 621 |
+
template<class R, copy_constructible F>
|
| 622 |
+
requires invocable<F&> && output_range<R, invoke_result_t<F&>>
|
| 623 |
+
constexpr borrowed_iterator_t<R> ranges::generate(R&& r, F gen);
|
| 624 |
+
template<input_or_output_iterator O, copy_constructible F>
|
| 625 |
+
requires invocable<F&> && indirectly_writable<O, invoke_result_t<F&>>
|
| 626 |
+
constexpr O ranges::generate_n(O first, iter_difference_t<O> n, F gen);
|
| 627 |
```
|
| 628 |
|
| 629 |
+
Let N be max(0, `n`) for the `generate_n` algorithms, and `last - first`
|
| 630 |
+
for the `generate` algorithms.
|
| 631 |
|
| 632 |
+
*Mandates:* `Size` is convertible to an integral
|
| 633 |
+
type ([[conv.integral]], [[class.conv]]).
|
|
|
|
|
|
|
|
|
|
|
|
|
| 634 |
|
| 635 |
+
*Effects:* Assigns the result of successive evaluations of `gen()`
|
| 636 |
+
through each iterator in the range \[`first`, `first + `N).
|
| 637 |
|
| 638 |
+
*Returns:* `first + `N.
|
| 639 |
+
|
| 640 |
+
*Complexity:* Exactly N evaluations of `gen()` and assignments.
|
| 641 |
|
| 642 |
### Remove <a id="alg.remove">[[alg.remove]]</a>
|
| 643 |
|
| 644 |
``` cpp
|
| 645 |
template<class ForwardIterator, class T>
|
| 646 |
+
constexpr ForwardIterator remove(ForwardIterator first, ForwardIterator last,
|
| 647 |
const T& value);
|
| 648 |
template<class ExecutionPolicy, class ForwardIterator, class T>
|
| 649 |
ForwardIterator remove(ExecutionPolicy&& exec,
|
| 650 |
ForwardIterator first, ForwardIterator last,
|
| 651 |
const T& value);
|
| 652 |
|
| 653 |
template<class ForwardIterator, class Predicate>
|
| 654 |
+
constexpr ForwardIterator remove_if(ForwardIterator first, ForwardIterator last,
|
| 655 |
Predicate pred);
|
| 656 |
template<class ExecutionPolicy, class ForwardIterator, class Predicate>
|
| 657 |
ForwardIterator remove_if(ExecutionPolicy&& exec,
|
| 658 |
ForwardIterator first, ForwardIterator last,
|
| 659 |
Predicate pred);
|
| 660 |
+
|
| 661 |
+
template<permutable I, sentinel_for<I> S, class T, class Proj = identity>
|
| 662 |
+
requires indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T*>
|
| 663 |
+
constexpr subrange<I> ranges::remove(I first, S last, const T& value, Proj proj = {});
|
| 664 |
+
template<forward_range R, class T, class Proj = identity>
|
| 665 |
+
requires permutable<iterator_t<R>> &&
|
| 666 |
+
indirect_binary_predicate<ranges::equal_to, projected<iterator_t<R>, Proj>, const T*>
|
| 667 |
+
constexpr borrowed_subrange_t<R>
|
| 668 |
+
ranges::remove(R&& r, const T& value, Proj proj = {});
|
| 669 |
+
template<permutable I, sentinel_for<I> S, class Proj = identity,
|
| 670 |
+
indirect_unary_predicate<projected<I, Proj>> Pred>
|
| 671 |
+
constexpr subrange<I> ranges::remove_if(I first, S last, Pred pred, Proj proj = {});
|
| 672 |
+
template<forward_range R, class Proj = identity,
|
| 673 |
+
indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
|
| 674 |
+
requires permutable<iterator_t<R>>
|
| 675 |
+
constexpr borrowed_subrange_t<R>
|
| 676 |
+
ranges::remove_if(R&& r, Pred pred, Proj proj = {});
|
| 677 |
```
|
| 678 |
|
| 679 |
+
Let E be
|
| 680 |
+
|
| 681 |
+
- `bool(*i == value)` for `remove`;
|
| 682 |
+
- `bool(pred(*i))` for `remove_if`;
|
| 683 |
+
- `bool(invoke(proj, *i) == value)` for `ranges::remove`;
|
| 684 |
+
- `bool(invoke(pred, invoke(proj, *i)))` for `ranges::remove_if`.
|
| 685 |
+
|
| 686 |
+
*Preconditions:* For the algorithms in namespace `std`, the type of
|
| 687 |
+
`*first` meets the *Cpp17MoveAssignable* requirements
|
| 688 |
+
([[cpp17.moveassignable]]).
|
| 689 |
|
| 690 |
*Effects:* Eliminates all the elements referred to by iterator `i` in
|
| 691 |
+
the range \[`first`, `last`) for which E holds.
|
|
|
|
| 692 |
|
| 693 |
+
*Returns:* Let j be the end of the resulting range. Returns:
|
| 694 |
|
| 695 |
+
- j for the overloads in namespace `std`.
|
| 696 |
+
- `{`j`, last}` for the overloads in namespace `ranges`.
|
| 697 |
+
|
| 698 |
+
*Remarks:* Stable [[algorithm.stable]].
|
| 699 |
|
| 700 |
*Complexity:* Exactly `last - first` applications of the corresponding
|
| 701 |
+
predicate and any projection.
|
| 702 |
|
| 703 |
[*Note 1*: Each element in the range \[`ret`, `last`), where `ret` is
|
| 704 |
the returned value, has a valid but unspecified state, because the
|
| 705 |
algorithms can eliminate elements by moving from elements that were
|
| 706 |
originally in that range. — *end note*]
|
| 707 |
|
| 708 |
``` cpp
|
| 709 |
template<class InputIterator, class OutputIterator, class T>
|
| 710 |
+
constexpr OutputIterator
|
| 711 |
remove_copy(InputIterator first, InputIterator last,
|
| 712 |
OutputIterator result, const T& value);
|
| 713 |
+
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 714 |
+
class T>
|
| 715 |
ForwardIterator2
|
| 716 |
remove_copy(ExecutionPolicy&& exec,
|
| 717 |
ForwardIterator1 first, ForwardIterator1 last,
|
| 718 |
ForwardIterator2 result, const T& value);
|
| 719 |
|
| 720 |
template<class InputIterator, class OutputIterator, class Predicate>
|
| 721 |
+
constexpr OutputIterator
|
| 722 |
remove_copy_if(InputIterator first, InputIterator last,
|
| 723 |
OutputIterator result, Predicate pred);
|
| 724 |
+
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 725 |
+
class Predicate>
|
| 726 |
ForwardIterator2
|
| 727 |
remove_copy_if(ExecutionPolicy&& exec,
|
| 728 |
ForwardIterator1 first, ForwardIterator1 last,
|
| 729 |
ForwardIterator2 result, Predicate pred);
|
| 730 |
+
|
| 731 |
+
template<input_iterator I, sentinel_for<I> S, weakly_incrementable O, class T,
|
| 732 |
+
class Proj = identity>
|
| 733 |
+
requires indirectly_copyable<I, O> &&
|
| 734 |
+
indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T*>
|
| 735 |
+
constexpr ranges::remove_copy_result<I, O>
|
| 736 |
+
ranges::remove_copy(I first, S last, O result, const T& value, Proj proj = {});
|
| 737 |
+
template<input_range R, weakly_incrementable O, class T, class Proj = identity>
|
| 738 |
+
requires indirectly_copyable<iterator_t<R>, O> &&
|
| 739 |
+
indirect_binary_predicate<ranges::equal_to, projected<iterator_t<R>, Proj>, const T*>
|
| 740 |
+
constexpr ranges::remove_copy_result<borrowed_iterator_t<R>, O>
|
| 741 |
+
ranges::remove_copy(R&& r, O result, const T& value, Proj proj = {});
|
| 742 |
+
template<input_iterator I, sentinel_for<I> S, weakly_incrementable O,
|
| 743 |
+
class Proj = identity, indirect_unary_predicate<projected<I, Proj>> Pred>
|
| 744 |
+
requires indirectly_copyable<I, O>
|
| 745 |
+
constexpr ranges::remove_copy_if_result<I, O>
|
| 746 |
+
ranges::remove_copy_if(I first, S last, O result, Pred pred, Proj proj = {});
|
| 747 |
+
template<input_range R, weakly_incrementable O, class Proj = identity,
|
| 748 |
+
indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
|
| 749 |
+
requires indirectly_copyable<iterator_t<R>, O>
|
| 750 |
+
constexpr ranges::remove_copy_if_result<borrowed_iterator_t<R>, O>
|
| 751 |
+
ranges::remove_copy_if(R&& r, O result, Pred pred, Proj proj = {});
|
| 752 |
```
|
| 753 |
|
| 754 |
+
Let E be
|
| 755 |
+
|
| 756 |
+
- `bool(*i == value)` for `remove_copy`;
|
| 757 |
+
- `bool(pred(*i))` for `remove_copy_if`;
|
| 758 |
+
- `bool(invoke(proj, *i) == value)` for `ranges::remove_copy`;
|
| 759 |
+
- `bool(invoke(pred, invoke(proj, *i)))` for `ranges::remove_copy_if`.
|
| 760 |
+
|
| 761 |
+
Let N be the number of elements in \[`first`, `last`) for which E is
|
| 762 |
+
`false`.
|
| 763 |
+
|
| 764 |
+
*Mandates:* `*first` is writable [[iterator.requirements.general]] to
|
| 765 |
+
`result`.
|
| 766 |
+
|
| 767 |
+
*Preconditions:* The ranges \[`first`, `last`) and \[`result`,
|
| 768 |
+
`result + (last - first)`) do not overlap.
|
| 769 |
|
| 770 |
[*Note 2*: For the overloads with an `ExecutionPolicy`, there may be a
|
| 771 |
+
performance cost if `iterator_traits<ForwardIterator1>::value_type` does
|
| 772 |
+
not meet the *Cpp17MoveConstructible* ([[cpp17.moveconstructible]])
|
| 773 |
+
requirements. — *end note*]
|
| 774 |
|
| 775 |
*Effects:* Copies all the elements referred to by the iterator `i` in
|
| 776 |
+
the range \[`first`, `last`) for which E is `false`.
|
|
|
|
| 777 |
|
| 778 |
+
*Returns:*
|
| 779 |
+
|
| 780 |
+
- `result + `N, for the algorithms in namespace `std`.
|
| 781 |
+
- `{last, result + `N`}`, for the algorithms in namespace `ranges`.
|
| 782 |
|
| 783 |
*Complexity:* Exactly `last - first` applications of the corresponding
|
| 784 |
+
predicate and any projection.
|
| 785 |
|
| 786 |
+
*Remarks:* Stable [[algorithm.stable]].
|
| 787 |
|
| 788 |
### Unique <a id="alg.unique">[[alg.unique]]</a>
|
| 789 |
|
| 790 |
``` cpp
|
| 791 |
template<class ForwardIterator>
|
| 792 |
+
constexpr ForwardIterator unique(ForwardIterator first, ForwardIterator last);
|
| 793 |
template<class ExecutionPolicy, class ForwardIterator>
|
| 794 |
ForwardIterator unique(ExecutionPolicy&& exec,
|
| 795 |
ForwardIterator first, ForwardIterator last);
|
| 796 |
|
| 797 |
template<class ForwardIterator, class BinaryPredicate>
|
| 798 |
+
constexpr ForwardIterator unique(ForwardIterator first, ForwardIterator last,
|
| 799 |
BinaryPredicate pred);
|
| 800 |
template<class ExecutionPolicy, class ForwardIterator, class BinaryPredicate>
|
| 801 |
ForwardIterator unique(ExecutionPolicy&& exec,
|
| 802 |
ForwardIterator first, ForwardIterator last,
|
| 803 |
BinaryPredicate pred);
|
| 804 |
+
|
| 805 |
+
template<permutable I, sentinel_for<I> S, class Proj = identity,
|
| 806 |
+
indirect_equivalence_relation<projected<I, Proj>> C = ranges::equal_to>
|
| 807 |
+
constexpr subrange<I> ranges::unique(I first, S last, C comp = {}, Proj proj = {});
|
| 808 |
+
template<forward_range R, class Proj = identity,
|
| 809 |
+
indirect_equivalence_relation<projected<iterator_t<R>, Proj>> C = ranges::equal_to>
|
| 810 |
+
requires permutable<iterator_t<R>>
|
| 811 |
+
constexpr borrowed_subrange_t<R>
|
| 812 |
+
ranges::unique(R&& r, C comp = {}, Proj proj = {});
|
| 813 |
```
|
| 814 |
|
| 815 |
+
Let `pred` be `equal_to{}` for the overloads with no parameter `pred`,
|
| 816 |
+
and let E be
|
| 817 |
+
|
| 818 |
+
- `bool(pred(*(i - 1), *i))` for the overloads in namespace `std`;
|
| 819 |
+
- `bool(invoke(comp, invoke(proj, *(i - 1)), invoke(proj, *i)))` for the
|
| 820 |
+
overloads in namespace `ranges`.
|
| 821 |
+
|
| 822 |
+
*Preconditions:* For the overloads in namepace `std`, `pred` is an
|
| 823 |
+
equivalence relation and the type of `*first` meets the
|
| 824 |
+
*Cpp17MoveAssignable* requirements ([[cpp17.moveassignable]]).
|
| 825 |
|
| 826 |
*Effects:* For a nonempty range, eliminates all but the first element
|
| 827 |
from every consecutive group of equivalent elements referred to by the
|
| 828 |
+
iterator `i` in the range \[`first + 1`, `last`) for which E is `true`.
|
|
|
|
| 829 |
|
| 830 |
+
*Returns:* Let j be the end of the resulting range. Returns:
|
| 831 |
+
|
| 832 |
+
- j for the overloads in namespace `std`.
|
| 833 |
+
- `{`j`, last}` for the overloads in namespace `ranges`.
|
| 834 |
|
| 835 |
*Complexity:* For nonempty ranges, exactly `(last - first) - 1`
|
| 836 |
+
applications of the corresponding predicate and no more than twice as
|
| 837 |
+
many applications of any projection.
|
| 838 |
|
| 839 |
``` cpp
|
| 840 |
template<class InputIterator, class OutputIterator>
|
| 841 |
+
constexpr OutputIterator
|
| 842 |
unique_copy(InputIterator first, InputIterator last,
|
| 843 |
OutputIterator result);
|
| 844 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 845 |
ForwardIterator2
|
| 846 |
unique_copy(ExecutionPolicy&& exec,
|
| 847 |
ForwardIterator1 first, ForwardIterator1 last,
|
| 848 |
ForwardIterator2 result);
|
| 849 |
|
| 850 |
template<class InputIterator, class OutputIterator,
|
| 851 |
class BinaryPredicate>
|
| 852 |
+
constexpr OutputIterator
|
| 853 |
unique_copy(InputIterator first, InputIterator last,
|
| 854 |
OutputIterator result, BinaryPredicate pred);
|
| 855 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 856 |
class BinaryPredicate>
|
| 857 |
ForwardIterator2
|
| 858 |
unique_copy(ExecutionPolicy&& exec,
|
| 859 |
ForwardIterator1 first, ForwardIterator1 last,
|
| 860 |
ForwardIterator2 result, BinaryPredicate pred);
|
| 861 |
+
|
| 862 |
+
template<input_iterator I, sentinel_for<I> S, weakly_incrementable O, class Proj = identity,
|
| 863 |
+
indirect_equivalence_relation<projected<I, Proj>> C = ranges::equal_to>
|
| 864 |
+
requires indirectly_copyable<I, O> &&
|
| 865 |
+
(forward_iterator<I> ||
|
| 866 |
+
(input_iterator<O> && same_as<iter_value_t<I>, iter_value_t<O>>) ||
|
| 867 |
+
indirectly_copyable_storable<I, O>)
|
| 868 |
+
constexpr ranges::unique_copy_result<I, O>
|
| 869 |
+
ranges::unique_copy(I first, S last, O result, C comp = {}, Proj proj = {});
|
| 870 |
+
template<input_range R, weakly_incrementable O, class Proj = identity,
|
| 871 |
+
indirect_equivalence_relation<projected<iterator_t<R>, Proj>> C = ranges::equal_to>
|
| 872 |
+
requires indirectly_copyable<iterator_t<R>, O> &&
|
| 873 |
+
(forward_iterator<iterator_t<R>> ||
|
| 874 |
+
(input_iterator<O> && same_as<range_value_t<R>, iter_value_t<O>>) ||
|
| 875 |
+
indirectly_copyable_storable<iterator_t<R>, O>)
|
| 876 |
+
constexpr ranges::unique_copy_result<borrowed_iterator_t<R>, O>
|
| 877 |
+
ranges::unique_copy(R&& r, O result, C comp = {}, Proj proj = {});
|
| 878 |
```
|
| 879 |
|
| 880 |
+
Let `pred` be `equal_to{}` for the overloads in namespace `std` with no
|
| 881 |
+
parameter `pred`, and let E be
|
| 882 |
+
|
| 883 |
+
- `bool(pred(*i, *(i - 1)))` for the overloads in namespace `std`;
|
| 884 |
+
- `bool(invoke(comp, invoke(proj, *i), invoke(proj, *(i - 1))))` for the
|
| 885 |
+
overloads in namespace `ranges`.
|
| 886 |
+
|
| 887 |
+
*Mandates:* `*first` is writable [[iterator.requirements.general]] to
|
| 888 |
+
`result`.
|
| 889 |
+
|
| 890 |
+
*Preconditions:*
|
| 891 |
|
|
|
|
| 892 |
- The ranges \[`first`, `last`) and \[`result`, `result+(last-first)`)
|
| 893 |
+
do not overlap.
|
| 894 |
+
- For the overloads in namespace `std`:
|
| 895 |
+
- The comparison function is an equivalence relation.
|
| 896 |
+
- For the overloads with no `ExecutionPolicy`, let `T` be the value
|
| 897 |
+
type of `InputIterator`. If `InputIterator` meets the
|
| 898 |
+
*Cpp17ForwardIterator* requirements, then there are no additional
|
| 899 |
+
requirements for `T`. Otherwise, if `OutputIterator` meets the
|
| 900 |
+
*Cpp17ForwardIterator* requirements and its value type is the same
|
| 901 |
+
as `T`, then `T` meets the *Cpp17CopyAssignable*
|
| 902 |
+
([[cpp17.copyassignable]]) requirements. Otherwise, `T` meets both
|
| 903 |
+
the *Cpp17CopyConstructible* ([[cpp17.copyconstructible]]) and
|
| 904 |
+
*Cpp17CopyAssignable* requirements. \[*Note 1*: For the overloads
|
| 905 |
+
with an `ExecutionPolicy`, there may be a performance cost if the
|
| 906 |
+
value type of `ForwardIterator1` does not meet both the
|
| 907 |
+
*Cpp17CopyConstructible* and *Cpp17CopyAssignable*
|
| 908 |
+
requirements. — *end note*]
|
| 909 |
|
| 910 |
*Effects:* Copies only the first element from every consecutive group of
|
| 911 |
equal elements referred to by the iterator `i` in the range \[`first`,
|
| 912 |
+
`last`) for which E holds.
|
|
|
|
| 913 |
|
| 914 |
+
*Returns:*
|
| 915 |
|
| 916 |
+
- `result + `N for the overloads in namespace `std`.
|
| 917 |
+
- `{last, result + `N`}` for the overloads in namespace `ranges`.
|
| 918 |
+
|
| 919 |
+
*Complexity:* Exactly `last - first - 1` applications of the
|
| 920 |
+
corresponding predicate and no more than twice as many applications of
|
| 921 |
+
any projection.
|
| 922 |
|
| 923 |
### Reverse <a id="alg.reverse">[[alg.reverse]]</a>
|
| 924 |
|
| 925 |
``` cpp
|
| 926 |
template<class BidirectionalIterator>
|
| 927 |
+
constexpr void reverse(BidirectionalIterator first, BidirectionalIterator last);
|
| 928 |
template<class ExecutionPolicy, class BidirectionalIterator>
|
| 929 |
void reverse(ExecutionPolicy&& exec,
|
| 930 |
BidirectionalIterator first, BidirectionalIterator last);
|
| 931 |
+
|
| 932 |
+
template<bidirectional_iterator I, sentinel_for<I> S>
|
| 933 |
+
requires permutable<I>
|
| 934 |
+
constexpr I ranges::reverse(I first, S last);
|
| 935 |
+
template<bidirectional_range R>
|
| 936 |
+
requires permutable<iterator_t<R>>
|
| 937 |
+
constexpr borrowed_iterator_t<R> ranges::reverse(R&& r);
|
| 938 |
```
|
| 939 |
|
| 940 |
+
*Preconditions:* For the overloads in namespace `std`,
|
| 941 |
+
`BidirectionalIterator` meets the *Cpp17ValueSwappable*
|
| 942 |
+
requirements [[swappable.requirements]].
|
| 943 |
|
| 944 |
*Effects:* For each non-negative integer `i < (last - first) / 2`,
|
| 945 |
+
applies `std::iter_swap`, or `ranges::iter_swap` for the overloads in
|
| 946 |
+
namespace `ranges`, to all pairs of iterators
|
| 947 |
`first + i, (last - i) - 1`.
|
| 948 |
|
| 949 |
+
*Returns:* `last` for the overloads in namespace `ranges`.
|
|
|
|
| 950 |
|
| 951 |
*Complexity:* Exactly `(last - first)/2` swaps.
|
| 952 |
|
| 953 |
``` cpp
|
| 954 |
template<class BidirectionalIterator, class OutputIterator>
|
| 955 |
+
constexpr OutputIterator
|
| 956 |
reverse_copy(BidirectionalIterator first, BidirectionalIterator last,
|
| 957 |
OutputIterator result);
|
| 958 |
template<class ExecutionPolicy, class BidirectionalIterator, class ForwardIterator>
|
| 959 |
ForwardIterator
|
| 960 |
reverse_copy(ExecutionPolicy&& exec,
|
| 961 |
BidirectionalIterator first, BidirectionalIterator last,
|
| 962 |
ForwardIterator result);
|
| 963 |
+
|
| 964 |
+
template<bidirectional_iterator I, sentinel_for<I> S, weakly_incrementable O>
|
| 965 |
+
requires indirectly_copyable<I, O>
|
| 966 |
+
constexpr ranges::reverse_copy_result<I, O>
|
| 967 |
+
ranges::reverse_copy(I first, S last, O result);
|
| 968 |
+
template<bidirectional_range R, weakly_incrementable O>
|
| 969 |
+
requires indirectly_copyable<iterator_t<R>, O>
|
| 970 |
+
constexpr ranges::reverse_copy_result<borrowed_iterator_t<R>, O>
|
| 971 |
+
ranges::reverse_copy(R&& r, O result);
|
| 972 |
```
|
| 973 |
|
| 974 |
+
Let N be `last - first`.
|
| 975 |
+
|
| 976 |
+
*Preconditions:* The ranges \[`first`, `last`) and \[`result`,
|
| 977 |
+
`result + `N) do not overlap.
|
| 978 |
|
| 979 |
*Effects:* Copies the range \[`first`, `last`) to the range \[`result`,
|
| 980 |
+
`result + `N) such that for every non-negative integer `i < `N the
|
| 981 |
+
following assignment takes place:
|
| 982 |
+
`*(result + `N` - 1 - i) = *(first + i)`.
|
| 983 |
|
| 984 |
+
*Returns:*
|
| 985 |
|
| 986 |
+
- `result + `N for the overloads in namespace `std`.
|
| 987 |
+
- `{last, result + `N`}` for the overloads in namespace `ranges`.
|
| 988 |
+
|
| 989 |
+
*Complexity:* Exactly N assignments.
|
| 990 |
|
| 991 |
### Rotate <a id="alg.rotate">[[alg.rotate]]</a>
|
| 992 |
|
| 993 |
``` cpp
|
| 994 |
template<class ForwardIterator>
|
| 995 |
+
constexpr ForwardIterator
|
| 996 |
rotate(ForwardIterator first, ForwardIterator middle, ForwardIterator last);
|
| 997 |
template<class ExecutionPolicy, class ForwardIterator>
|
| 998 |
ForwardIterator
|
| 999 |
rotate(ExecutionPolicy&& exec,
|
| 1000 |
ForwardIterator first, ForwardIterator middle, ForwardIterator last);
|
| 1001 |
+
|
| 1002 |
+
template<permutable I, sentinel_for<I> S>
|
| 1003 |
+
constexpr subrange<I> ranges::rotate(I first, I middle, S last);
|
| 1004 |
```
|
| 1005 |
|
| 1006 |
+
*Preconditions:* \[`first`, `middle`) and \[`middle`, `last`) are valid
|
| 1007 |
+
ranges. For the overloads in namespace `std`, `ForwardIterator` meets
|
| 1008 |
+
the *Cpp17ValueSwappable* requirements [[swappable.requirements]], and
|
| 1009 |
+
the type of `*first` meets the *Cpp17MoveConstructible*
|
| 1010 |
+
([[cpp17.moveconstructible]]) and *Cpp17MoveAssignable*
|
| 1011 |
+
([[cpp17.moveassignable]]) requirements.
|
| 1012 |
|
| 1013 |
*Effects:* For each non-negative integer `i < (last - first)`, places
|
| 1014 |
the element from the position `first + i` into position
|
| 1015 |
`first + (i + (last - middle)) % (last - first)`.
|
| 1016 |
|
| 1017 |
+
[*Note 1*: This is a left rotate. — *end note*]
|
| 1018 |
|
| 1019 |
+
*Returns:*
|
| 1020 |
+
|
| 1021 |
+
- `first + (last - middle)` for the overloads in namespace `std`.
|
| 1022 |
+
- `{first + (last - middle), last}` for the overload in namespace
|
| 1023 |
+
`ranges`.
|
| 1024 |
|
| 1025 |
*Complexity:* At most `last - first` swaps.
|
| 1026 |
|
| 1027 |
+
``` cpp
|
| 1028 |
+
template<forward_range R>
|
| 1029 |
+
requires permutable<iterator_t<R>>
|
| 1030 |
+
constexpr borrowed_subrange_t<R> ranges::rotate(R&& r, iterator_t<R> middle);
|
| 1031 |
+
```
|
| 1032 |
+
|
| 1033 |
+
*Effects:* Equivalent to:
|
| 1034 |
+
`return ranges::rotate(ranges::begin(r), middle, ranges::end(r));`
|
| 1035 |
+
|
| 1036 |
``` cpp
|
| 1037 |
template<class ForwardIterator, class OutputIterator>
|
| 1038 |
+
constexpr OutputIterator
|
| 1039 |
rotate_copy(ForwardIterator first, ForwardIterator middle, ForwardIterator last,
|
| 1040 |
OutputIterator result);
|
| 1041 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 1042 |
ForwardIterator2
|
| 1043 |
rotate_copy(ExecutionPolicy&& exec,
|
| 1044 |
ForwardIterator1 first, ForwardIterator1 middle, ForwardIterator1 last,
|
| 1045 |
ForwardIterator2 result);
|
| 1046 |
+
|
| 1047 |
+
template<forward_iterator I, sentinel_for<I> S, weakly_incrementable O>
|
| 1048 |
+
requires indirectly_copyable<I, O>
|
| 1049 |
+
constexpr ranges::rotate_copy_result<I, O>
|
| 1050 |
+
ranges::rotate_copy(I first, I middle, S last, O result);
|
| 1051 |
```
|
| 1052 |
|
| 1053 |
+
Let N be `last - first`.
|
| 1054 |
+
|
| 1055 |
+
*Preconditions:* \[`first`, `middle`) and \[`middle`, `last`) are valid
|
| 1056 |
+
ranges. The ranges \[`first`, `last`) and \[`result`, `result + `N) do
|
| 1057 |
+
not overlap.
|
| 1058 |
|
| 1059 |
*Effects:* Copies the range \[`first`, `last`) to the range \[`result`,
|
| 1060 |
+
`result + `N) such that for each non-negative integer i < N the
|
| 1061 |
+
following assignment takes place:
|
| 1062 |
+
`*(result + `i`) = *(first + (`i` + (middle - first)) % `N`)`.
|
| 1063 |
|
| 1064 |
+
*Returns:*
|
| 1065 |
|
| 1066 |
+
- `result + `N for the overloads in namespace `std`.
|
| 1067 |
+
- `{last, result + `N`}` for the overload in namespace `ranges`.
|
| 1068 |
+
|
| 1069 |
+
*Complexity:* Exactly N assignments.
|
| 1070 |
+
|
| 1071 |
+
``` cpp
|
| 1072 |
+
template<forward_range R, weakly_incrementable O>
|
| 1073 |
+
requires indirectly_copyable<iterator_t<R>, O>
|
| 1074 |
+
constexpr ranges::rotate_copy_result<borrowed_iterator_t<R>, O>
|
| 1075 |
+
ranges::rotate_copy(R&& r, iterator_t<R> middle, O result);
|
| 1076 |
+
```
|
| 1077 |
+
|
| 1078 |
+
*Effects:* Equivalent to:
|
| 1079 |
+
|
| 1080 |
+
``` cpp
|
| 1081 |
+
return ranges::rotate_copy(ranges::begin(r), middle, ranges::end(r), result);
|
| 1082 |
+
```
|
| 1083 |
|
| 1084 |
### Sample <a id="alg.random.sample">[[alg.random.sample]]</a>
|
| 1085 |
|
| 1086 |
``` cpp
|
| 1087 |
template<class PopulationIterator, class SampleIterator,
|
| 1088 |
class Distance, class UniformRandomBitGenerator>
|
| 1089 |
SampleIterator sample(PopulationIterator first, PopulationIterator last,
|
| 1090 |
SampleIterator out, Distance n,
|
| 1091 |
UniformRandomBitGenerator&& g);
|
| 1092 |
+
|
| 1093 |
+
template<input_iterator I, sentinel_for<I> S, weakly_incrementable O, class Gen>
|
| 1094 |
+
requires (forward_iterator<I> || random_access_iterator<O>) &&
|
| 1095 |
+
indirectly_copyable<I, O> &&
|
| 1096 |
+
uniform_random_bit_generator<remove_reference_t<Gen>>
|
| 1097 |
+
O ranges::sample(I first, S last, O out, iter_difference_t<I> n, Gen&& g);
|
| 1098 |
+
template<input_range R, weakly_incrementable O, class Gen>
|
| 1099 |
+
requires (forward_range<R> || random_access_iterator<O>) &&
|
| 1100 |
+
indirectly_copyable<iterator_t<R>, O> &&
|
| 1101 |
+
uniform_random_bit_generator<remove_reference_t<Gen>>
|
| 1102 |
+
O ranges::sample(R&& r, O out, range_difference_t<R> n, Gen&& g);
|
| 1103 |
```
|
| 1104 |
|
| 1105 |
+
*Mandates:* For the overload in namespace `std`, `Distance` is an
|
| 1106 |
+
integer type and `*first` is writable [[iterator.requirements.general]]
|
| 1107 |
+
to `out`.
|
| 1108 |
|
| 1109 |
+
*Preconditions:* `out` is not in the range \[`first`, `last`). For the
|
| 1110 |
+
overload in namespace `std`:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1111 |
|
| 1112 |
+
- `PopulationIterator` meets the *Cpp17InputIterator*
|
| 1113 |
+
requirements [[input.iterators]].
|
| 1114 |
+
- `SampleIterator` meets the *Cpp17OutputIterator*
|
| 1115 |
+
requirements [[output.iterators]].
|
| 1116 |
+
- `SampleIterator` meets the *Cpp17RandomAccessIterator*
|
| 1117 |
+
requirements [[random.access.iterators]] unless `PopulationIterator`
|
| 1118 |
+
meets the *Cpp17ForwardIterator* requirements [[forward.iterators]].
|
| 1119 |
+
- `remove_reference_t<UniformRandomBitGenerator>` meets the requirements
|
| 1120 |
+
of a uniform random bit generator type [[rand.req.urng]].
|
| 1121 |
+
|
| 1122 |
+
*Effects:* Copies min(`last - first`, `n`) elements (the *sample*) from
|
| 1123 |
\[`first`, `last`) (the *population*) to `out` such that each possible
|
| 1124 |
sample has equal probability of appearance.
|
| 1125 |
|
| 1126 |
[*Note 1*: Algorithms that obtain such effects include *selection
|
| 1127 |
sampling* and *reservoir sampling*. — *end note*]
|
|
|
|
| 1130 |
|
| 1131 |
*Complexity:* 𝑂(`last - first`).
|
| 1132 |
|
| 1133 |
*Remarks:*
|
| 1134 |
|
| 1135 |
+
- For the overload in namespace `std`, stable if and only if
|
| 1136 |
+
`PopulationIterator` meets the *Cpp17ForwardIterator* requirements.
|
| 1137 |
+
For the first overload in namespace `ranges`, stable if and only if
|
| 1138 |
+
`I` models `forward_iterator`.
|
| 1139 |
- To the extent that the implementation of this function makes use of
|
| 1140 |
+
random numbers, the object `g` serves as the implementation’s source
|
| 1141 |
+
of randomness.
|
| 1142 |
|
| 1143 |
### Shuffle <a id="alg.random.shuffle">[[alg.random.shuffle]]</a>
|
| 1144 |
|
| 1145 |
``` cpp
|
| 1146 |
template<class RandomAccessIterator, class UniformRandomBitGenerator>
|
| 1147 |
void shuffle(RandomAccessIterator first,
|
| 1148 |
RandomAccessIterator last,
|
| 1149 |
UniformRandomBitGenerator&& g);
|
| 1150 |
+
|
| 1151 |
+
template<random_access_iterator I, sentinel_for<I> S, class Gen>
|
| 1152 |
+
requires permutable<I> &&
|
| 1153 |
+
uniform_random_bit_generator<remove_reference_t<Gen>>
|
| 1154 |
+
I ranges::shuffle(I first, S last, Gen&& g);
|
| 1155 |
+
template<random_access_range R, class Gen>
|
| 1156 |
+
requires permutable<iterator_t<R>> &&
|
| 1157 |
+
uniform_random_bit_generator<remove_reference_t<Gen>>
|
| 1158 |
+
borrowed_iterator_t<R> ranges::shuffle(R&& r, Gen&& g);
|
| 1159 |
```
|
| 1160 |
|
| 1161 |
+
*Preconditions:* For the overload in namespace `std`:
|
| 1162 |
+
|
| 1163 |
+
- `RandomAccessIterator` meets the *Cpp17ValueSwappable*
|
| 1164 |
+
requirements [[swappable.requirements]].
|
| 1165 |
+
- The type `remove_reference_t<UniformRandomBitGenerator>` meets the
|
| 1166 |
+
uniform random bit generator [[rand.req.urng]] requirements.
|
| 1167 |
|
| 1168 |
*Effects:* Permutes the elements in the range \[`first`, `last`) such
|
| 1169 |
that each possible permutation of those elements has equal probability
|
| 1170 |
of appearance.
|
| 1171 |
|
| 1172 |
+
*Returns:* `last` for the overloads in namespace `ranges`.
|
| 1173 |
+
|
| 1174 |
*Complexity:* Exactly `(last - first) - 1` swaps.
|
| 1175 |
|
| 1176 |
*Remarks:* To the extent that the implementation of this function makes
|
| 1177 |
+
use of random numbers, the object referenced by `g` shall serve as the
|
| 1178 |
implementation’s source of randomness.
|
| 1179 |
|
| 1180 |
+
### Shift <a id="alg.shift">[[alg.shift]]</a>
|
| 1181 |
+
|
| 1182 |
+
``` cpp
|
| 1183 |
+
template<class ForwardIterator>
|
| 1184 |
+
constexpr ForwardIterator
|
| 1185 |
+
shift_left(ForwardIterator first, ForwardIterator last,
|
| 1186 |
+
typename iterator_traits<ForwardIterator>::difference_type n);
|
| 1187 |
+
template<class ExecutionPolicy, class ForwardIterator>
|
| 1188 |
+
ForwardIterator
|
| 1189 |
+
shift_left(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last,
|
| 1190 |
+
typename iterator_traits<ForwardIterator>::difference_type n);
|
| 1191 |
+
```
|
| 1192 |
+
|
| 1193 |
+
*Preconditions:* `n >= 0` is `true`. The type of `*first` meets the
|
| 1194 |
+
*Cpp17MoveAssignable* requirements.
|
| 1195 |
+
|
| 1196 |
+
*Effects:* If `n == 0` or `n >= last - first`, does nothing. Otherwise,
|
| 1197 |
+
moves the element from position `first + n + i` into position
|
| 1198 |
+
`first + i` for each non-negative integer `i < (last - first) - n`. In
|
| 1199 |
+
the first overload case, does so in order starting from `i = 0` and
|
| 1200 |
+
proceeding to `i = (last - first) - n - 1`.
|
| 1201 |
+
|
| 1202 |
+
*Returns:* `first + (last - first - n)` if `n < last - first`, otherwise
|
| 1203 |
+
`first`.
|
| 1204 |
+
|
| 1205 |
+
*Complexity:* At most `(last - first) - n` assignments.
|
| 1206 |
+
|
| 1207 |
+
``` cpp
|
| 1208 |
+
template<class ForwardIterator>
|
| 1209 |
+
constexpr ForwardIterator
|
| 1210 |
+
shift_right(ForwardIterator first, ForwardIterator last,
|
| 1211 |
+
typename iterator_traits<ForwardIterator>::difference_type n);
|
| 1212 |
+
template<class ExecutionPolicy, class ForwardIterator>
|
| 1213 |
+
ForwardIterator
|
| 1214 |
+
shift_right(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last,
|
| 1215 |
+
typename iterator_traits<ForwardIterator>::difference_type n);
|
| 1216 |
+
```
|
| 1217 |
+
|
| 1218 |
+
*Preconditions:* `n >= 0` is `true`. The type of `*first` meets the
|
| 1219 |
+
*Cpp17MoveAssignable* requirements. `ForwardIterator` meets the
|
| 1220 |
+
*Cpp17BidirectionalIterator* requirements [[bidirectional.iterators]] or
|
| 1221 |
+
the *Cpp17ValueSwappable* requirements.
|
| 1222 |
+
|
| 1223 |
+
*Effects:* If `n == 0` or `n >= last - first`, does nothing. Otherwise,
|
| 1224 |
+
moves the element from position `first + i` into position
|
| 1225 |
+
`first + n + i` for each non-negative integer `i < (last - first) - n`.
|
| 1226 |
+
In the first overload case, if `ForwardIterator` meets the
|
| 1227 |
+
*Cpp17BidirectionalIterator* requirements, does so in order starting
|
| 1228 |
+
from `i = (last - first) - n - 1` and proceeding to `i = 0`.
|
| 1229 |
+
|
| 1230 |
+
*Returns:* `first + n` if `n < last - first`, otherwise `last`.
|
| 1231 |
+
|
| 1232 |
+
*Complexity:* At most `(last - first) - n` assignments or swaps.
|
| 1233 |
+
|