- tmp/tmppxab2jzq/{from.md → to.md} +501 -156
tmp/tmppxab2jzq/{from.md → to.md}
RENAMED
|
@@ -1,75 +1,114 @@
|
|
| 1 |
## Non-modifying sequence operations <a id="alg.nonmodifying">[[alg.nonmodifying]]</a>
|
| 2 |
|
| 3 |
-
### All of <a id="alg.
|
| 4 |
|
| 5 |
``` cpp
|
| 6 |
template<class InputIterator, class Predicate>
|
| 7 |
-
bool all_of(InputIterator first, InputIterator last, Predicate pred);
|
| 8 |
template<class ExecutionPolicy, class ForwardIterator, class Predicate>
|
| 9 |
bool all_of(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last,
|
| 10 |
Predicate pred);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
```
|
| 12 |
|
| 13 |
-
|
| 14 |
-
`true` for every iterator `i` in the range \[`first`, `last`), and
|
| 15 |
-
`false` otherwise.
|
| 16 |
|
| 17 |
-
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
``` cpp
|
| 22 |
template<class InputIterator, class Predicate>
|
| 23 |
-
bool any_of(InputIterator first, InputIterator last, Predicate pred);
|
| 24 |
template<class ExecutionPolicy, class ForwardIterator, class Predicate>
|
| 25 |
bool any_of(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last,
|
| 26 |
Predicate pred);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
```
|
| 28 |
|
| 29 |
-
|
| 30 |
-
iterator `i` in the range \[`first`, `last`) such that `pred(*i)` is
|
| 31 |
-
`true`, and `true` otherwise.
|
| 32 |
|
| 33 |
-
|
|
|
|
|
|
|
| 34 |
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
``` cpp
|
| 38 |
template<class InputIterator, class Predicate>
|
| 39 |
-
bool none_of(InputIterator first, InputIterator last, Predicate pred);
|
| 40 |
template<class ExecutionPolicy, class ForwardIterator, class Predicate>
|
| 41 |
bool none_of(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last,
|
| 42 |
Predicate pred);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
```
|
| 44 |
|
| 45 |
-
|
| 46 |
-
`false` for every iterator `i` in the range \[`first`, `last`), and
|
| 47 |
-
`false` otherwise.
|
| 48 |
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
### For each <a id="alg.foreach">[[alg.foreach]]</a>
|
| 52 |
|
| 53 |
``` cpp
|
| 54 |
template<class InputIterator, class Function>
|
| 55 |
-
Function for_each(InputIterator first, InputIterator last, Function f);
|
| 56 |
```
|
| 57 |
|
| 58 |
-
*
|
| 59 |
-
|
| 60 |
|
| 61 |
[*Note 1*: `Function` need not meet the requirements of
|
| 62 |
-
|
| 63 |
|
| 64 |
*Effects:* Applies `f` to the result of dereferencing every iterator in
|
| 65 |
the range \[`first`, `last`), starting from `first` and proceeding to
|
| 66 |
`last - 1`.
|
| 67 |
|
| 68 |
-
[*Note 2*: If the type of `first`
|
| 69 |
-
|
| 70 |
-
|
| 71 |
|
| 72 |
*Returns:* `f`.
|
| 73 |
|
| 74 |
*Complexity:* Applies `f` exactly `last - first` times.
|
| 75 |
|
|
@@ -80,19 +119,19 @@ template<class ExecutionPolicy, class ForwardIterator, class Function>
|
|
| 80 |
void for_each(ExecutionPolicy&& exec,
|
| 81 |
ForwardIterator first, ForwardIterator last,
|
| 82 |
Function f);
|
| 83 |
```
|
| 84 |
|
| 85 |
-
*
|
| 86 |
-
|
| 87 |
|
| 88 |
*Effects:* Applies `f` to the result of dereferencing every iterator in
|
| 89 |
the range \[`first`, `last`).
|
| 90 |
|
| 91 |
-
[*Note 3*: If the type of `first`
|
| 92 |
-
|
| 93 |
-
|
| 94 |
|
| 95 |
*Complexity:* Applies `f` exactly `last - first` times.
|
| 96 |
|
| 97 |
*Remarks:* If `f` returns a result, the result is ignored.
|
| 98 |
Implementations do not have the freedom granted under
|
|
@@ -101,29 +140,59 @@ the input sequence.
|
|
| 101 |
|
| 102 |
[*Note 4*: Does not return a copy of its `Function` parameter, since
|
| 103 |
parallelization may not permit efficient state
|
| 104 |
accumulation. — *end note*]
|
| 105 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
``` cpp
|
| 107 |
template<class InputIterator, class Size, class Function>
|
| 108 |
-
InputIterator for_each_n(InputIterator first, Size n, Function f);
|
| 109 |
```
|
| 110 |
|
| 111 |
-
*
|
| 112 |
-
|
| 113 |
|
| 114 |
-
|
| 115 |
-
|
| 116 |
|
| 117 |
-
*
|
|
|
|
|
|
|
|
|
|
| 118 |
|
| 119 |
*Effects:* Applies `f` to the result of dereferencing every iterator in
|
| 120 |
the range \[`first`, `first + n`) in order.
|
| 121 |
|
| 122 |
-
[*Note
|
| 123 |
-
|
| 124 |
-
|
| 125 |
|
| 126 |
*Returns:* `first + n`.
|
| 127 |
|
| 128 |
*Remarks:* If `f` returns a result, the result is ignored.
|
| 129 |
|
|
@@ -131,350 +200,540 @@ dereferenced iterator. — *end note*]
|
|
| 131 |
template<class ExecutionPolicy, class ForwardIterator, class Size, class Function>
|
| 132 |
ForwardIterator for_each_n(ExecutionPolicy&& exec, ForwardIterator first, Size n,
|
| 133 |
Function f);
|
| 134 |
```
|
| 135 |
|
| 136 |
-
*
|
| 137 |
-
|
| 138 |
|
| 139 |
-
*
|
|
|
|
|
|
|
|
|
|
| 140 |
|
| 141 |
*Effects:* Applies `f` to the result of dereferencing every iterator in
|
| 142 |
the range \[`first`, `first + n`).
|
| 143 |
|
| 144 |
-
[*Note
|
| 145 |
-
|
| 146 |
-
|
| 147 |
|
| 148 |
*Returns:* `first + n`.
|
| 149 |
|
| 150 |
*Remarks:* If `f` returns a result, the result is ignored.
|
| 151 |
Implementations do not have the freedom granted under
|
| 152 |
[[algorithms.parallel.exec]] to make arbitrary copies of elements from
|
| 153 |
the input sequence.
|
| 154 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
### Find <a id="alg.find">[[alg.find]]</a>
|
| 156 |
|
| 157 |
``` cpp
|
| 158 |
template<class InputIterator, class T>
|
| 159 |
-
InputIterator find(InputIterator first, InputIterator last,
|
| 160 |
const T& value);
|
| 161 |
template<class ExecutionPolicy, class ForwardIterator, class T>
|
| 162 |
ForwardIterator find(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last,
|
| 163 |
const T& value);
|
| 164 |
|
| 165 |
template<class InputIterator, class Predicate>
|
| 166 |
-
InputIterator find_if(InputIterator first, InputIterator last,
|
| 167 |
Predicate pred);
|
| 168 |
template<class ExecutionPolicy, class ForwardIterator, class Predicate>
|
| 169 |
ForwardIterator find_if(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last,
|
| 170 |
Predicate pred);
|
| 171 |
|
| 172 |
template<class InputIterator, class Predicate>
|
| 173 |
-
InputIterator find_if_not(InputIterator first, InputIterator last,
|
| 174 |
Predicate pred);
|
| 175 |
template<class ExecutionPolicy, class ForwardIterator, class Predicate>
|
| 176 |
-
ForwardIterator find_if_not(ExecutionPolicy&& exec,
|
|
|
|
| 177 |
Predicate pred);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
```
|
| 179 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
*Returns:* The first iterator `i` in the range \[`first`, `last`) for
|
| 181 |
-
which
|
| 182 |
-
`pred(*i) != false`, `pred(*i) == false`. Returns `last` if no such
|
| 183 |
-
iterator is found.
|
| 184 |
|
| 185 |
*Complexity:* At most `last - first` applications of the corresponding
|
| 186 |
-
predicate.
|
| 187 |
|
| 188 |
### Find end <a id="alg.find.end">[[alg.find.end]]</a>
|
| 189 |
|
| 190 |
``` cpp
|
| 191 |
template<class ForwardIterator1, class ForwardIterator2>
|
| 192 |
-
ForwardIterator1
|
| 193 |
find_end(ForwardIterator1 first1, ForwardIterator1 last1,
|
| 194 |
ForwardIterator2 first2, ForwardIterator2 last2);
|
| 195 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 196 |
ForwardIterator1
|
| 197 |
find_end(ExecutionPolicy&& exec,
|
| 198 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 199 |
ForwardIterator2 first2, ForwardIterator2 last2);
|
| 200 |
|
| 201 |
template<class ForwardIterator1, class ForwardIterator2,
|
| 202 |
class BinaryPredicate>
|
| 203 |
-
ForwardIterator1
|
| 204 |
find_end(ForwardIterator1 first1, ForwardIterator1 last1,
|
| 205 |
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 206 |
BinaryPredicate pred);
|
| 207 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 208 |
class BinaryPredicate>
|
| 209 |
ForwardIterator1
|
| 210 |
find_end(ExecutionPolicy&& exec,
|
| 211 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 212 |
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 213 |
BinaryPredicate pred);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 214 |
```
|
| 215 |
|
| 216 |
-
|
| 217 |
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
`
|
| 221 |
-
`
|
| 222 |
-
|
| 223 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 224 |
|
| 225 |
*Complexity:* At most
|
| 226 |
`(last2 - first2) * (last1 - first1 - (last2 - first2) + 1)`
|
| 227 |
-
applications of the corresponding predicate.
|
| 228 |
|
| 229 |
### Find first <a id="alg.find.first.of">[[alg.find.first.of]]</a>
|
| 230 |
|
| 231 |
``` cpp
|
| 232 |
template<class InputIterator, class ForwardIterator>
|
| 233 |
-
InputIterator
|
| 234 |
find_first_of(InputIterator first1, InputIterator last1,
|
| 235 |
ForwardIterator first2, ForwardIterator last2);
|
| 236 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 237 |
ForwardIterator1
|
| 238 |
find_first_of(ExecutionPolicy&& exec,
|
| 239 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 240 |
ForwardIterator2 first2, ForwardIterator2 last2);
|
| 241 |
|
| 242 |
template<class InputIterator, class ForwardIterator,
|
| 243 |
class BinaryPredicate>
|
| 244 |
-
InputIterator
|
| 245 |
find_first_of(InputIterator first1, InputIterator last1,
|
| 246 |
ForwardIterator first2, ForwardIterator last2,
|
| 247 |
BinaryPredicate pred);
|
| 248 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 249 |
class BinaryPredicate>
|
| 250 |
ForwardIterator1
|
| 251 |
find_first_of(ExecutionPolicy&& exec,
|
| 252 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 253 |
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 254 |
BinaryPredicate pred);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 255 |
```
|
| 256 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 257 |
*Effects:* Finds an element that matches one of a set of values.
|
| 258 |
|
| 259 |
*Returns:* The first iterator `i` in the range \[`first1`, `last1`) such
|
| 260 |
-
that for some iterator `j` in the range \[`first2`, `last2`)
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
found.
|
| 264 |
|
| 265 |
*Complexity:* At most `(last1-first1) * (last2-first2)` applications of
|
| 266 |
-
the corresponding predicate.
|
| 267 |
|
| 268 |
### Adjacent find <a id="alg.adjacent.find">[[alg.adjacent.find]]</a>
|
| 269 |
|
| 270 |
``` cpp
|
| 271 |
template<class ForwardIterator>
|
| 272 |
-
|
|
|
|
| 273 |
template<class ExecutionPolicy, class ForwardIterator>
|
| 274 |
-
ForwardIterator
|
|
|
|
| 275 |
ForwardIterator first, ForwardIterator last);
|
| 276 |
|
| 277 |
template<class ForwardIterator, class BinaryPredicate>
|
| 278 |
-
|
|
|
|
| 279 |
BinaryPredicate pred);
|
| 280 |
template<class ExecutionPolicy, class ForwardIterator, class BinaryPredicate>
|
| 281 |
-
ForwardIterator
|
|
|
|
| 282 |
ForwardIterator first, ForwardIterator last,
|
| 283 |
BinaryPredicate pred);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 284 |
```
|
| 285 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 286 |
*Returns:* The first iterator `i` such that both `i` and `i + 1` are in
|
| 287 |
-
the range \[`first`, `last`) for which
|
| 288 |
-
|
| 289 |
-
`last` if no such iterator is found.
|
| 290 |
|
| 291 |
*Complexity:* For the overloads with no `ExecutionPolicy`, exactly
|
| 292 |
-
|
| 293 |
-
corresponding predicate, where `i` is
|
| 294 |
-
For the overloads with an
|
| 295 |
-
applications of the corresponding
|
|
|
|
|
|
|
| 296 |
|
| 297 |
### Count <a id="alg.count">[[alg.count]]</a>
|
| 298 |
|
| 299 |
``` cpp
|
| 300 |
template<class InputIterator, class T>
|
| 301 |
-
typename iterator_traits<InputIterator>::difference_type
|
| 302 |
count(InputIterator first, InputIterator last, const T& value);
|
| 303 |
template<class ExecutionPolicy, class ForwardIterator, class T>
|
| 304 |
typename iterator_traits<ForwardIterator>::difference_type
|
| 305 |
-
count(ExecutionPolicy&& exec,
|
|
|
|
| 306 |
|
| 307 |
template<class InputIterator, class Predicate>
|
| 308 |
-
typename iterator_traits<InputIterator>::difference_type
|
| 309 |
count_if(InputIterator first, InputIterator last, Predicate pred);
|
| 310 |
template<class ExecutionPolicy, class ForwardIterator, class Predicate>
|
| 311 |
typename iterator_traits<ForwardIterator>::difference_type
|
| 312 |
-
count_if(ExecutionPolicy&& exec,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 313 |
```
|
| 314 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 315 |
*Effects:* Returns the number of iterators `i` in the range \[`first`,
|
| 316 |
-
`last`) for which
|
| 317 |
-
`*i == value, pred(*i) != false`.
|
| 318 |
|
| 319 |
*Complexity:* Exactly `last - first` applications of the corresponding
|
| 320 |
-
predicate.
|
| 321 |
|
| 322 |
### Mismatch <a id="mismatch">[[mismatch]]</a>
|
| 323 |
|
| 324 |
``` cpp
|
| 325 |
template<class InputIterator1, class InputIterator2>
|
| 326 |
-
pair<InputIterator1, InputIterator2>
|
| 327 |
mismatch(InputIterator1 first1, InputIterator1 last1,
|
| 328 |
InputIterator2 first2);
|
| 329 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 330 |
pair<ForwardIterator1, ForwardIterator2>
|
| 331 |
mismatch(ExecutionPolicy&& exec,
|
| 332 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 333 |
ForwardIterator2 first2);
|
| 334 |
|
| 335 |
template<class InputIterator1, class InputIterator2,
|
| 336 |
class BinaryPredicate>
|
| 337 |
-
pair<InputIterator1, InputIterator2>
|
| 338 |
mismatch(InputIterator1 first1, InputIterator1 last1,
|
| 339 |
InputIterator2 first2, BinaryPredicate pred);
|
| 340 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 341 |
class BinaryPredicate>
|
| 342 |
pair<ForwardIterator1, ForwardIterator2>
|
| 343 |
mismatch(ExecutionPolicy&& exec,
|
| 344 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 345 |
ForwardIterator2 first2, BinaryPredicate pred);
|
| 346 |
|
| 347 |
template<class InputIterator1, class InputIterator2>
|
| 348 |
-
pair<InputIterator1, InputIterator2>
|
| 349 |
mismatch(InputIterator1 first1, InputIterator1 last1,
|
| 350 |
InputIterator2 first2, InputIterator2 last2);
|
| 351 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 352 |
pair<ForwardIterator1, ForwardIterator2>
|
| 353 |
mismatch(ExecutionPolicy&& exec,
|
| 354 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 355 |
ForwardIterator2 first2, ForwardIterator2 last2);
|
| 356 |
|
| 357 |
template<class InputIterator1, class InputIterator2,
|
| 358 |
class BinaryPredicate>
|
| 359 |
-
pair<InputIterator1, InputIterator2>
|
| 360 |
mismatch(InputIterator1 first1, InputIterator1 last1,
|
| 361 |
InputIterator2 first2, InputIterator2 last2,
|
| 362 |
BinaryPredicate pred);
|
| 363 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 364 |
class BinaryPredicate>
|
| 365 |
pair<ForwardIterator1, ForwardIterator2>
|
| 366 |
mismatch(ExecutionPolicy&& exec,
|
| 367 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 368 |
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 369 |
BinaryPredicate pred);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 370 |
```
|
| 371 |
|
| 372 |
-
|
| 373 |
-
`
|
| 374 |
|
| 375 |
-
|
| 376 |
-
is the smallest integer such that, respectively,
|
| 377 |
|
| 378 |
-
- `!(*(first1 + n) == *(first2 + n))`
|
| 379 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 380 |
|
| 381 |
-
|
| 382 |
|
| 383 |
-
*
|
| 384 |
-
|
|
|
|
|
|
|
|
|
|
| 385 |
|
| 386 |
### Equal <a id="alg.equal">[[alg.equal]]</a>
|
| 387 |
|
| 388 |
``` cpp
|
| 389 |
template<class InputIterator1, class InputIterator2>
|
| 390 |
-
bool equal(InputIterator1 first1, InputIterator1 last1,
|
| 391 |
InputIterator2 first2);
|
| 392 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 393 |
bool equal(ExecutionPolicy&& exec,
|
| 394 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 395 |
ForwardIterator2 first2);
|
| 396 |
|
| 397 |
template<class InputIterator1, class InputIterator2,
|
| 398 |
class BinaryPredicate>
|
| 399 |
-
bool equal(InputIterator1 first1, InputIterator1 last1,
|
| 400 |
InputIterator2 first2, BinaryPredicate pred);
|
| 401 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 402 |
class BinaryPredicate>
|
| 403 |
bool equal(ExecutionPolicy&& exec,
|
| 404 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 405 |
ForwardIterator2 first2, BinaryPredicate pred);
|
| 406 |
|
| 407 |
template<class InputIterator1, class InputIterator2>
|
| 408 |
-
bool equal(InputIterator1 first1, InputIterator1 last1,
|
| 409 |
InputIterator2 first2, InputIterator2 last2);
|
| 410 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 411 |
bool equal(ExecutionPolicy&& exec,
|
| 412 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 413 |
ForwardIterator2 first2, ForwardIterator2 last2);
|
| 414 |
|
| 415 |
template<class InputIterator1, class InputIterator2,
|
| 416 |
class BinaryPredicate>
|
| 417 |
-
bool equal(InputIterator1 first1, InputIterator1 last1,
|
| 418 |
InputIterator2 first2, InputIterator2 last2,
|
| 419 |
BinaryPredicate pred);
|
| 420 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 421 |
class BinaryPredicate>
|
| 422 |
bool equal(ExecutionPolicy&& exec,
|
| 423 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 424 |
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 425 |
BinaryPredicate pred);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 426 |
```
|
| 427 |
|
| 428 |
-
|
| 429 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 430 |
|
| 431 |
*Returns:* If `last1 - first1 != last2 - first2`, return `false`.
|
| 432 |
-
Otherwise return `true` if for every iterator `i` in the range
|
| 433 |
-
\[`first1`, `last1`)
|
| 434 |
-
`*i == *(first2 + (i - first1)), pred(*i, *(first2 + (i - first1))) != false`.
|
| 435 |
-
Otherwise, returns `false`.
|
| 436 |
|
| 437 |
-
*Complexity:*
|
| 438 |
|
| 439 |
-
-
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
|
| 443 |
-
|
| 444 |
-
- at most min(`last1 - first1`, `last2 - first2`) applications of the
|
| 445 |
-
corresponding predicate.
|
| 446 |
-
- For the overloads with no `ExecutionPolicy`,
|
| 447 |
-
- if `ForwardIterator1` and `ForwardIterator2` meet the requirements
|
| 448 |
-
of random access iterators and `last1 - first1 != last2 - first2`,
|
| 449 |
-
then no applications of the corresponding predicate; otherwise,
|
| 450 |
-
- 𝑂(min(`last1 - first1`, `last2 - first2`)) applications of the
|
| 451 |
-
corresponding predicate.
|
| 452 |
|
| 453 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 454 |
|
| 455 |
``` cpp
|
| 456 |
template<class ForwardIterator1, class ForwardIterator2>
|
| 457 |
-
bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
|
| 458 |
ForwardIterator2 first2);
|
| 459 |
template<class ForwardIterator1, class ForwardIterator2,
|
| 460 |
class BinaryPredicate>
|
| 461 |
-
bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
|
| 462 |
ForwardIterator2 first2, BinaryPredicate pred);
|
| 463 |
template<class ForwardIterator1, class ForwardIterator2>
|
| 464 |
-
bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
|
| 465 |
ForwardIterator2 first2, ForwardIterator2 last2);
|
| 466 |
template<class ForwardIterator1, class ForwardIterator2,
|
| 467 |
class BinaryPredicate>
|
| 468 |
-
bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
|
| 469 |
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 470 |
BinaryPredicate pred);
|
| 471 |
```
|
| 472 |
|
| 473 |
-
*
|
| 474 |
-
|
| 475 |
-
|
|
|
|
| 476 |
|
| 477 |
*Remarks:* If `last2` was not given in the argument list, it denotes
|
| 478 |
`first2 + (last1 - first1)` below.
|
| 479 |
|
| 480 |
*Returns:* If `last1 - first1 != last2 - first2`, return `false`.
|
|
@@ -488,30 +747,65 @@ otherwise, returns `false`.
|
|
| 488 |
`ForwardIterator1` and `ForwardIterator2` meet the requirements of
|
| 489 |
random access iterators and `last1 - first1 != last2 - first2`.
|
| 490 |
Otherwise, exactly `last1 - first1` applications of the corresponding
|
| 491 |
predicate if `equal(first1, last1, first2, last2)` would return `true`
|
| 492 |
if `pred` was not given in the argument list or
|
| 493 |
-
`equal(first1, last1, first2, last2, pred)` would return `true` if
|
| 494 |
-
was given in the argument list; otherwise, at worst 𝑂(N^2), where
|
| 495 |
-
the value `last1 - first1`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 496 |
|
| 497 |
### Search <a id="alg.search">[[alg.search]]</a>
|
| 498 |
|
| 499 |
``` cpp
|
| 500 |
template<class ForwardIterator1, class ForwardIterator2>
|
| 501 |
-
ForwardIterator1
|
| 502 |
search(ForwardIterator1 first1, ForwardIterator1 last1,
|
| 503 |
ForwardIterator2 first2, ForwardIterator2 last2);
|
| 504 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 505 |
ForwardIterator1
|
| 506 |
search(ExecutionPolicy&& exec,
|
| 507 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 508 |
ForwardIterator2 first2, ForwardIterator2 last2);
|
| 509 |
|
| 510 |
template<class ForwardIterator1, class ForwardIterator2,
|
| 511 |
class BinaryPredicate>
|
| 512 |
-
ForwardIterator1
|
| 513 |
search(ForwardIterator1 first1, ForwardIterator1 last1,
|
| 514 |
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 515 |
BinaryPredicate pred);
|
| 516 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 517 |
class BinaryPredicate>
|
|
@@ -520,68 +814,119 @@ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
|
| 520 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 521 |
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 522 |
BinaryPredicate pred);
|
| 523 |
```
|
| 524 |
|
| 525 |
-
*Effects:* Finds a subsequence of equal values in a sequence.
|
| 526 |
-
|
| 527 |
*Returns:* The first iterator `i` in the range \[`first1`,
|
| 528 |
`last1 - (last2-first2)`) such that for every non-negative integer `n`
|
| 529 |
less than `last2 - first2` the following corresponding conditions hold:
|
| 530 |
`*(i + n) == *(first2 + n), pred(*(i + n), *(first2 + n)) != false`.
|
| 531 |
Returns `first1` if \[`first2`, `last2`) is empty, otherwise returns
|
| 532 |
`last1` if no such iterator is found.
|
| 533 |
|
| 534 |
*Complexity:* At most `(last1 - first1) * (last2 - first2)` applications
|
| 535 |
of the corresponding predicate.
|
| 536 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 537 |
``` cpp
|
| 538 |
template<class ForwardIterator, class Size, class T>
|
| 539 |
-
ForwardIterator
|
| 540 |
-
search_n(ForwardIterator first, ForwardIterator last,
|
| 541 |
-
const T& value);
|
| 542 |
-
|
| 543 |
-
template<class ForwardIterator, class Size, class T,
|
| 544 |
-
class BinaryPredicate>
|
| 545 |
-
ForwardIterator
|
| 546 |
-
search_n(ForwardIterator first, ForwardIterator last, Size count,
|
| 547 |
-
const T& value, BinaryPredicate pred);
|
| 548 |
-
|
| 549 |
template<class ExecutionPolicy, class ForwardIterator, class Size, class T>
|
| 550 |
ForwardIterator
|
| 551 |
search_n(ExecutionPolicy&& exec,
|
| 552 |
ForwardIterator first, ForwardIterator last,
|
| 553 |
Size count, const T& value);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 554 |
template<class ExecutionPolicy, class ForwardIterator, class Size, class T,
|
| 555 |
class BinaryPredicate>
|
| 556 |
ForwardIterator
|
| 557 |
search_n(ExecutionPolicy&& exec,
|
| 558 |
ForwardIterator first, ForwardIterator last,
|
| 559 |
Size count, const T& value,
|
| 560 |
BinaryPredicate pred);
|
| 561 |
```
|
| 562 |
|
| 563 |
-
*
|
| 564 |
type ([[conv.integral]], [[class.conv]]).
|
| 565 |
|
| 566 |
-
*Effects:* Finds a subsequence of equal values in a sequence.
|
| 567 |
-
|
| 568 |
*Returns:* The first iterator `i` in the range \[`first`, `last-count`)
|
| 569 |
such that for every non-negative integer `n` less than `count` the
|
| 570 |
following corresponding conditions hold:
|
| 571 |
`*(i + n) == value, pred(*(i + n),value) != false`. Returns `last` if no
|
| 572 |
such iterator is found.
|
| 573 |
|
| 574 |
*Complexity:* At most `last - first` applications of the corresponding
|
| 575 |
predicate.
|
| 576 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 577 |
``` cpp
|
| 578 |
template<class ForwardIterator, class Searcher>
|
| 579 |
-
|
| 580 |
-
|
| 581 |
```
|
| 582 |
|
| 583 |
*Effects:* Equivalent to: `return searcher(first, last).first;`
|
| 584 |
|
| 585 |
-
*Remarks:* `Searcher` need not meet the
|
| 586 |
requirements.
|
| 587 |
|
|
|
|
| 1 |
## Non-modifying sequence operations <a id="alg.nonmodifying">[[alg.nonmodifying]]</a>
|
| 2 |
|
| 3 |
+
### All of <a id="alg.all.of">[[alg.all.of]]</a>
|
| 4 |
|
| 5 |
``` cpp
|
| 6 |
template<class InputIterator, class Predicate>
|
| 7 |
+
constexpr bool all_of(InputIterator first, InputIterator last, Predicate pred);
|
| 8 |
template<class ExecutionPolicy, class ForwardIterator, class Predicate>
|
| 9 |
bool all_of(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last,
|
| 10 |
Predicate pred);
|
| 11 |
+
|
| 12 |
+
template<input_iterator I, sentinel_for<I> S, class Proj = identity,
|
| 13 |
+
indirect_unary_predicate<projected<I, Proj>> Pred>
|
| 14 |
+
constexpr bool ranges::all_of(I first, S last, Pred pred, Proj proj = {});
|
| 15 |
+
template<input_range R, class Proj = identity,
|
| 16 |
+
indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
|
| 17 |
+
constexpr bool ranges::all_of(R&& r, Pred pred, Proj proj = {});
|
| 18 |
```
|
| 19 |
|
| 20 |
+
Let E be:
|
|
|
|
|
|
|
| 21 |
|
| 22 |
+
- `pred(*i)` for the overloads in namespace `std`;
|
| 23 |
+
- `invoke(pred, invoke(proj, *i))` for the overloads in namespace
|
| 24 |
+
`ranges`.
|
| 25 |
|
| 26 |
+
*Returns:* `false` if E is `false` for some iterator `i` in the range
|
| 27 |
+
\[`first`, `last`), and `true` otherwise.
|
| 28 |
+
|
| 29 |
+
*Complexity:* At most `last - first` applications of the predicate and
|
| 30 |
+
any projection.
|
| 31 |
+
|
| 32 |
+
### Any of <a id="alg.any.of">[[alg.any.of]]</a>
|
| 33 |
|
| 34 |
``` cpp
|
| 35 |
template<class InputIterator, class Predicate>
|
| 36 |
+
constexpr bool any_of(InputIterator first, InputIterator last, Predicate pred);
|
| 37 |
template<class ExecutionPolicy, class ForwardIterator, class Predicate>
|
| 38 |
bool any_of(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last,
|
| 39 |
Predicate pred);
|
| 40 |
+
|
| 41 |
+
template<input_iterator I, sentinel_for<I> S, class Proj = identity,
|
| 42 |
+
indirect_unary_predicate<projected<I, Proj>> Pred>
|
| 43 |
+
constexpr bool ranges::any_of(I first, S last, Pred pred, Proj proj = {});
|
| 44 |
+
template<input_range R, class Proj = identity,
|
| 45 |
+
indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
|
| 46 |
+
constexpr bool ranges::any_of(R&& r, Pred pred, Proj proj = {});
|
| 47 |
```
|
| 48 |
|
| 49 |
+
Let E be:
|
|
|
|
|
|
|
| 50 |
|
| 51 |
+
- `pred(*i)` for the overloads in namespace `std`;
|
| 52 |
+
- `invoke(pred, invoke(proj, *i))` for the overloads in namespace
|
| 53 |
+
`ranges`.
|
| 54 |
|
| 55 |
+
*Returns:* `true` if E is `true` for some iterator `i` in the range
|
| 56 |
+
\[`first`, `last`), and `false` otherwise.
|
| 57 |
+
|
| 58 |
+
*Complexity:* At most `last - first` applications of the predicate and
|
| 59 |
+
any projection.
|
| 60 |
+
|
| 61 |
+
### None of <a id="alg.none.of">[[alg.none.of]]</a>
|
| 62 |
|
| 63 |
``` cpp
|
| 64 |
template<class InputIterator, class Predicate>
|
| 65 |
+
constexpr bool none_of(InputIterator first, InputIterator last, Predicate pred);
|
| 66 |
template<class ExecutionPolicy, class ForwardIterator, class Predicate>
|
| 67 |
bool none_of(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last,
|
| 68 |
Predicate pred);
|
| 69 |
+
|
| 70 |
+
template<input_iterator I, sentinel_for<I> S, class Proj = identity,
|
| 71 |
+
indirect_unary_predicate<projected<I, Proj>> Pred>
|
| 72 |
+
constexpr bool ranges::none_of(I first, S last, Pred pred, Proj proj = {});
|
| 73 |
+
template<input_range R, class Proj = identity,
|
| 74 |
+
indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
|
| 75 |
+
constexpr bool ranges::none_of(R&& r, Pred pred, Proj proj = {});
|
| 76 |
```
|
| 77 |
|
| 78 |
+
Let E be:
|
|
|
|
|
|
|
| 79 |
|
| 80 |
+
- `pred(*i)` for the overloads in namespace `std`;
|
| 81 |
+
- `invoke(pred, invoke(proj, *i))` for the overloads in namespace
|
| 82 |
+
`ranges`.
|
| 83 |
+
|
| 84 |
+
*Returns:* `false` if E is `true` for some iterator `i` in the range
|
| 85 |
+
\[`first`, `last`), and `true` otherwise.
|
| 86 |
+
|
| 87 |
+
*Complexity:* At most `last - first` applications of the predicate and
|
| 88 |
+
any projection.
|
| 89 |
|
| 90 |
### For each <a id="alg.foreach">[[alg.foreach]]</a>
|
| 91 |
|
| 92 |
``` cpp
|
| 93 |
template<class InputIterator, class Function>
|
| 94 |
+
constexpr Function for_each(InputIterator first, InputIterator last, Function f);
|
| 95 |
```
|
| 96 |
|
| 97 |
+
*Preconditions:* `Function` meets the *Cpp17MoveConstructible*
|
| 98 |
+
requirements ([[cpp17.moveconstructible]]).
|
| 99 |
|
| 100 |
[*Note 1*: `Function` need not meet the requirements of
|
| 101 |
+
*Cpp17CopyConstructible* ([[cpp17.copyconstructible]]). — *end note*]
|
| 102 |
|
| 103 |
*Effects:* Applies `f` to the result of dereferencing every iterator in
|
| 104 |
the range \[`first`, `last`), starting from `first` and proceeding to
|
| 105 |
`last - 1`.
|
| 106 |
|
| 107 |
+
[*Note 2*: If the type of `first` meets the requirements of a mutable
|
| 108 |
+
iterator, `f` may apply non-constant functions through the dereferenced
|
| 109 |
+
iterator. — *end note*]
|
| 110 |
|
| 111 |
*Returns:* `f`.
|
| 112 |
|
| 113 |
*Complexity:* Applies `f` exactly `last - first` times.
|
| 114 |
|
|
|
|
| 119 |
void for_each(ExecutionPolicy&& exec,
|
| 120 |
ForwardIterator first, ForwardIterator last,
|
| 121 |
Function f);
|
| 122 |
```
|
| 123 |
|
| 124 |
+
*Preconditions:* `Function` meets the *Cpp17CopyConstructible*
|
| 125 |
+
requirements.
|
| 126 |
|
| 127 |
*Effects:* Applies `f` to the result of dereferencing every iterator in
|
| 128 |
the range \[`first`, `last`).
|
| 129 |
|
| 130 |
+
[*Note 3*: If the type of `first` meets the requirements of a mutable
|
| 131 |
+
iterator, `f` may apply non-constant functions through the dereferenced
|
| 132 |
+
iterator. — *end note*]
|
| 133 |
|
| 134 |
*Complexity:* Applies `f` exactly `last - first` times.
|
| 135 |
|
| 136 |
*Remarks:* If `f` returns a result, the result is ignored.
|
| 137 |
Implementations do not have the freedom granted under
|
|
|
|
| 140 |
|
| 141 |
[*Note 4*: Does not return a copy of its `Function` parameter, since
|
| 142 |
parallelization may not permit efficient state
|
| 143 |
accumulation. — *end note*]
|
| 144 |
|
| 145 |
+
``` cpp
|
| 146 |
+
template<input_iterator I, sentinel_for<I> S, class Proj = identity,
|
| 147 |
+
indirectly_unary_invocable<projected<I, Proj>> Fun>
|
| 148 |
+
constexpr ranges::for_each_result<I, Fun>
|
| 149 |
+
ranges::for_each(I first, S last, Fun f, Proj proj = {});
|
| 150 |
+
template<input_range R, class Proj = identity,
|
| 151 |
+
indirectly_unary_invocable<projected<iterator_t<R>, Proj>> Fun>
|
| 152 |
+
constexpr ranges::for_each_result<borrowed_iterator_t<R>, Fun>
|
| 153 |
+
ranges::for_each(R&& r, Fun f, Proj proj = {});
|
| 154 |
+
```
|
| 155 |
+
|
| 156 |
+
*Effects:* Calls `invoke(f, invoke(proj, *i))` for every iterator `i` in
|
| 157 |
+
the range \[`first`, `last`), starting from `first` and proceeding to
|
| 158 |
+
`last - 1`.
|
| 159 |
+
|
| 160 |
+
[*Note 5*: If the result of `invoke(proj, *i)` is a mutable reference,
|
| 161 |
+
`f` may apply non-constant functions. — *end note*]
|
| 162 |
+
|
| 163 |
+
*Returns:* `{last, std::move(f)}`.
|
| 164 |
+
|
| 165 |
+
*Complexity:* Applies `f` and `proj` exactly `last - first` times.
|
| 166 |
+
|
| 167 |
+
*Remarks:* If `f` returns a result, the result is ignored.
|
| 168 |
+
|
| 169 |
+
[*Note 6*: The overloads in namespace `ranges` require `Fun` to model
|
| 170 |
+
`copy_constructible`. — *end note*]
|
| 171 |
+
|
| 172 |
``` cpp
|
| 173 |
template<class InputIterator, class Size, class Function>
|
| 174 |
+
constexpr InputIterator for_each_n(InputIterator first, Size n, Function f);
|
| 175 |
```
|
| 176 |
|
| 177 |
+
*Mandates:* The type `Size` is convertible to an integral
|
| 178 |
+
type ([[conv.integral]], [[class.conv]]).
|
| 179 |
|
| 180 |
+
*Preconditions:* `Function` meets the *Cpp17MoveConstructible*
|
| 181 |
+
requirements.
|
| 182 |
|
| 183 |
+
[*Note 7*: `Function` need not meet the requirements of
|
| 184 |
+
*Cpp17CopyConstructible*. — *end note*]
|
| 185 |
+
|
| 186 |
+
*Preconditions:* `n >= 0` is `true`.
|
| 187 |
|
| 188 |
*Effects:* Applies `f` to the result of dereferencing every iterator in
|
| 189 |
the range \[`first`, `first + n`) in order.
|
| 190 |
|
| 191 |
+
[*Note 8*: If the type of `first` meets the requirements of a mutable
|
| 192 |
+
iterator, `f` may apply non-constant functions through the dereferenced
|
| 193 |
+
iterator. — *end note*]
|
| 194 |
|
| 195 |
*Returns:* `first + n`.
|
| 196 |
|
| 197 |
*Remarks:* If `f` returns a result, the result is ignored.
|
| 198 |
|
|
|
|
| 200 |
template<class ExecutionPolicy, class ForwardIterator, class Size, class Function>
|
| 201 |
ForwardIterator for_each_n(ExecutionPolicy&& exec, ForwardIterator first, Size n,
|
| 202 |
Function f);
|
| 203 |
```
|
| 204 |
|
| 205 |
+
*Mandates:* The type `Size` is convertible to an integral
|
| 206 |
+
type ([[conv.integral]], [[class.conv]]).
|
| 207 |
|
| 208 |
+
*Preconditions:* `Function` meets the *Cpp17CopyConstructible*
|
| 209 |
+
requirements.
|
| 210 |
+
|
| 211 |
+
*Preconditions:* `n >= 0` is `true`.
|
| 212 |
|
| 213 |
*Effects:* Applies `f` to the result of dereferencing every iterator in
|
| 214 |
the range \[`first`, `first + n`).
|
| 215 |
|
| 216 |
+
[*Note 9*: If the type of `first` meets the requirements of a mutable
|
| 217 |
+
iterator, `f` may apply non-constant functions through the dereferenced
|
| 218 |
+
iterator. — *end note*]
|
| 219 |
|
| 220 |
*Returns:* `first + n`.
|
| 221 |
|
| 222 |
*Remarks:* If `f` returns a result, the result is ignored.
|
| 223 |
Implementations do not have the freedom granted under
|
| 224 |
[[algorithms.parallel.exec]] to make arbitrary copies of elements from
|
| 225 |
the input sequence.
|
| 226 |
|
| 227 |
+
``` cpp
|
| 228 |
+
template<input_iterator I, class Proj = identity,
|
| 229 |
+
indirectly_unary_invocable<projected<I, Proj>> Fun>
|
| 230 |
+
constexpr ranges::for_each_n_result<I, Fun>
|
| 231 |
+
ranges::for_each_n(I first, iter_difference_t<I> n, Fun f, Proj proj = {});
|
| 232 |
+
```
|
| 233 |
+
|
| 234 |
+
*Preconditions:* `n >= 0` is `true`.
|
| 235 |
+
|
| 236 |
+
*Effects:* Calls `invoke(f, invoke(proj, *i))` for every iterator `i` in
|
| 237 |
+
the range \[`first`, `first + n`) in order.
|
| 238 |
+
|
| 239 |
+
[*Note 10*: If the result of `invoke(proj, *i)` is a mutable reference,
|
| 240 |
+
`f` may apply non-constant functions. — *end note*]
|
| 241 |
+
|
| 242 |
+
*Returns:* `{first + n, std::move(f)}`.
|
| 243 |
+
|
| 244 |
+
*Remarks:* If `f` returns a result, the result is ignored.
|
| 245 |
+
|
| 246 |
+
[*Note 11*: The overload in namespace `ranges` requires `Fun` to model
|
| 247 |
+
`copy_constructible`. — *end note*]
|
| 248 |
+
|
| 249 |
### Find <a id="alg.find">[[alg.find]]</a>
|
| 250 |
|
| 251 |
``` cpp
|
| 252 |
template<class InputIterator, class T>
|
| 253 |
+
constexpr InputIterator find(InputIterator first, InputIterator last,
|
| 254 |
const T& value);
|
| 255 |
template<class ExecutionPolicy, class ForwardIterator, class T>
|
| 256 |
ForwardIterator find(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last,
|
| 257 |
const T& value);
|
| 258 |
|
| 259 |
template<class InputIterator, class Predicate>
|
| 260 |
+
constexpr InputIterator find_if(InputIterator first, InputIterator last,
|
| 261 |
Predicate pred);
|
| 262 |
template<class ExecutionPolicy, class ForwardIterator, class Predicate>
|
| 263 |
ForwardIterator find_if(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last,
|
| 264 |
Predicate pred);
|
| 265 |
|
| 266 |
template<class InputIterator, class Predicate>
|
| 267 |
+
constexpr InputIterator find_if_not(InputIterator first, InputIterator last,
|
| 268 |
Predicate pred);
|
| 269 |
template<class ExecutionPolicy, class ForwardIterator, class Predicate>
|
| 270 |
+
ForwardIterator find_if_not(ExecutionPolicy&& exec,
|
| 271 |
+
ForwardIterator first, ForwardIterator last,
|
| 272 |
Predicate pred);
|
| 273 |
+
|
| 274 |
+
template<input_iterator I, sentinel_for<I> S, class T, class Proj = identity>
|
| 275 |
+
requires indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T*>
|
| 276 |
+
constexpr I ranges::find(I first, S last, const T& value, Proj proj = {});
|
| 277 |
+
template<input_range R, class T, class Proj = identity>
|
| 278 |
+
requires indirect_binary_predicate<ranges::equal_to, projected<iterator_t<R>, Proj>, const T*>
|
| 279 |
+
constexpr borrowed_iterator_t<R>
|
| 280 |
+
ranges::find(R&& r, const T& value, Proj proj = {});
|
| 281 |
+
template<input_iterator I, sentinel_for<I> S, class Proj = identity,
|
| 282 |
+
indirect_unary_predicate<projected<I, Proj>> Pred>
|
| 283 |
+
constexpr I ranges::find_if(I first, S last, Pred pred, Proj proj = {});
|
| 284 |
+
template<input_range R, class Proj = identity,
|
| 285 |
+
indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
|
| 286 |
+
constexpr borrowed_iterator_t<R>
|
| 287 |
+
ranges::find_if(R&& r, Pred pred, Proj proj = {});
|
| 288 |
+
template<input_iterator I, sentinel_for<I> S, class Proj = identity,
|
| 289 |
+
indirect_unary_predicate<projected<I, Proj>> Pred>
|
| 290 |
+
constexpr I ranges::find_if_not(I first, S last, Pred pred, Proj proj = {});
|
| 291 |
+
template<input_range R, class Proj = identity,
|
| 292 |
+
indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
|
| 293 |
+
constexpr borrowed_iterator_t<R>
|
| 294 |
+
ranges::find_if_not(R&& r, Pred pred, Proj proj = {});
|
| 295 |
```
|
| 296 |
|
| 297 |
+
Let E be:
|
| 298 |
+
|
| 299 |
+
- `*i == value` for `find`;
|
| 300 |
+
- `pred(*i) != false` for `find_if`;
|
| 301 |
+
- `pred(*i) == false` for `find_if_not`;
|
| 302 |
+
- `bool(invoke(proj, *i) == value)` for `ranges::find`;
|
| 303 |
+
- `bool(invoke(pred, invoke(proj, *i)))` for `ranges::find_if`;
|
| 304 |
+
- `bool(!invoke(pred, invoke(proj, *i)))` for `ranges::find_if_not`.
|
| 305 |
+
|
| 306 |
*Returns:* The first iterator `i` in the range \[`first`, `last`) for
|
| 307 |
+
which E is `true`. Returns `last` if no such iterator is found.
|
|
|
|
|
|
|
| 308 |
|
| 309 |
*Complexity:* At most `last - first` applications of the corresponding
|
| 310 |
+
predicate and any projection.
|
| 311 |
|
| 312 |
### Find end <a id="alg.find.end">[[alg.find.end]]</a>
|
| 313 |
|
| 314 |
``` cpp
|
| 315 |
template<class ForwardIterator1, class ForwardIterator2>
|
| 316 |
+
constexpr ForwardIterator1
|
| 317 |
find_end(ForwardIterator1 first1, ForwardIterator1 last1,
|
| 318 |
ForwardIterator2 first2, ForwardIterator2 last2);
|
| 319 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 320 |
ForwardIterator1
|
| 321 |
find_end(ExecutionPolicy&& exec,
|
| 322 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 323 |
ForwardIterator2 first2, ForwardIterator2 last2);
|
| 324 |
|
| 325 |
template<class ForwardIterator1, class ForwardIterator2,
|
| 326 |
class BinaryPredicate>
|
| 327 |
+
constexpr ForwardIterator1
|
| 328 |
find_end(ForwardIterator1 first1, ForwardIterator1 last1,
|
| 329 |
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 330 |
BinaryPredicate pred);
|
| 331 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 332 |
class BinaryPredicate>
|
| 333 |
ForwardIterator1
|
| 334 |
find_end(ExecutionPolicy&& exec,
|
| 335 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 336 |
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 337 |
BinaryPredicate pred);
|
| 338 |
+
|
| 339 |
+
template<forward_iterator I1, sentinel_for<I1> S1, forward_iterator I2, sentinel_for<I2> S2,
|
| 340 |
+
class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
|
| 341 |
+
requires indirectly_comparable<I1, I2, Pred, Proj1, Proj2>
|
| 342 |
+
constexpr subrange<I1>
|
| 343 |
+
ranges::find_end(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {},
|
| 344 |
+
Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 345 |
+
template<forward_range R1, forward_range R2,
|
| 346 |
+
class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
|
| 347 |
+
requires indirectly_comparable<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
|
| 348 |
+
constexpr borrowed_subrange_t<R1>
|
| 349 |
+
ranges::find_end(R1&& r1, R2&& r2, Pred pred = {},
|
| 350 |
+
Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 351 |
```
|
| 352 |
|
| 353 |
+
Let:
|
| 354 |
|
| 355 |
+
- `pred` be `equal_to{}` for the overloads with no parameter `pred`;
|
| 356 |
+
- E be:
|
| 357 |
+
- `pred(*(i + n), *(first2 + n))` for the overloads in namespace
|
| 358 |
+
`std`;
|
| 359 |
+
- `invoke(pred, invoke(proj1, *(i + n)), invoke(proj2, *(first2 + n)))`
|
| 360 |
+
for the overloads in namespace `ranges`;
|
| 361 |
+
- `i` be `last1` if \[`first2`, `last2`) is empty, or if
|
| 362 |
+
`(last2 - first2) > (last1 - first1)` is `true`, or if there is no
|
| 363 |
+
iterator in the range \[`first1`, `last1 - (last2 - first2)`) such
|
| 364 |
+
that for every non-negative integer `n < (last2 - first2)`, E is
|
| 365 |
+
`true`. Otherwise `i` is the last such iterator in \[`first1`,
|
| 366 |
+
`last1 - (last2 - first2)`).
|
| 367 |
+
|
| 368 |
+
*Returns:*
|
| 369 |
+
|
| 370 |
+
- `i` for the overloads in namespace `std`.
|
| 371 |
+
- `{i, i + (i == last1 ? 0 : last2 - first2)}` for the overloads in
|
| 372 |
+
namespace `ranges`.
|
| 373 |
|
| 374 |
*Complexity:* At most
|
| 375 |
`(last2 - first2) * (last1 - first1 - (last2 - first2) + 1)`
|
| 376 |
+
applications of the corresponding predicate and any projections.
|
| 377 |
|
| 378 |
### Find first <a id="alg.find.first.of">[[alg.find.first.of]]</a>
|
| 379 |
|
| 380 |
``` cpp
|
| 381 |
template<class InputIterator, class ForwardIterator>
|
| 382 |
+
constexpr InputIterator
|
| 383 |
find_first_of(InputIterator first1, InputIterator last1,
|
| 384 |
ForwardIterator first2, ForwardIterator last2);
|
| 385 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 386 |
ForwardIterator1
|
| 387 |
find_first_of(ExecutionPolicy&& exec,
|
| 388 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 389 |
ForwardIterator2 first2, ForwardIterator2 last2);
|
| 390 |
|
| 391 |
template<class InputIterator, class ForwardIterator,
|
| 392 |
class BinaryPredicate>
|
| 393 |
+
constexpr InputIterator
|
| 394 |
find_first_of(InputIterator first1, InputIterator last1,
|
| 395 |
ForwardIterator first2, ForwardIterator last2,
|
| 396 |
BinaryPredicate pred);
|
| 397 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 398 |
class BinaryPredicate>
|
| 399 |
ForwardIterator1
|
| 400 |
find_first_of(ExecutionPolicy&& exec,
|
| 401 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 402 |
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 403 |
BinaryPredicate pred);
|
| 404 |
+
|
| 405 |
+
template<input_iterator I1, sentinel_for<I1> S1, forward_iterator I2, sentinel_for<I2> S2,
|
| 406 |
+
class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
|
| 407 |
+
requires indirectly_comparable<I1, I2, Pred, Proj1, Proj2>
|
| 408 |
+
constexpr I1 ranges::find_first_of(I1 first1, S1 last1, I2 first2, S2 last2,
|
| 409 |
+
Pred pred = {},
|
| 410 |
+
Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 411 |
+
template<input_range R1, forward_range R2,
|
| 412 |
+
class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
|
| 413 |
+
requires indirectly_comparable<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
|
| 414 |
+
constexpr borrowed_iterator_t<R1>
|
| 415 |
+
ranges::find_first_of(R1&& r1, R2&& r2,
|
| 416 |
+
Pred pred = {},
|
| 417 |
+
Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 418 |
```
|
| 419 |
|
| 420 |
+
Let E be:
|
| 421 |
+
|
| 422 |
+
- `*i == *j` for the overloads with no parameter `pred`;
|
| 423 |
+
- `pred(*i, *j) != false` for the overloads with a parameter `pred` and
|
| 424 |
+
no parameter `proj1`;
|
| 425 |
+
- `bool(invoke(pred, invoke(proj1, *i), invoke(proj2, *j)))` for the
|
| 426 |
+
overloads with parameters `pred` and `proj1`.
|
| 427 |
+
|
| 428 |
*Effects:* Finds an element that matches one of a set of values.
|
| 429 |
|
| 430 |
*Returns:* The first iterator `i` in the range \[`first1`, `last1`) such
|
| 431 |
+
that for some iterator `j` in the range \[`first2`, `last2`) E holds.
|
| 432 |
+
Returns `last1` if \[`first2`, `last2`) is empty or if no such iterator
|
| 433 |
+
is found.
|
|
|
|
| 434 |
|
| 435 |
*Complexity:* At most `(last1-first1) * (last2-first2)` applications of
|
| 436 |
+
the corresponding predicate and any projections.
|
| 437 |
|
| 438 |
### Adjacent find <a id="alg.adjacent.find">[[alg.adjacent.find]]</a>
|
| 439 |
|
| 440 |
``` cpp
|
| 441 |
template<class ForwardIterator>
|
| 442 |
+
constexpr ForwardIterator
|
| 443 |
+
adjacent_find(ForwardIterator first, ForwardIterator last);
|
| 444 |
template<class ExecutionPolicy, class ForwardIterator>
|
| 445 |
+
ForwardIterator
|
| 446 |
+
adjacent_find(ExecutionPolicy&& exec,
|
| 447 |
ForwardIterator first, ForwardIterator last);
|
| 448 |
|
| 449 |
template<class ForwardIterator, class BinaryPredicate>
|
| 450 |
+
constexpr ForwardIterator
|
| 451 |
+
adjacent_find(ForwardIterator first, ForwardIterator last,
|
| 452 |
BinaryPredicate pred);
|
| 453 |
template<class ExecutionPolicy, class ForwardIterator, class BinaryPredicate>
|
| 454 |
+
ForwardIterator
|
| 455 |
+
adjacent_find(ExecutionPolicy&& exec,
|
| 456 |
ForwardIterator first, ForwardIterator last,
|
| 457 |
BinaryPredicate pred);
|
| 458 |
+
|
| 459 |
+
template<forward_iterator I, sentinel_for<I> S, class Proj = identity,
|
| 460 |
+
indirect_binary_predicate<projected<I, Proj>,
|
| 461 |
+
projected<I, Proj>> Pred = ranges::equal_to>
|
| 462 |
+
constexpr I ranges::adjacent_find(I first, S last, Pred pred = {}, Proj proj = {});
|
| 463 |
+
template<forward_range R, class Proj = identity,
|
| 464 |
+
indirect_binary_predicate<projected<iterator_t<R>, Proj>,
|
| 465 |
+
projected<iterator_t<R>, Proj>> Pred = ranges::equal_to>
|
| 466 |
+
constexpr borrowed_iterator_t<R> ranges::adjacent_find(R&& r, Pred pred = {}, Proj proj = {});
|
| 467 |
```
|
| 468 |
|
| 469 |
+
Let E be:
|
| 470 |
+
|
| 471 |
+
- `*i == *(i + 1)` for the overloads with no parameter `pred`;
|
| 472 |
+
- `pred(*i, *(i + 1)) != false` for the overloads with a parameter
|
| 473 |
+
`pred` and no parameter `proj`;
|
| 474 |
+
- `bool(invoke(pred, invoke(proj, *i), invoke(proj, *(i + 1))))` for the
|
| 475 |
+
overloads with both parameters `pred` and `proj`.
|
| 476 |
+
|
| 477 |
*Returns:* The first iterator `i` such that both `i` and `i + 1` are in
|
| 478 |
+
the range \[`first`, `last`) for which E holds. Returns `last` if no
|
| 479 |
+
such iterator is found.
|
|
|
|
| 480 |
|
| 481 |
*Complexity:* For the overloads with no `ExecutionPolicy`, exactly
|
| 482 |
+
$$\min(\texttt{(i - first) + 1}, \ \texttt{(last - first) - 1})$$
|
| 483 |
+
applications of the corresponding predicate, where `i` is
|
| 484 |
+
`adjacent_find`’s return value. For the overloads with an
|
| 485 |
+
`ExecutionPolicy`, 𝑂(`last - first`) applications of the corresponding
|
| 486 |
+
predicate, and no more than twice as many applications of any
|
| 487 |
+
projection.
|
| 488 |
|
| 489 |
### Count <a id="alg.count">[[alg.count]]</a>
|
| 490 |
|
| 491 |
``` cpp
|
| 492 |
template<class InputIterator, class T>
|
| 493 |
+
constexpr typename iterator_traits<InputIterator>::difference_type
|
| 494 |
count(InputIterator first, InputIterator last, const T& value);
|
| 495 |
template<class ExecutionPolicy, class ForwardIterator, class T>
|
| 496 |
typename iterator_traits<ForwardIterator>::difference_type
|
| 497 |
+
count(ExecutionPolicy&& exec,
|
| 498 |
+
ForwardIterator first, ForwardIterator last, const T& value);
|
| 499 |
|
| 500 |
template<class InputIterator, class Predicate>
|
| 501 |
+
constexpr typename iterator_traits<InputIterator>::difference_type
|
| 502 |
count_if(InputIterator first, InputIterator last, Predicate pred);
|
| 503 |
template<class ExecutionPolicy, class ForwardIterator, class Predicate>
|
| 504 |
typename iterator_traits<ForwardIterator>::difference_type
|
| 505 |
+
count_if(ExecutionPolicy&& exec,
|
| 506 |
+
ForwardIterator first, ForwardIterator last, Predicate pred);
|
| 507 |
+
|
| 508 |
+
template<input_iterator I, sentinel_for<I> S, class T, class Proj = identity>
|
| 509 |
+
requires indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T*>
|
| 510 |
+
constexpr iter_difference_t<I>
|
| 511 |
+
ranges::count(I first, S last, const T& value, Proj proj = {});
|
| 512 |
+
template<input_range R, class T, class Proj = identity>
|
| 513 |
+
requires indirect_binary_predicate<ranges::equal_to, projected<iterator_t<R>, Proj>, const T*>
|
| 514 |
+
constexpr range_difference_t<R>
|
| 515 |
+
ranges::count(R&& r, const T& value, Proj proj = {});
|
| 516 |
+
template<input_iterator I, sentinel_for<I> S, class Proj = identity,
|
| 517 |
+
indirect_unary_predicate<projected<I, Proj>> Pred>
|
| 518 |
+
constexpr iter_difference_t<I>
|
| 519 |
+
ranges::count_if(I first, S last, Pred pred, Proj proj = {});
|
| 520 |
+
template<input_range R, class Proj = identity,
|
| 521 |
+
indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
|
| 522 |
+
constexpr range_difference_t<R>
|
| 523 |
+
ranges::count_if(R&& r, Pred pred, Proj proj = {});
|
| 524 |
```
|
| 525 |
|
| 526 |
+
Let E be:
|
| 527 |
+
|
| 528 |
+
- `*i == value` for the overloads with no parameter `pred` or `proj`;
|
| 529 |
+
- `pred(*i) != false` for the overloads with a parameter `pred` but no
|
| 530 |
+
parameter `proj`;
|
| 531 |
+
- `invoke(proj, *i) == value` for the overloads with a parameter `proj`
|
| 532 |
+
but no parameter `pred`;
|
| 533 |
+
- `bool(invoke(pred, invoke(proj, *i)))` for the overloads with both
|
| 534 |
+
parameters `proj` and `pred`.
|
| 535 |
+
|
| 536 |
*Effects:* Returns the number of iterators `i` in the range \[`first`,
|
| 537 |
+
`last`) for which E holds.
|
|
|
|
| 538 |
|
| 539 |
*Complexity:* Exactly `last - first` applications of the corresponding
|
| 540 |
+
predicate and any projection.
|
| 541 |
|
| 542 |
### Mismatch <a id="mismatch">[[mismatch]]</a>
|
| 543 |
|
| 544 |
``` cpp
|
| 545 |
template<class InputIterator1, class InputIterator2>
|
| 546 |
+
constexpr pair<InputIterator1, InputIterator2>
|
| 547 |
mismatch(InputIterator1 first1, InputIterator1 last1,
|
| 548 |
InputIterator2 first2);
|
| 549 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 550 |
pair<ForwardIterator1, ForwardIterator2>
|
| 551 |
mismatch(ExecutionPolicy&& exec,
|
| 552 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 553 |
ForwardIterator2 first2);
|
| 554 |
|
| 555 |
template<class InputIterator1, class InputIterator2,
|
| 556 |
class BinaryPredicate>
|
| 557 |
+
constexpr pair<InputIterator1, InputIterator2>
|
| 558 |
mismatch(InputIterator1 first1, InputIterator1 last1,
|
| 559 |
InputIterator2 first2, BinaryPredicate pred);
|
| 560 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 561 |
class BinaryPredicate>
|
| 562 |
pair<ForwardIterator1, ForwardIterator2>
|
| 563 |
mismatch(ExecutionPolicy&& exec,
|
| 564 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 565 |
ForwardIterator2 first2, BinaryPredicate pred);
|
| 566 |
|
| 567 |
template<class InputIterator1, class InputIterator2>
|
| 568 |
+
constexpr pair<InputIterator1, InputIterator2>
|
| 569 |
mismatch(InputIterator1 first1, InputIterator1 last1,
|
| 570 |
InputIterator2 first2, InputIterator2 last2);
|
| 571 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 572 |
pair<ForwardIterator1, ForwardIterator2>
|
| 573 |
mismatch(ExecutionPolicy&& exec,
|
| 574 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 575 |
ForwardIterator2 first2, ForwardIterator2 last2);
|
| 576 |
|
| 577 |
template<class InputIterator1, class InputIterator2,
|
| 578 |
class BinaryPredicate>
|
| 579 |
+
constexpr pair<InputIterator1, InputIterator2>
|
| 580 |
mismatch(InputIterator1 first1, InputIterator1 last1,
|
| 581 |
InputIterator2 first2, InputIterator2 last2,
|
| 582 |
BinaryPredicate pred);
|
| 583 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 584 |
class BinaryPredicate>
|
| 585 |
pair<ForwardIterator1, ForwardIterator2>
|
| 586 |
mismatch(ExecutionPolicy&& exec,
|
| 587 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 588 |
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 589 |
BinaryPredicate pred);
|
| 590 |
+
|
| 591 |
+
template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2,
|
| 592 |
+
class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
|
| 593 |
+
requires indirectly_comparable<I1, I2, Pred, Proj1, Proj2>
|
| 594 |
+
constexpr ranges::mismatch_result<I1, I2>
|
| 595 |
+
ranges::mismatch(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {},
|
| 596 |
+
Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 597 |
+
template<input_range R1, input_range R2,
|
| 598 |
+
class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
|
| 599 |
+
requires indirectly_comparable<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
|
| 600 |
+
constexpr ranges::mismatch_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>>
|
| 601 |
+
ranges::mismatch(R1&& r1, R2&& r2, Pred pred = {},
|
| 602 |
+
Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 603 |
```
|
| 604 |
|
| 605 |
+
Let `last2` be `first2 + (last1 - first1)` for the overloads with no
|
| 606 |
+
parameter `last2` or `r2`.
|
| 607 |
|
| 608 |
+
Let E be:
|
|
|
|
| 609 |
|
| 610 |
+
- `!(*(first1 + n) == *(first2 + n))` for the overloads with no
|
| 611 |
+
parameter `pred`;
|
| 612 |
+
- `pred(*(first1 + n), *(first2 + n)) == false` for the overloads with a
|
| 613 |
+
parameter `pred` and no parameter `proj1`;
|
| 614 |
+
- `!invoke(pred, invoke(proj1, *(first1 + n)), invoke(proj2, *(first2 + n)))`
|
| 615 |
+
for the overloads with both parameters `pred` and `proj1`.
|
| 616 |
|
| 617 |
+
Let N be min(`last1 - first1`, `last2 - first2`).
|
| 618 |
|
| 619 |
+
*Returns:* `{ first1 + n, first2 + n }`, where `n` is the smallest
|
| 620 |
+
integer in \[`0`, N) such that E holds, or N if no such integer exists.
|
| 621 |
+
|
| 622 |
+
*Complexity:* At most N applications of the corresponding predicate and
|
| 623 |
+
any projections.
|
| 624 |
|
| 625 |
### Equal <a id="alg.equal">[[alg.equal]]</a>
|
| 626 |
|
| 627 |
``` cpp
|
| 628 |
template<class InputIterator1, class InputIterator2>
|
| 629 |
+
constexpr bool equal(InputIterator1 first1, InputIterator1 last1,
|
| 630 |
InputIterator2 first2);
|
| 631 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 632 |
bool equal(ExecutionPolicy&& exec,
|
| 633 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 634 |
ForwardIterator2 first2);
|
| 635 |
|
| 636 |
template<class InputIterator1, class InputIterator2,
|
| 637 |
class BinaryPredicate>
|
| 638 |
+
constexpr bool equal(InputIterator1 first1, InputIterator1 last1,
|
| 639 |
InputIterator2 first2, BinaryPredicate pred);
|
| 640 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 641 |
class BinaryPredicate>
|
| 642 |
bool equal(ExecutionPolicy&& exec,
|
| 643 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 644 |
ForwardIterator2 first2, BinaryPredicate pred);
|
| 645 |
|
| 646 |
template<class InputIterator1, class InputIterator2>
|
| 647 |
+
constexpr bool equal(InputIterator1 first1, InputIterator1 last1,
|
| 648 |
InputIterator2 first2, InputIterator2 last2);
|
| 649 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 650 |
bool equal(ExecutionPolicy&& exec,
|
| 651 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 652 |
ForwardIterator2 first2, ForwardIterator2 last2);
|
| 653 |
|
| 654 |
template<class InputIterator1, class InputIterator2,
|
| 655 |
class BinaryPredicate>
|
| 656 |
+
constexpr bool equal(InputIterator1 first1, InputIterator1 last1,
|
| 657 |
InputIterator2 first2, InputIterator2 last2,
|
| 658 |
BinaryPredicate pred);
|
| 659 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 660 |
class BinaryPredicate>
|
| 661 |
bool equal(ExecutionPolicy&& exec,
|
| 662 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 663 |
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 664 |
BinaryPredicate pred);
|
| 665 |
+
|
| 666 |
+
template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2,
|
| 667 |
+
class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
|
| 668 |
+
requires indirectly_comparable<I1, I2, Pred, Proj1, Proj2>
|
| 669 |
+
constexpr bool ranges::equal(I1 first1, S1 last1, I2 first2, S2 last2,
|
| 670 |
+
Pred pred = {},
|
| 671 |
+
Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 672 |
+
template<input_range R1, input_range R2, class Pred = ranges::equal_to,
|
| 673 |
+
class Proj1 = identity, class Proj2 = identity>
|
| 674 |
+
requires indirectly_comparable<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
|
| 675 |
+
constexpr bool ranges::equal(R1&& r1, R2&& r2, Pred pred = {},
|
| 676 |
+
Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 677 |
```
|
| 678 |
|
| 679 |
+
Let:
|
| 680 |
+
|
| 681 |
+
- `last2` be `first2 + (last1 - first1)` for the overloads with no
|
| 682 |
+
parameter `last2` or `r2`;
|
| 683 |
+
- `pred` be `equal_to{}` for the overloads with no parameter `pred`;
|
| 684 |
+
- E be:
|
| 685 |
+
- `pred(*i, *(first2 + (i - first1)))` for the overloads with no
|
| 686 |
+
parameter `proj1`;
|
| 687 |
+
- `invoke(pred, invoke(proj1, *i), invoke(proj2, *(first2 + (i - first1))))`
|
| 688 |
+
for the overloads with parameter `proj1`.
|
| 689 |
|
| 690 |
*Returns:* If `last1 - first1 != last2 - first2`, return `false`.
|
| 691 |
+
Otherwise return `true` if E holds for every iterator `i` in the range
|
| 692 |
+
\[`first1`, `last1`) Otherwise, returns `false`.
|
|
|
|
|
|
|
| 693 |
|
| 694 |
+
*Complexity:* If the types of `first1`, `last1`, `first2`, and `last2`:
|
| 695 |
|
| 696 |
+
- meet the *Cpp17RandomAccessIterator*
|
| 697 |
+
requirements [[random.access.iterators]] for the overloads in
|
| 698 |
+
namespace `std`;
|
| 699 |
+
- pairwise model `sized_sentinel_for` [[iterator.concept.sizedsentinel]]
|
| 700 |
+
for the overloads in namespace `ranges`,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 701 |
|
| 702 |
+
and `last1 - first1 != last2 - first2`, then no applications of the
|
| 703 |
+
corresponding predicate and each projection; otherwise,
|
| 704 |
+
|
| 705 |
+
- For the overloads with no `ExecutionPolicy`, at most
|
| 706 |
+
min(`last1 - first1`, `last2 - first2`) applications of the
|
| 707 |
+
corresponding predicate and any projections.
|
| 708 |
+
- For the overloads with an `ExecutionPolicy`, 𝑂(min(`last1 - first1`,
|
| 709 |
+
`last2 - first2`)) applications of the corresponding predicate.
|
| 710 |
+
|
| 711 |
+
### Is permutation <a id="alg.is.permutation">[[alg.is.permutation]]</a>
|
| 712 |
|
| 713 |
``` cpp
|
| 714 |
template<class ForwardIterator1, class ForwardIterator2>
|
| 715 |
+
constexpr bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
|
| 716 |
ForwardIterator2 first2);
|
| 717 |
template<class ForwardIterator1, class ForwardIterator2,
|
| 718 |
class BinaryPredicate>
|
| 719 |
+
constexpr bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
|
| 720 |
ForwardIterator2 first2, BinaryPredicate pred);
|
| 721 |
template<class ForwardIterator1, class ForwardIterator2>
|
| 722 |
+
constexpr bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
|
| 723 |
ForwardIterator2 first2, ForwardIterator2 last2);
|
| 724 |
template<class ForwardIterator1, class ForwardIterator2,
|
| 725 |
class BinaryPredicate>
|
| 726 |
+
constexpr bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
|
| 727 |
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 728 |
BinaryPredicate pred);
|
| 729 |
```
|
| 730 |
|
| 731 |
+
*Mandates:* `ForwardIterator1` and `ForwardIterator2` have the same
|
| 732 |
+
value type.
|
| 733 |
+
|
| 734 |
+
*Preconditions:* The comparison function is an equivalence relation.
|
| 735 |
|
| 736 |
*Remarks:* If `last2` was not given in the argument list, it denotes
|
| 737 |
`first2 + (last1 - first1)` below.
|
| 738 |
|
| 739 |
*Returns:* If `last1 - first1 != last2 - first2`, return `false`.
|
|
|
|
| 747 |
`ForwardIterator1` and `ForwardIterator2` meet the requirements of
|
| 748 |
random access iterators and `last1 - first1 != last2 - first2`.
|
| 749 |
Otherwise, exactly `last1 - first1` applications of the corresponding
|
| 750 |
predicate if `equal(first1, last1, first2, last2)` would return `true`
|
| 751 |
if `pred` was not given in the argument list or
|
| 752 |
+
`equal(first1, last1, first2, last2, pred)` would return `true` if
|
| 753 |
+
`pred` was given in the argument list; otherwise, at worst 𝑂(N^2), where
|
| 754 |
+
N has the value `last1 - first1`.
|
| 755 |
+
|
| 756 |
+
``` cpp
|
| 757 |
+
template<forward_iterator I1, sentinel_for<I1> S1, forward_iterator I2,
|
| 758 |
+
sentinel_for<I2> S2, class Proj1 = identity, class Proj2 = identity,
|
| 759 |
+
indirect_equivalence_relation<projected<I1, Proj1>,
|
| 760 |
+
projected<I2, Proj2>> Pred = ranges::equal_to>
|
| 761 |
+
constexpr bool ranges::is_permutation(I1 first1, S1 last1, I2 first2, S2 last2,
|
| 762 |
+
Pred pred = {},
|
| 763 |
+
Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 764 |
+
template<forward_range R1, forward_range R2,
|
| 765 |
+
class Proj1 = identity, class Proj2 = identity,
|
| 766 |
+
indirect_equivalence_relation<projected<iterator_t<R1>, Proj1>,
|
| 767 |
+
projected<iterator_t<R2>, Proj2>> Pred = ranges::equal_to>
|
| 768 |
+
constexpr bool ranges::is_permutation(R1&& r1, R2&& r2, Pred pred = {},
|
| 769 |
+
Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 770 |
+
```
|
| 771 |
+
|
| 772 |
+
*Returns:* If `last1 - first1 != last2 - first2`, return `false`.
|
| 773 |
+
Otherwise return `true` if there exists a permutation of the elements in
|
| 774 |
+
the range \[`first2`, `last2`), bounded by \[`pfirst`, `plast`), such
|
| 775 |
+
that `ranges::equal(first1, last1, pfirst, plast, pred, proj1, proj2)`
|
| 776 |
+
returns `true`; otherwise, returns `false`.
|
| 777 |
+
|
| 778 |
+
*Complexity:* No applications of the corresponding predicate and
|
| 779 |
+
projections if:
|
| 780 |
+
|
| 781 |
+
- `S1` and `I1` model `sized_sentinel_for<S1, I1>`,
|
| 782 |
+
- `S2` and `I2` model `sized_sentinel_for<S2, I2>`, and
|
| 783 |
+
- `last1 - first1 != last2 - first2`.
|
| 784 |
+
|
| 785 |
+
Otherwise, exactly `last1 - first1` applications of the corresponding
|
| 786 |
+
predicate and projections if
|
| 787 |
+
`ranges::equal(first1, last1, first2, last2, pred, proj1, proj2)` would
|
| 788 |
+
return `true`; otherwise, at worst 𝑂(N^2), where N has the value
|
| 789 |
+
`last1 - first1`.
|
| 790 |
|
| 791 |
### Search <a id="alg.search">[[alg.search]]</a>
|
| 792 |
|
| 793 |
``` cpp
|
| 794 |
template<class ForwardIterator1, class ForwardIterator2>
|
| 795 |
+
constexpr ForwardIterator1
|
| 796 |
search(ForwardIterator1 first1, ForwardIterator1 last1,
|
| 797 |
ForwardIterator2 first2, ForwardIterator2 last2);
|
| 798 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 799 |
ForwardIterator1
|
| 800 |
search(ExecutionPolicy&& exec,
|
| 801 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 802 |
ForwardIterator2 first2, ForwardIterator2 last2);
|
| 803 |
|
| 804 |
template<class ForwardIterator1, class ForwardIterator2,
|
| 805 |
class BinaryPredicate>
|
| 806 |
+
constexpr ForwardIterator1
|
| 807 |
search(ForwardIterator1 first1, ForwardIterator1 last1,
|
| 808 |
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 809 |
BinaryPredicate pred);
|
| 810 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 811 |
class BinaryPredicate>
|
|
|
|
| 814 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 815 |
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 816 |
BinaryPredicate pred);
|
| 817 |
```
|
| 818 |
|
|
|
|
|
|
|
| 819 |
*Returns:* The first iterator `i` in the range \[`first1`,
|
| 820 |
`last1 - (last2-first2)`) such that for every non-negative integer `n`
|
| 821 |
less than `last2 - first2` the following corresponding conditions hold:
|
| 822 |
`*(i + n) == *(first2 + n), pred(*(i + n), *(first2 + n)) != false`.
|
| 823 |
Returns `first1` if \[`first2`, `last2`) is empty, otherwise returns
|
| 824 |
`last1` if no such iterator is found.
|
| 825 |
|
| 826 |
*Complexity:* At most `(last1 - first1) * (last2 - first2)` applications
|
| 827 |
of the corresponding predicate.
|
| 828 |
|
| 829 |
+
``` cpp
|
| 830 |
+
template<forward_iterator I1, sentinel_for<I1> S1, forward_iterator I2,
|
| 831 |
+
sentinel_for<I2> S2, class Pred = ranges::equal_to,
|
| 832 |
+
class Proj1 = identity, class Proj2 = identity>
|
| 833 |
+
requires indirectly_comparable<I1, I2, Pred, Proj1, Proj2>
|
| 834 |
+
constexpr subrange<I1>
|
| 835 |
+
ranges::search(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {},
|
| 836 |
+
Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 837 |
+
template<forward_range R1, forward_range R2, class Pred = ranges::equal_to,
|
| 838 |
+
class Proj1 = identity, class Proj2 = identity>
|
| 839 |
+
requires indirectly_comparable<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
|
| 840 |
+
constexpr borrowed_subrange_t<R1>
|
| 841 |
+
ranges::search(R1&& r1, R2&& r2, Pred pred = {},
|
| 842 |
+
Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 843 |
+
```
|
| 844 |
+
|
| 845 |
+
*Returns:*
|
| 846 |
+
|
| 847 |
+
- `{i, i + (last2 - first2)}`, where `i` is the first iterator in the
|
| 848 |
+
range \[`first1`, `last1 - (last2 - first2)`) such that for every
|
| 849 |
+
non-negative integer `n` less than `last2 - first2` the condition
|
| 850 |
+
``` cpp
|
| 851 |
+
bool(invoke(pred, invoke(proj1, *(i + n)), invoke(proj2, *(first2 + n))))
|
| 852 |
+
```
|
| 853 |
+
|
| 854 |
+
is `true`.
|
| 855 |
+
- Returns `{last1, last1}` if no such iterator exists.
|
| 856 |
+
|
| 857 |
+
*Complexity:* At most `(last1 - first1) * (last2 - first2)` applications
|
| 858 |
+
of the corresponding predicate and projections.
|
| 859 |
+
|
| 860 |
``` cpp
|
| 861 |
template<class ForwardIterator, class Size, class T>
|
| 862 |
+
constexpr ForwardIterator
|
| 863 |
+
search_n(ForwardIterator first, ForwardIterator last,
|
| 864 |
+
Size count, const T& value);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 865 |
template<class ExecutionPolicy, class ForwardIterator, class Size, class T>
|
| 866 |
ForwardIterator
|
| 867 |
search_n(ExecutionPolicy&& exec,
|
| 868 |
ForwardIterator first, ForwardIterator last,
|
| 869 |
Size count, const T& value);
|
| 870 |
+
|
| 871 |
+
template<class ForwardIterator, class Size, class T,
|
| 872 |
+
class BinaryPredicate>
|
| 873 |
+
constexpr ForwardIterator
|
| 874 |
+
search_n(ForwardIterator first, ForwardIterator last,
|
| 875 |
+
Size count, const T& value,
|
| 876 |
+
BinaryPredicate pred);
|
| 877 |
template<class ExecutionPolicy, class ForwardIterator, class Size, class T,
|
| 878 |
class BinaryPredicate>
|
| 879 |
ForwardIterator
|
| 880 |
search_n(ExecutionPolicy&& exec,
|
| 881 |
ForwardIterator first, ForwardIterator last,
|
| 882 |
Size count, const T& value,
|
| 883 |
BinaryPredicate pred);
|
| 884 |
```
|
| 885 |
|
| 886 |
+
*Mandates:* The type `Size` is convertible to an integral
|
| 887 |
type ([[conv.integral]], [[class.conv]]).
|
| 888 |
|
|
|
|
|
|
|
| 889 |
*Returns:* The first iterator `i` in the range \[`first`, `last-count`)
|
| 890 |
such that for every non-negative integer `n` less than `count` the
|
| 891 |
following corresponding conditions hold:
|
| 892 |
`*(i + n) == value, pred(*(i + n),value) != false`. Returns `last` if no
|
| 893 |
such iterator is found.
|
| 894 |
|
| 895 |
*Complexity:* At most `last - first` applications of the corresponding
|
| 896 |
predicate.
|
| 897 |
|
| 898 |
+
``` cpp
|
| 899 |
+
template<forward_iterator I, sentinel_for<I> S, class T,
|
| 900 |
+
class Pred = ranges::equal_to, class Proj = identity>
|
| 901 |
+
requires indirectly_comparable<I, const T*, Pred, Proj>
|
| 902 |
+
constexpr subrange<I>
|
| 903 |
+
ranges::search_n(I first, S last, iter_difference_t<I> count,
|
| 904 |
+
const T& value, Pred pred = {}, Proj proj = {});
|
| 905 |
+
template<forward_range R, class T, class Pred = ranges::equal_to,
|
| 906 |
+
class Proj = identity>
|
| 907 |
+
requires indirectly_comparable<iterator_t<R>, const T*, Pred, Proj>
|
| 908 |
+
constexpr borrowed_subrange_t<R>
|
| 909 |
+
ranges::search_n(R&& r, range_difference_t<R> count,
|
| 910 |
+
const T& value, Pred pred = {}, Proj proj = {});
|
| 911 |
+
```
|
| 912 |
+
|
| 913 |
+
*Returns:* `{i, i + count}` where `i` is the first iterator in the range
|
| 914 |
+
\[`first`, `last - count`) such that for every non-negative integer `n`
|
| 915 |
+
less than `count`, the following condition holds:
|
| 916 |
+
`invoke(pred, invoke(proj, *(i + n)), value)`. Returns `{last, last}` if
|
| 917 |
+
no such iterator is found.
|
| 918 |
+
|
| 919 |
+
*Complexity:* At most `last - first` applications of the corresponding
|
| 920 |
+
predicate and projection.
|
| 921 |
+
|
| 922 |
``` cpp
|
| 923 |
template<class ForwardIterator, class Searcher>
|
| 924 |
+
constexpr ForwardIterator
|
| 925 |
+
search(ForwardIterator first, ForwardIterator last, const Searcher& searcher);
|
| 926 |
```
|
| 927 |
|
| 928 |
*Effects:* Equivalent to: `return searcher(first, last).first;`
|
| 929 |
|
| 930 |
+
*Remarks:* `Searcher` need not meet the *Cpp17CopyConstructible*
|
| 931 |
requirements.
|
| 932 |
|