- tmp/tmp4qyvvvc9/{from.md → to.md} +6736 -2034
tmp/tmp4qyvvvc9/{from.md → to.md}
RENAMED
|
@@ -1,1164 +1,217 @@
|
|
| 1 |
# Algorithms library <a id="algorithms">[[algorithms]]</a>
|
| 2 |
|
| 3 |
## General <a id="algorithms.general">[[algorithms.general]]</a>
|
| 4 |
|
| 5 |
This Clause describes components that C++ programs may use to perform
|
| 6 |
-
algorithmic operations on containers
|
| 7 |
-
sequences.
|
| 8 |
|
| 9 |
The following subclauses describe components for non-modifying sequence
|
| 10 |
-
operations,
|
| 11 |
operations, and algorithms from the ISO C library, as summarized in
|
| 12 |
-
|
| 13 |
|
| 14 |
-
**Table: Algorithms library summary** <a id="
|
| 15 |
|
| 16 |
| Subclause | | Header |
|
| 17 |
| ---------------------------- | --------------------------------- | ------------- |
|
| 18 |
-
| [[
|
| 19 |
-
| [[
|
|
|
|
|
|
|
| 20 |
| [[alg.sorting]] | Sorting and related operations | |
|
|
|
|
|
|
|
| 21 |
| [[alg.c.library]] | C library algorithms | `<cstdlib>` |
|
| 22 |
|
| 23 |
|
| 24 |
-
## Header `<algorithm>` synopsis <a id="algorithm.syn">[[algorithm.syn]]</a>
|
| 25 |
-
|
| 26 |
-
``` cpp
|
| 27 |
-
#include <initializer_list>
|
| 28 |
-
|
| 29 |
-
namespace std {
|
| 30 |
-
// [alg.nonmodifying], non-modifying sequence operations
|
| 31 |
-
// [alg.all_of], all of
|
| 32 |
-
template <class InputIterator, class Predicate>
|
| 33 |
-
bool all_of(InputIterator first, InputIterator last, Predicate pred);
|
| 34 |
-
template <class ExecutionPolicy, class ForwardIterator, class Predicate>
|
| 35 |
-
bool all_of(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 36 |
-
ForwardIterator first, ForwardIterator last, Predicate pred);
|
| 37 |
-
|
| 38 |
-
// [alg.any_of], any of
|
| 39 |
-
template <class InputIterator, class Predicate>
|
| 40 |
-
bool any_of(InputIterator first, InputIterator last, Predicate pred);
|
| 41 |
-
template <class ExecutionPolicy, class ForwardIterator, class Predicate>
|
| 42 |
-
bool any_of(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 43 |
-
ForwardIterator first, ForwardIterator last, Predicate pred);
|
| 44 |
-
|
| 45 |
-
// [alg.none_of], none of
|
| 46 |
-
template <class InputIterator, class Predicate>
|
| 47 |
-
bool none_of(InputIterator first, InputIterator last, Predicate pred);
|
| 48 |
-
template <class ExecutionPolicy, class ForwardIterator, class Predicate>
|
| 49 |
-
bool none_of(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 50 |
-
ForwardIterator first, ForwardIterator last, Predicate pred);
|
| 51 |
-
|
| 52 |
-
// [alg.foreach], for each
|
| 53 |
-
template<class InputIterator, class Function>
|
| 54 |
-
Function for_each(InputIterator first, InputIterator last, Function f);
|
| 55 |
-
template<class ExecutionPolicy, class ForwardIterator, class Function>
|
| 56 |
-
void for_each(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 57 |
-
ForwardIterator first, ForwardIterator last, Function f);
|
| 58 |
-
template<class InputIterator, class Size, class Function>
|
| 59 |
-
InputIterator for_each_n(InputIterator first, Size n, Function f);
|
| 60 |
-
template<class ExecutionPolicy, class ForwardIterator, class Size, class Function>
|
| 61 |
-
ForwardIterator for_each_n(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 62 |
-
ForwardIterator first, Size n, Function f);
|
| 63 |
-
|
| 64 |
-
// [alg.find], find
|
| 65 |
-
template<class InputIterator, class T>
|
| 66 |
-
InputIterator find(InputIterator first, InputIterator last,
|
| 67 |
-
const T& value);
|
| 68 |
-
template<class ExecutionPolicy, class ForwardIterator, class T>
|
| 69 |
-
ForwardIterator find(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 70 |
-
ForwardIterator first, ForwardIterator last,
|
| 71 |
-
const T& value);
|
| 72 |
-
template<class InputIterator, class Predicate>
|
| 73 |
-
InputIterator find_if(InputIterator first, InputIterator last,
|
| 74 |
-
Predicate pred);
|
| 75 |
-
template<class ExecutionPolicy, class ForwardIterator, class Predicate>
|
| 76 |
-
ForwardIterator find_if(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 77 |
-
ForwardIterator first, ForwardIterator last,
|
| 78 |
-
Predicate pred);
|
| 79 |
-
template<class InputIterator, class Predicate>
|
| 80 |
-
InputIterator find_if_not(InputIterator first, InputIterator last,
|
| 81 |
-
Predicate pred);
|
| 82 |
-
template<class ExecutionPolicy, class ForwardIterator, class Predicate>
|
| 83 |
-
ForwardIterator find_if_not(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 84 |
-
ForwardIterator first, ForwardIterator last,
|
| 85 |
-
Predicate pred);
|
| 86 |
-
|
| 87 |
-
// [alg.find.end], find end
|
| 88 |
-
template<class ForwardIterator1, class ForwardIterator2>
|
| 89 |
-
ForwardIterator1
|
| 90 |
-
find_end(ForwardIterator1 first1, ForwardIterator1 last1,
|
| 91 |
-
ForwardIterator2 first2, ForwardIterator2 last2);
|
| 92 |
-
template<class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
|
| 93 |
-
ForwardIterator1
|
| 94 |
-
find_end(ForwardIterator1 first1, ForwardIterator1 last1,
|
| 95 |
-
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 96 |
-
BinaryPredicate pred);
|
| 97 |
-
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 98 |
-
ForwardIterator1
|
| 99 |
-
find_end(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 100 |
-
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 101 |
-
ForwardIterator2 first2, ForwardIterator2 last2);
|
| 102 |
-
template<class ExecutionPolicy, class ForwardIterator1,
|
| 103 |
-
class ForwardIterator2, class BinaryPredicate>
|
| 104 |
-
ForwardIterator1
|
| 105 |
-
find_end(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 106 |
-
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 107 |
-
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 108 |
-
BinaryPredicate pred);
|
| 109 |
-
|
| 110 |
-
// [alg.find.first.of], find first
|
| 111 |
-
template<class InputIterator, class ForwardIterator>
|
| 112 |
-
InputIterator
|
| 113 |
-
find_first_of(InputIterator first1, InputIterator last1,
|
| 114 |
-
ForwardIterator first2, ForwardIterator last2);
|
| 115 |
-
template<class InputIterator, class ForwardIterator, class BinaryPredicate>
|
| 116 |
-
InputIterator
|
| 117 |
-
find_first_of(InputIterator first1, InputIterator last1,
|
| 118 |
-
ForwardIterator first2, ForwardIterator last2,
|
| 119 |
-
BinaryPredicate pred);
|
| 120 |
-
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 121 |
-
ForwardIterator1
|
| 122 |
-
find_first_of(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 123 |
-
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 124 |
-
ForwardIterator2 first2, ForwardIterator2 last2);
|
| 125 |
-
template<class ExecutionPolicy, class ForwardIterator1,
|
| 126 |
-
class ForwardIterator2, class BinaryPredicate>
|
| 127 |
-
ForwardIterator1
|
| 128 |
-
find_first_of(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 129 |
-
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 130 |
-
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 131 |
-
BinaryPredicate pred);
|
| 132 |
-
|
| 133 |
-
// [alg.adjacent.find], adjacent find
|
| 134 |
-
template<class ForwardIterator>
|
| 135 |
-
ForwardIterator adjacent_find(ForwardIterator first,
|
| 136 |
-
ForwardIterator last);
|
| 137 |
-
template<class ForwardIterator, class BinaryPredicate>
|
| 138 |
-
ForwardIterator adjacent_find(ForwardIterator first,
|
| 139 |
-
ForwardIterator last,
|
| 140 |
-
BinaryPredicate pred);
|
| 141 |
-
template<class ExecutionPolicy, class ForwardIterator>
|
| 142 |
-
ForwardIterator adjacent_find(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 143 |
-
ForwardIterator first,
|
| 144 |
-
ForwardIterator last);
|
| 145 |
-
template<class ExecutionPolicy, class ForwardIterator, class BinaryPredicate>
|
| 146 |
-
ForwardIterator adjacent_find(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 147 |
-
ForwardIterator first,
|
| 148 |
-
ForwardIterator last,
|
| 149 |
-
BinaryPredicate pred);
|
| 150 |
-
|
| 151 |
-
// [alg.count], count
|
| 152 |
-
template<class InputIterator, class T>
|
| 153 |
-
typename iterator_traits<InputIterator>::difference_type
|
| 154 |
-
count(InputIterator first, InputIterator last, const T& value);
|
| 155 |
-
template<class ExecutionPolicy, class ForwardIterator, class T>
|
| 156 |
-
typename iterator_traits<ForwardIterator>::difference_type
|
| 157 |
-
count(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 158 |
-
ForwardIterator first, ForwardIterator last, const T& value);
|
| 159 |
-
template<class InputIterator, class Predicate>
|
| 160 |
-
typename iterator_traits<InputIterator>::difference_type
|
| 161 |
-
count_if(InputIterator first, InputIterator last, Predicate pred);
|
| 162 |
-
template<class ExecutionPolicy, class ForwardIterator, class Predicate>
|
| 163 |
-
typename iterator_traits<ForwardIterator>::difference_type
|
| 164 |
-
count_if(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 165 |
-
ForwardIterator first, ForwardIterator last, Predicate pred);
|
| 166 |
-
|
| 167 |
-
// [mismatch], mismatch
|
| 168 |
-
template<class InputIterator1, class InputIterator2>
|
| 169 |
-
pair<InputIterator1, InputIterator2>
|
| 170 |
-
mismatch(InputIterator1 first1, InputIterator1 last1,
|
| 171 |
-
InputIterator2 first2);
|
| 172 |
-
template<class InputIterator1, class InputIterator2, class BinaryPredicate>
|
| 173 |
-
pair<InputIterator1, InputIterator2>
|
| 174 |
-
mismatch(InputIterator1 first1, InputIterator1 last1,
|
| 175 |
-
InputIterator2 first2, BinaryPredicate pred);
|
| 176 |
-
template<class InputIterator1, class InputIterator2>
|
| 177 |
-
pair<InputIterator1, InputIterator2>
|
| 178 |
-
mismatch(InputIterator1 first1, InputIterator1 last1,
|
| 179 |
-
InputIterator2 first2, InputIterator2 last2);
|
| 180 |
-
template<class InputIterator1, class InputIterator2, class BinaryPredicate>
|
| 181 |
-
pair<InputIterator1, InputIterator2>
|
| 182 |
-
mismatch(InputIterator1 first1, InputIterator1 last1,
|
| 183 |
-
InputIterator2 first2, InputIterator2 last2,
|
| 184 |
-
BinaryPredicate pred);
|
| 185 |
-
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 186 |
-
pair<ForwardIterator1, ForwardIterator2>
|
| 187 |
-
mismatch(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 188 |
-
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 189 |
-
ForwardIterator2 first2);
|
| 190 |
-
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 191 |
-
class BinaryPredicate>
|
| 192 |
-
pair<ForwardIterator1, ForwardIterator2>
|
| 193 |
-
mismatch(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 194 |
-
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 195 |
-
ForwardIterator2 first2, BinaryPredicate pred);
|
| 196 |
-
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 197 |
-
pair<ForwardIterator1, ForwardIterator2>
|
| 198 |
-
mismatch(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 199 |
-
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 200 |
-
ForwardIterator2 first2, ForwardIterator2 last2);
|
| 201 |
-
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 202 |
-
class BinaryPredicate>
|
| 203 |
-
pair<ForwardIterator1, ForwardIterator2>
|
| 204 |
-
mismatch(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 205 |
-
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 206 |
-
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 207 |
-
BinaryPredicate pred);
|
| 208 |
-
|
| 209 |
-
// [alg.equal], equal
|
| 210 |
-
template<class InputIterator1, class InputIterator2>
|
| 211 |
-
bool equal(InputIterator1 first1, InputIterator1 last1,
|
| 212 |
-
InputIterator2 first2);
|
| 213 |
-
template<class InputIterator1, class InputIterator2, class BinaryPredicate>
|
| 214 |
-
bool equal(InputIterator1 first1, InputIterator1 last1,
|
| 215 |
-
InputIterator2 first2, BinaryPredicate pred);
|
| 216 |
-
template<class InputIterator1, class InputIterator2>
|
| 217 |
-
bool equal(InputIterator1 first1, InputIterator1 last1,
|
| 218 |
-
InputIterator2 first2, InputIterator2 last2);
|
| 219 |
-
template<class InputIterator1, class InputIterator2, class BinaryPredicate>
|
| 220 |
-
bool equal(InputIterator1 first1, InputIterator1 last1,
|
| 221 |
-
InputIterator2 first2, InputIterator2 last2,
|
| 222 |
-
BinaryPredicate pred);
|
| 223 |
-
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 224 |
-
bool equal(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 225 |
-
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 226 |
-
ForwardIterator2 first2);
|
| 227 |
-
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 228 |
-
class BinaryPredicate>
|
| 229 |
-
bool equal(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 230 |
-
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 231 |
-
ForwardIterator2 first2, BinaryPredicate pred);
|
| 232 |
-
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 233 |
-
bool equal(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 234 |
-
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 235 |
-
ForwardIterator2 first2, ForwardIterator2 last2);
|
| 236 |
-
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 237 |
-
class BinaryPredicate>
|
| 238 |
-
bool equal(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 239 |
-
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 240 |
-
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 241 |
-
BinaryPredicate pred);
|
| 242 |
-
|
| 243 |
-
// [alg.is_permutation], is permutation
|
| 244 |
-
template<class ForwardIterator1, class ForwardIterator2>
|
| 245 |
-
bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
|
| 246 |
-
ForwardIterator2 first2);
|
| 247 |
-
template<class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
|
| 248 |
-
bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
|
| 249 |
-
ForwardIterator2 first2, BinaryPredicate pred);
|
| 250 |
-
|
| 251 |
-
template<class ForwardIterator1, class ForwardIterator2>
|
| 252 |
-
bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
|
| 253 |
-
ForwardIterator2 first2, ForwardIterator2 last2);
|
| 254 |
-
|
| 255 |
-
template<class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
|
| 256 |
-
bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
|
| 257 |
-
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 258 |
-
BinaryPredicate pred);
|
| 259 |
-
|
| 260 |
-
// [alg.search], search
|
| 261 |
-
template<class ForwardIterator1, class ForwardIterator2>
|
| 262 |
-
ForwardIterator1 search(
|
| 263 |
-
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 264 |
-
ForwardIterator2 first2, ForwardIterator2 last2);
|
| 265 |
-
template<class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
|
| 266 |
-
ForwardIterator1 search(
|
| 267 |
-
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 268 |
-
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 269 |
-
BinaryPredicate pred);
|
| 270 |
-
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 271 |
-
ForwardIterator1 search(
|
| 272 |
-
ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 273 |
-
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 274 |
-
ForwardIterator2 first2, ForwardIterator2 last2);
|
| 275 |
-
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 276 |
-
class BinaryPredicate>
|
| 277 |
-
ForwardIterator1 search(
|
| 278 |
-
ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 279 |
-
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 280 |
-
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 281 |
-
BinaryPredicate pred);
|
| 282 |
-
template<class ForwardIterator, class Size, class T>
|
| 283 |
-
ForwardIterator search_n(ForwardIterator first, ForwardIterator last,
|
| 284 |
-
Size count, const T& value);
|
| 285 |
-
template<class ForwardIterator, class Size, class T, class BinaryPredicate>
|
| 286 |
-
ForwardIterator search_n(ForwardIterator first, ForwardIterator last,
|
| 287 |
-
Size count, const T& value,
|
| 288 |
-
BinaryPredicate pred);
|
| 289 |
-
template<class ExecutionPolicy, class ForwardIterator, class Size, class T>
|
| 290 |
-
ForwardIterator search_n(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 291 |
-
ForwardIterator first, ForwardIterator last,
|
| 292 |
-
Size count, const T& value);
|
| 293 |
-
template<class ExecutionPolicy, class ForwardIterator, class Size, class T,
|
| 294 |
-
class BinaryPredicate>
|
| 295 |
-
ForwardIterator search_n(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 296 |
-
ForwardIterator first, ForwardIterator last,
|
| 297 |
-
Size count, const T& value,
|
| 298 |
-
BinaryPredicate pred);
|
| 299 |
-
|
| 300 |
-
template <class ForwardIterator, class Searcher>
|
| 301 |
-
ForwardIterator search(ForwardIterator first, ForwardIterator last,
|
| 302 |
-
const Searcher& searcher);
|
| 303 |
-
|
| 304 |
-
// [alg.modifying.operations], modifying sequence operations
|
| 305 |
-
// [alg.copy], copy
|
| 306 |
-
template<class InputIterator, class OutputIterator>
|
| 307 |
-
OutputIterator copy(InputIterator first, InputIterator last,
|
| 308 |
-
OutputIterator result);
|
| 309 |
-
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 310 |
-
ForwardIterator2 copy(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 311 |
-
ForwardIterator1 first, ForwardIterator1 last,
|
| 312 |
-
ForwardIterator2 result);
|
| 313 |
-
template<class InputIterator, class Size, class OutputIterator>
|
| 314 |
-
OutputIterator copy_n(InputIterator first, Size n,
|
| 315 |
-
OutputIterator result);
|
| 316 |
-
template<class ExecutionPolicy, class ForwardIterator1, class Size,
|
| 317 |
-
class ForwardIterator2>
|
| 318 |
-
ForwardIterator2 copy_n(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 319 |
-
ForwardIterator1 first, Size n,
|
| 320 |
-
ForwardIterator2 result);
|
| 321 |
-
template<class InputIterator, class OutputIterator, class Predicate>
|
| 322 |
-
OutputIterator copy_if(InputIterator first, InputIterator last,
|
| 323 |
-
OutputIterator result, Predicate pred);
|
| 324 |
-
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 325 |
-
class Predicate>
|
| 326 |
-
ForwardIterator2 copy_if(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 327 |
-
ForwardIterator1 first, ForwardIterator1 last,
|
| 328 |
-
ForwardIterator2 result, Predicate pred);
|
| 329 |
-
template<class BidirectionalIterator1, class BidirectionalIterator2>
|
| 330 |
-
BidirectionalIterator2 copy_backward(
|
| 331 |
-
BidirectionalIterator1 first, BidirectionalIterator1 last,
|
| 332 |
-
BidirectionalIterator2 result);
|
| 333 |
-
|
| 334 |
-
// [alg.move], move
|
| 335 |
-
template<class InputIterator, class OutputIterator>
|
| 336 |
-
OutputIterator move(InputIterator first, InputIterator last,
|
| 337 |
-
OutputIterator result);
|
| 338 |
-
template<class ExecutionPolicy, class ForwardIterator1,
|
| 339 |
-
class ForwardIterator2>
|
| 340 |
-
ForwardIterator2 move(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 341 |
-
ForwardIterator1 first, ForwardIterator1 last,
|
| 342 |
-
ForwardIterator2 result);
|
| 343 |
-
template<class BidirectionalIterator1, class BidirectionalIterator2>
|
| 344 |
-
BidirectionalIterator2 move_backward(
|
| 345 |
-
BidirectionalIterator1 first, BidirectionalIterator1 last,
|
| 346 |
-
BidirectionalIterator2 result);
|
| 347 |
-
|
| 348 |
-
// [alg.swap], swap
|
| 349 |
-
template<class ForwardIterator1, class ForwardIterator2>
|
| 350 |
-
ForwardIterator2 swap_ranges(ForwardIterator1 first1, ForwardIterator1 last1,
|
| 351 |
-
ForwardIterator2 first2);
|
| 352 |
-
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 353 |
-
ForwardIterator2 swap_ranges(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 354 |
-
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 355 |
-
ForwardIterator2 first2);
|
| 356 |
-
template<class ForwardIterator1, class ForwardIterator2>
|
| 357 |
-
void iter_swap(ForwardIterator1 a, ForwardIterator2 b);
|
| 358 |
-
|
| 359 |
-
// [alg.transform], transform
|
| 360 |
-
template<class InputIterator, class OutputIterator, class UnaryOperation>
|
| 361 |
-
OutputIterator transform(InputIterator first, InputIterator last,
|
| 362 |
-
OutputIterator result, UnaryOperation op);
|
| 363 |
-
template<class InputIterator1, class InputIterator2, class OutputIterator,
|
| 364 |
-
class BinaryOperation>
|
| 365 |
-
OutputIterator transform(InputIterator1 first1, InputIterator1 last1,
|
| 366 |
-
InputIterator2 first2, OutputIterator result,
|
| 367 |
-
BinaryOperation binary_op);
|
| 368 |
-
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 369 |
-
class UnaryOperation>
|
| 370 |
-
ForwardIterator2 transform(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 371 |
-
ForwardIterator1 first, ForwardIterator1 last,
|
| 372 |
-
ForwardIterator2 result, UnaryOperation op);
|
| 373 |
-
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 374 |
-
class ForwardIterator, class BinaryOperation>
|
| 375 |
-
ForwardIterator transform(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 376 |
-
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 377 |
-
ForwardIterator2 first2, ForwardIterator result,
|
| 378 |
-
BinaryOperation binary_op);
|
| 379 |
-
|
| 380 |
-
// [alg.replace], replace
|
| 381 |
-
template<class ForwardIterator, class T>
|
| 382 |
-
void replace(ForwardIterator first, ForwardIterator last,
|
| 383 |
-
const T& old_value, const T& new_value);
|
| 384 |
-
template<class ExecutionPolicy, class ForwardIterator, class T>
|
| 385 |
-
void replace(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 386 |
-
ForwardIterator first, ForwardIterator last,
|
| 387 |
-
const T& old_value, const T& new_value);
|
| 388 |
-
template<class ForwardIterator, class Predicate, class T>
|
| 389 |
-
void replace_if(ForwardIterator first, ForwardIterator last,
|
| 390 |
-
Predicate pred, const T& new_value);
|
| 391 |
-
template<class ExecutionPolicy, class ForwardIterator, class Predicate, class T>
|
| 392 |
-
void replace_if(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 393 |
-
ForwardIterator first, ForwardIterator last,
|
| 394 |
-
Predicate pred, const T& new_value);
|
| 395 |
-
template<class InputIterator, class OutputIterator, class T>
|
| 396 |
-
OutputIterator replace_copy(InputIterator first, InputIterator last,
|
| 397 |
-
OutputIterator result,
|
| 398 |
-
const T& old_value, const T& new_value);
|
| 399 |
-
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class T>
|
| 400 |
-
ForwardIterator2 replace_copy(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 401 |
-
ForwardIterator1 first, ForwardIterator1 last,
|
| 402 |
-
ForwardIterator2 result,
|
| 403 |
-
const T& old_value, const T& new_value);
|
| 404 |
-
template<class InputIterator, class OutputIterator, class Predicate, class T>
|
| 405 |
-
OutputIterator replace_copy_if(InputIterator first, InputIterator last,
|
| 406 |
-
OutputIterator result,
|
| 407 |
-
Predicate pred, const T& new_value);
|
| 408 |
-
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 409 |
-
class Predicate, class T>
|
| 410 |
-
ForwardIterator2 replace_copy_if(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 411 |
-
ForwardIterator1 first, ForwardIterator1 last,
|
| 412 |
-
ForwardIterator2 result,
|
| 413 |
-
Predicate pred, const T& new_value);
|
| 414 |
-
|
| 415 |
-
// [alg.fill], fill
|
| 416 |
-
template<class ForwardIterator, class T>
|
| 417 |
-
void fill(ForwardIterator first, ForwardIterator last, const T& value);
|
| 418 |
-
template<class ExecutionPolicy, class ForwardIterator,
|
| 419 |
-
class T>
|
| 420 |
-
void fill(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 421 |
-
ForwardIterator first, ForwardIterator last, const T& value);
|
| 422 |
-
template<class OutputIterator, class Size, class T>
|
| 423 |
-
OutputIterator fill_n(OutputIterator first, Size n, const T& value);
|
| 424 |
-
template<class ExecutionPolicy, class ForwardIterator,
|
| 425 |
-
class Size, class T>
|
| 426 |
-
ForwardIterator fill_n(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 427 |
-
ForwardIterator first, Size n, const T& value);
|
| 428 |
-
|
| 429 |
-
// [alg.generate], generate
|
| 430 |
-
template<class ForwardIterator, class Generator>
|
| 431 |
-
void generate(ForwardIterator first, ForwardIterator last,
|
| 432 |
-
Generator gen);
|
| 433 |
-
template<class ExecutionPolicy, class ForwardIterator, class Generator>
|
| 434 |
-
void generate(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 435 |
-
ForwardIterator first, ForwardIterator last,
|
| 436 |
-
Generator gen);
|
| 437 |
-
template<class OutputIterator, class Size, class Generator>
|
| 438 |
-
OutputIterator generate_n(OutputIterator first, Size n, Generator gen);
|
| 439 |
-
template<class ExecutionPolicy, class ForwardIterator, class Size, class Generator>
|
| 440 |
-
ForwardIterator generate_n(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 441 |
-
ForwardIterator first, Size n, Generator gen);
|
| 442 |
-
|
| 443 |
-
// [alg.remove], remove
|
| 444 |
-
template<class ForwardIterator, class T>
|
| 445 |
-
ForwardIterator remove(ForwardIterator first, ForwardIterator last,
|
| 446 |
-
const T& value);
|
| 447 |
-
template<class ExecutionPolicy, class ForwardIterator, class T>
|
| 448 |
-
ForwardIterator remove(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 449 |
-
ForwardIterator first, ForwardIterator last,
|
| 450 |
-
const T& value);
|
| 451 |
-
template<class ForwardIterator, class Predicate>
|
| 452 |
-
ForwardIterator remove_if(ForwardIterator first, ForwardIterator last,
|
| 453 |
-
Predicate pred);
|
| 454 |
-
template<class ExecutionPolicy, class ForwardIterator, class Predicate>
|
| 455 |
-
ForwardIterator remove_if(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 456 |
-
ForwardIterator first, ForwardIterator last,
|
| 457 |
-
Predicate pred);
|
| 458 |
-
template<class InputIterator, class OutputIterator, class T>
|
| 459 |
-
OutputIterator remove_copy(InputIterator first, InputIterator last,
|
| 460 |
-
OutputIterator result, const T& value);
|
| 461 |
-
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 462 |
-
class T>
|
| 463 |
-
ForwardIterator2 remove_copy(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 464 |
-
ForwardIterator1 first, ForwardIterator1 last,
|
| 465 |
-
ForwardIterator2 result, const T& value);
|
| 466 |
-
template<class InputIterator, class OutputIterator, class Predicate>
|
| 467 |
-
OutputIterator remove_copy_if(InputIterator first, InputIterator last,
|
| 468 |
-
OutputIterator result, Predicate pred);
|
| 469 |
-
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 470 |
-
class Predicate>
|
| 471 |
-
ForwardIterator2 remove_copy_if(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 472 |
-
ForwardIterator1 first, ForwardIterator1 last,
|
| 473 |
-
ForwardIterator2 result, Predicate pred);
|
| 474 |
-
|
| 475 |
-
// [alg.unique], unique
|
| 476 |
-
template<class ForwardIterator>
|
| 477 |
-
ForwardIterator unique(ForwardIterator first, ForwardIterator last);
|
| 478 |
-
template<class ForwardIterator, class BinaryPredicate>
|
| 479 |
-
ForwardIterator unique(ForwardIterator first, ForwardIterator last,
|
| 480 |
-
BinaryPredicate pred);
|
| 481 |
-
template<class ExecutionPolicy, class ForwardIterator>
|
| 482 |
-
ForwardIterator unique(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 483 |
-
ForwardIterator first, ForwardIterator last);
|
| 484 |
-
template<class ExecutionPolicy, class ForwardIterator, class BinaryPredicate>
|
| 485 |
-
ForwardIterator unique(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 486 |
-
ForwardIterator first, ForwardIterator last,
|
| 487 |
-
BinaryPredicate pred);
|
| 488 |
-
template<class InputIterator, class OutputIterator>
|
| 489 |
-
OutputIterator unique_copy(InputIterator first, InputIterator last,
|
| 490 |
-
OutputIterator result);
|
| 491 |
-
template<class InputIterator, class OutputIterator, class BinaryPredicate>
|
| 492 |
-
OutputIterator unique_copy(InputIterator first, InputIterator last,
|
| 493 |
-
OutputIterator result, BinaryPredicate pred);
|
| 494 |
-
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 495 |
-
ForwardIterator2 unique_copy(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 496 |
-
ForwardIterator1 first, ForwardIterator1 last,
|
| 497 |
-
ForwardIterator2 result);
|
| 498 |
-
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 499 |
-
class BinaryPredicate>
|
| 500 |
-
ForwardIterator2 unique_copy(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 501 |
-
ForwardIterator1 first, ForwardIterator1 last,
|
| 502 |
-
ForwardIterator2 result, BinaryPredicate pred);
|
| 503 |
-
|
| 504 |
-
// [alg.reverse], reverse
|
| 505 |
-
template<class BidirectionalIterator>
|
| 506 |
-
void reverse(BidirectionalIterator first, BidirectionalIterator last);
|
| 507 |
-
template<class ExecutionPolicy, class BidirectionalIterator>
|
| 508 |
-
void reverse(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 509 |
-
BidirectionalIterator first, BidirectionalIterator last);
|
| 510 |
-
template<class BidirectionalIterator, class OutputIterator>
|
| 511 |
-
OutputIterator reverse_copy(BidirectionalIterator first,
|
| 512 |
-
BidirectionalIterator last,
|
| 513 |
-
OutputIterator result);
|
| 514 |
-
template<class ExecutionPolicy, class BidirectionalIterator, class ForwardIterator>
|
| 515 |
-
ForwardIterator reverse_copy(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 516 |
-
BidirectionalIterator first,
|
| 517 |
-
BidirectionalIterator last,
|
| 518 |
-
ForwardIterator result);
|
| 519 |
-
|
| 520 |
-
// [alg.rotate], rotate
|
| 521 |
-
template<class ForwardIterator>
|
| 522 |
-
ForwardIterator rotate(ForwardIterator first,
|
| 523 |
-
ForwardIterator middle,
|
| 524 |
-
ForwardIterator last);
|
| 525 |
-
template<class ExecutionPolicy, class ForwardIterator>
|
| 526 |
-
ForwardIterator rotate(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 527 |
-
ForwardIterator first,
|
| 528 |
-
ForwardIterator middle,
|
| 529 |
-
ForwardIterator last);
|
| 530 |
-
template<class ForwardIterator, class OutputIterator>
|
| 531 |
-
OutputIterator rotate_copy(
|
| 532 |
-
ForwardIterator first, ForwardIterator middle,
|
| 533 |
-
ForwardIterator last, OutputIterator result);
|
| 534 |
-
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 535 |
-
ForwardIterator2 rotate_copy(
|
| 536 |
-
ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 537 |
-
ForwardIterator1 first, ForwardIterator1 middle,
|
| 538 |
-
ForwardIterator1 last, ForwardIterator2 result);
|
| 539 |
-
|
| 540 |
-
// [alg.random.sample], sample
|
| 541 |
-
template<class PopulationIterator, class SampleIterator,
|
| 542 |
-
class Distance, class UniformRandomBitGenerator>
|
| 543 |
-
SampleIterator sample(PopulationIterator first, PopulationIterator last,
|
| 544 |
-
SampleIterator out, Distance n,
|
| 545 |
-
UniformRandomBitGenerator&& g);
|
| 546 |
-
|
| 547 |
-
// [alg.random.shuffle], shuffle
|
| 548 |
-
template<class RandomAccessIterator, class UniformRandomBitGenerator>
|
| 549 |
-
void shuffle(RandomAccessIterator first,
|
| 550 |
-
RandomAccessIterator last,
|
| 551 |
-
UniformRandomBitGenerator&& g);
|
| 552 |
-
|
| 553 |
-
// [alg.partitions], partitions
|
| 554 |
-
template <class InputIterator, class Predicate>
|
| 555 |
-
bool is_partitioned(InputIterator first, InputIterator last, Predicate pred);
|
| 556 |
-
template <class ExecutionPolicy, class ForwardIterator, class Predicate>
|
| 557 |
-
bool is_partitioned(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 558 |
-
ForwardIterator first, ForwardIterator last, Predicate pred);
|
| 559 |
-
|
| 560 |
-
template<class ForwardIterator, class Predicate>
|
| 561 |
-
ForwardIterator partition(ForwardIterator first,
|
| 562 |
-
ForwardIterator last,
|
| 563 |
-
Predicate pred);
|
| 564 |
-
template<class ExecutionPolicy, class ForwardIterator, class Predicate>
|
| 565 |
-
ForwardIterator partition(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 566 |
-
ForwardIterator first,
|
| 567 |
-
ForwardIterator last,
|
| 568 |
-
Predicate pred);
|
| 569 |
-
template<class BidirectionalIterator, class Predicate>
|
| 570 |
-
BidirectionalIterator stable_partition(BidirectionalIterator first,
|
| 571 |
-
BidirectionalIterator last,
|
| 572 |
-
Predicate pred);
|
| 573 |
-
template<class ExecutionPolicy, class BidirectionalIterator, class Predicate>
|
| 574 |
-
BidirectionalIterator stable_partition(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 575 |
-
BidirectionalIterator first,
|
| 576 |
-
BidirectionalIterator last,
|
| 577 |
-
Predicate pred);
|
| 578 |
-
template <class InputIterator, class OutputIterator1,
|
| 579 |
-
class OutputIterator2, class Predicate>
|
| 580 |
-
pair<OutputIterator1, OutputIterator2>
|
| 581 |
-
partition_copy(InputIterator first, InputIterator last,
|
| 582 |
-
OutputIterator1 out_true, OutputIterator2 out_false,
|
| 583 |
-
Predicate pred);
|
| 584 |
-
template <class ExecutionPolicy, class ForwardIterator, class ForwardIterator1,
|
| 585 |
-
class ForwardIterator2, class Predicate>
|
| 586 |
-
pair<ForwardIterator1, ForwardIterator2>
|
| 587 |
-
partition_copy(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 588 |
-
ForwardIterator first, ForwardIterator last,
|
| 589 |
-
ForwardIterator1 out_true, ForwardIterator2 out_false,
|
| 590 |
-
Predicate pred);
|
| 591 |
-
template<class ForwardIterator, class Predicate>
|
| 592 |
-
ForwardIterator partition_point(ForwardIterator first,
|
| 593 |
-
ForwardIterator last,
|
| 594 |
-
Predicate pred);
|
| 595 |
-
|
| 596 |
-
// [alg.sorting], sorting and related operations
|
| 597 |
-
// [alg.sort], sorting
|
| 598 |
-
template<class RandomAccessIterator>
|
| 599 |
-
void sort(RandomAccessIterator first, RandomAccessIterator last);
|
| 600 |
-
template<class RandomAccessIterator, class Compare>
|
| 601 |
-
void sort(RandomAccessIterator first, RandomAccessIterator last,
|
| 602 |
-
Compare comp);
|
| 603 |
-
template<class ExecutionPolicy, class RandomAccessIterator>
|
| 604 |
-
void sort(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 605 |
-
RandomAccessIterator first, RandomAccessIterator last);
|
| 606 |
-
template<class ExecutionPolicy, class RandomAccessIterator, class Compare>
|
| 607 |
-
void sort(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 608 |
-
RandomAccessIterator first, RandomAccessIterator last,
|
| 609 |
-
Compare comp);
|
| 610 |
-
|
| 611 |
-
template<class RandomAccessIterator>
|
| 612 |
-
void stable_sort(RandomAccessIterator first, RandomAccessIterator last);
|
| 613 |
-
template<class RandomAccessIterator, class Compare>
|
| 614 |
-
void stable_sort(RandomAccessIterator first, RandomAccessIterator last,
|
| 615 |
-
Compare comp);
|
| 616 |
-
template<class ExecutionPolicy, class RandomAccessIterator>
|
| 617 |
-
void stable_sort(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 618 |
-
RandomAccessIterator first, RandomAccessIterator last);
|
| 619 |
-
template<class ExecutionPolicy, class RandomAccessIterator, class Compare>
|
| 620 |
-
void stable_sort(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 621 |
-
RandomAccessIterator first, RandomAccessIterator last,
|
| 622 |
-
Compare comp);
|
| 623 |
-
|
| 624 |
-
template<class RandomAccessIterator>
|
| 625 |
-
void partial_sort(RandomAccessIterator first,
|
| 626 |
-
RandomAccessIterator middle,
|
| 627 |
-
RandomAccessIterator last);
|
| 628 |
-
template<class RandomAccessIterator, class Compare>
|
| 629 |
-
void partial_sort(RandomAccessIterator first,
|
| 630 |
-
RandomAccessIterator middle,
|
| 631 |
-
RandomAccessIterator last, Compare comp);
|
| 632 |
-
template<class ExecutionPolicy, class RandomAccessIterator>
|
| 633 |
-
void partial_sort(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 634 |
-
RandomAccessIterator first,
|
| 635 |
-
RandomAccessIterator middle,
|
| 636 |
-
RandomAccessIterator last);
|
| 637 |
-
template<class ExecutionPolicy, class RandomAccessIterator, class Compare>
|
| 638 |
-
void partial_sort(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 639 |
-
RandomAccessIterator first,
|
| 640 |
-
RandomAccessIterator middle,
|
| 641 |
-
RandomAccessIterator last, Compare comp);
|
| 642 |
-
template<class InputIterator, class RandomAccessIterator>
|
| 643 |
-
RandomAccessIterator partial_sort_copy(
|
| 644 |
-
InputIterator first, InputIterator last,
|
| 645 |
-
RandomAccessIterator result_first,
|
| 646 |
-
RandomAccessIterator result_last);
|
| 647 |
-
template<class InputIterator, class RandomAccessIterator, class Compare>
|
| 648 |
-
RandomAccessIterator partial_sort_copy(
|
| 649 |
-
InputIterator first, InputIterator last,
|
| 650 |
-
RandomAccessIterator result_first,
|
| 651 |
-
RandomAccessIterator result_last,
|
| 652 |
-
Compare comp);
|
| 653 |
-
template<class ExecutionPolicy, class ForwardIterator, class RandomAccessIterator>
|
| 654 |
-
RandomAccessIterator partial_sort_copy(
|
| 655 |
-
ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 656 |
-
ForwardIterator first, ForwardIterator last,
|
| 657 |
-
RandomAccessIterator result_first,
|
| 658 |
-
RandomAccessIterator result_last);
|
| 659 |
-
template<class ExecutionPolicy, class ForwardIterator, class RandomAccessIterator,
|
| 660 |
-
class Compare>
|
| 661 |
-
RandomAccessIterator partial_sort_copy(
|
| 662 |
-
ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 663 |
-
ForwardIterator first, ForwardIterator last,
|
| 664 |
-
RandomAccessIterator result_first,
|
| 665 |
-
RandomAccessIterator result_last,
|
| 666 |
-
Compare comp);
|
| 667 |
-
template<class ForwardIterator>
|
| 668 |
-
bool is_sorted(ForwardIterator first, ForwardIterator last);
|
| 669 |
-
template<class ForwardIterator, class Compare>
|
| 670 |
-
bool is_sorted(ForwardIterator first, ForwardIterator last,
|
| 671 |
-
Compare comp);
|
| 672 |
-
template<class ExecutionPolicy, class ForwardIterator>
|
| 673 |
-
bool is_sorted(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 674 |
-
ForwardIterator first, ForwardIterator last);
|
| 675 |
-
template<class ExecutionPolicy, class ForwardIterator, class Compare>
|
| 676 |
-
bool is_sorted(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 677 |
-
ForwardIterator first, ForwardIterator last,
|
| 678 |
-
Compare comp);
|
| 679 |
-
template<class ForwardIterator>
|
| 680 |
-
ForwardIterator is_sorted_until(ForwardIterator first, ForwardIterator last);
|
| 681 |
-
template<class ForwardIterator, class Compare>
|
| 682 |
-
ForwardIterator is_sorted_until(ForwardIterator first, ForwardIterator last,
|
| 683 |
-
Compare comp);
|
| 684 |
-
template<class ExecutionPolicy, class ForwardIterator>
|
| 685 |
-
ForwardIterator is_sorted_until(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 686 |
-
ForwardIterator first, ForwardIterator last);
|
| 687 |
-
template<class ExecutionPolicy, class ForwardIterator, class Compare>
|
| 688 |
-
ForwardIterator is_sorted_until(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 689 |
-
ForwardIterator first, ForwardIterator last,
|
| 690 |
-
Compare comp);
|
| 691 |
-
|
| 692 |
-
// [alg.nth.element], Nth element
|
| 693 |
-
template<class RandomAccessIterator>
|
| 694 |
-
void nth_element(RandomAccessIterator first, RandomAccessIterator nth,
|
| 695 |
-
RandomAccessIterator last);
|
| 696 |
-
template<class RandomAccessIterator, class Compare>
|
| 697 |
-
void nth_element(RandomAccessIterator first, RandomAccessIterator nth,
|
| 698 |
-
RandomAccessIterator last, Compare comp);
|
| 699 |
-
template<class ExecutionPolicy, class RandomAccessIterator>
|
| 700 |
-
void nth_element(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 701 |
-
RandomAccessIterator first, RandomAccessIterator nth,
|
| 702 |
-
RandomAccessIterator last);
|
| 703 |
-
template<class ExecutionPolicy, class RandomAccessIterator, class Compare>
|
| 704 |
-
void nth_element(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 705 |
-
RandomAccessIterator first, RandomAccessIterator nth,
|
| 706 |
-
RandomAccessIterator last, Compare comp);
|
| 707 |
-
|
| 708 |
-
// [alg.binary.search], binary search
|
| 709 |
-
template<class ForwardIterator, class T>
|
| 710 |
-
ForwardIterator lower_bound(ForwardIterator first, ForwardIterator last,
|
| 711 |
-
const T& value);
|
| 712 |
-
template<class ForwardIterator, class T, class Compare>
|
| 713 |
-
ForwardIterator lower_bound(ForwardIterator first, ForwardIterator last,
|
| 714 |
-
const T& value, Compare comp);
|
| 715 |
-
|
| 716 |
-
template<class ForwardIterator, class T>
|
| 717 |
-
ForwardIterator upper_bound(ForwardIterator first, ForwardIterator last,
|
| 718 |
-
const T& value);
|
| 719 |
-
template<class ForwardIterator, class T, class Compare>
|
| 720 |
-
ForwardIterator upper_bound(ForwardIterator first, ForwardIterator last,
|
| 721 |
-
const T& value, Compare comp);
|
| 722 |
-
|
| 723 |
-
template<class ForwardIterator, class T>
|
| 724 |
-
pair<ForwardIterator, ForwardIterator>
|
| 725 |
-
equal_range(ForwardIterator first, ForwardIterator last,
|
| 726 |
-
const T& value);
|
| 727 |
-
template<class ForwardIterator, class T, class Compare>
|
| 728 |
-
pair<ForwardIterator, ForwardIterator>
|
| 729 |
-
equal_range(ForwardIterator first, ForwardIterator last,
|
| 730 |
-
const T& value, Compare comp);
|
| 731 |
-
|
| 732 |
-
template<class ForwardIterator, class T>
|
| 733 |
-
bool binary_search(ForwardIterator first, ForwardIterator last,
|
| 734 |
-
const T& value);
|
| 735 |
-
template<class ForwardIterator, class T, class Compare>
|
| 736 |
-
bool binary_search(ForwardIterator first, ForwardIterator last,
|
| 737 |
-
const T& value, Compare comp);
|
| 738 |
-
|
| 739 |
-
// [alg.merge], merge
|
| 740 |
-
template<class InputIterator1, class InputIterator2, class OutputIterator>
|
| 741 |
-
OutputIterator merge(InputIterator1 first1, InputIterator1 last1,
|
| 742 |
-
InputIterator2 first2, InputIterator2 last2,
|
| 743 |
-
OutputIterator result);
|
| 744 |
-
template<class InputIterator1, class InputIterator2, class OutputIterator,
|
| 745 |
-
class Compare>
|
| 746 |
-
OutputIterator merge(InputIterator1 first1, InputIterator1 last1,
|
| 747 |
-
InputIterator2 first2, InputIterator2 last2,
|
| 748 |
-
OutputIterator result, Compare comp);
|
| 749 |
-
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 750 |
-
class ForwardIterator>
|
| 751 |
-
ForwardIterator merge(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 752 |
-
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 753 |
-
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 754 |
-
ForwardIterator result);
|
| 755 |
-
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 756 |
-
class ForwardIterator, class Compare>
|
| 757 |
-
ForwardIterator merge(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 758 |
-
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 759 |
-
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 760 |
-
ForwardIterator result, Compare comp);
|
| 761 |
-
|
| 762 |
-
template<class BidirectionalIterator>
|
| 763 |
-
void inplace_merge(BidirectionalIterator first,
|
| 764 |
-
BidirectionalIterator middle,
|
| 765 |
-
BidirectionalIterator last);
|
| 766 |
-
template<class BidirectionalIterator, class Compare>
|
| 767 |
-
void inplace_merge(BidirectionalIterator first,
|
| 768 |
-
BidirectionalIterator middle,
|
| 769 |
-
BidirectionalIterator last, Compare comp);
|
| 770 |
-
template<class ExecutionPolicy, class BidirectionalIterator>
|
| 771 |
-
void inplace_merge(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 772 |
-
BidirectionalIterator first,
|
| 773 |
-
BidirectionalIterator middle,
|
| 774 |
-
BidirectionalIterator last);
|
| 775 |
-
template<class ExecutionPolicy, class BidirectionalIterator, class Compare>
|
| 776 |
-
void inplace_merge(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 777 |
-
BidirectionalIterator first,
|
| 778 |
-
BidirectionalIterator middle,
|
| 779 |
-
BidirectionalIterator last, Compare comp);
|
| 780 |
-
|
| 781 |
-
// [alg.set.operations], set operations
|
| 782 |
-
template<class InputIterator1, class InputIterator2>
|
| 783 |
-
bool includes(InputIterator1 first1, InputIterator1 last1,
|
| 784 |
-
InputIterator2 first2, InputIterator2 last2);
|
| 785 |
-
template<class InputIterator1, class InputIterator2, class Compare>
|
| 786 |
-
bool includes(InputIterator1 first1, InputIterator1 last1,
|
| 787 |
-
InputIterator2 first2, InputIterator2 last2, Compare comp);
|
| 788 |
-
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 789 |
-
bool includes(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 790 |
-
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 791 |
-
ForwardIterator2 first2, ForwardIterator2 last2);
|
| 792 |
-
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 793 |
-
class Compare>
|
| 794 |
-
bool includes(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 795 |
-
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 796 |
-
ForwardIterator2 first2, ForwardIterator2 last2, Compare comp);
|
| 797 |
-
|
| 798 |
-
template<class InputIterator1, class InputIterator2, class OutputIterator>
|
| 799 |
-
OutputIterator set_union(InputIterator1 first1, InputIterator1 last1,
|
| 800 |
-
InputIterator2 first2, InputIterator2 last2,
|
| 801 |
-
OutputIterator result);
|
| 802 |
-
template<class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
|
| 803 |
-
OutputIterator set_union(InputIterator1 first1, InputIterator1 last1,
|
| 804 |
-
InputIterator2 first2, InputIterator2 last2,
|
| 805 |
-
OutputIterator result, Compare comp);
|
| 806 |
-
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 807 |
-
class ForwardIterator>
|
| 808 |
-
ForwardIterator set_union(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 809 |
-
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 810 |
-
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 811 |
-
ForwardIterator result);
|
| 812 |
-
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 813 |
-
class ForwardIterator, class Compare>
|
| 814 |
-
ForwardIterator set_union(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 815 |
-
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 816 |
-
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 817 |
-
ForwardIterator result, Compare comp);
|
| 818 |
-
|
| 819 |
-
template<class InputIterator1, class InputIterator2, class OutputIterator>
|
| 820 |
-
OutputIterator set_intersection(
|
| 821 |
-
InputIterator1 first1, InputIterator1 last1,
|
| 822 |
-
InputIterator2 first2, InputIterator2 last2,
|
| 823 |
-
OutputIterator result);
|
| 824 |
-
template<class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
|
| 825 |
-
OutputIterator set_intersection(
|
| 826 |
-
InputIterator1 first1, InputIterator1 last1,
|
| 827 |
-
InputIterator2 first2, InputIterator2 last2,
|
| 828 |
-
OutputIterator result, Compare comp);
|
| 829 |
-
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 830 |
-
class ForwardIterator>
|
| 831 |
-
ForwardIterator set_intersection(
|
| 832 |
-
ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 833 |
-
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 834 |
-
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 835 |
-
ForwardIterator result);
|
| 836 |
-
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 837 |
-
class ForwardIterator, class Compare>
|
| 838 |
-
ForwardIterator set_intersection(
|
| 839 |
-
ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 840 |
-
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 841 |
-
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 842 |
-
ForwardIterator result, Compare comp);
|
| 843 |
-
|
| 844 |
-
template<class InputIterator1, class InputIterator2, class OutputIterator>
|
| 845 |
-
OutputIterator set_difference(
|
| 846 |
-
InputIterator1 first1, InputIterator1 last1,
|
| 847 |
-
InputIterator2 first2, InputIterator2 last2,
|
| 848 |
-
OutputIterator result);
|
| 849 |
-
template<class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
|
| 850 |
-
OutputIterator set_difference(
|
| 851 |
-
InputIterator1 first1, InputIterator1 last1,
|
| 852 |
-
InputIterator2 first2, InputIterator2 last2,
|
| 853 |
-
OutputIterator result, Compare comp);
|
| 854 |
-
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 855 |
-
class ForwardIterator>
|
| 856 |
-
ForwardIterator set_difference(
|
| 857 |
-
ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 858 |
-
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 859 |
-
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 860 |
-
ForwardIterator result);
|
| 861 |
-
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 862 |
-
class ForwardIterator, class Compare>
|
| 863 |
-
ForwardIterator set_difference(
|
| 864 |
-
ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 865 |
-
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 866 |
-
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 867 |
-
ForwardIterator result, Compare comp);
|
| 868 |
-
|
| 869 |
-
template<class InputIterator1, class InputIterator2, class OutputIterator>
|
| 870 |
-
OutputIterator set_symmetric_difference(
|
| 871 |
-
InputIterator1 first1, InputIterator1 last1,
|
| 872 |
-
InputIterator2 first2, InputIterator2 last2,
|
| 873 |
-
OutputIterator result);
|
| 874 |
-
template<class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
|
| 875 |
-
OutputIterator set_symmetric_difference(
|
| 876 |
-
InputIterator1 first1, InputIterator1 last1,
|
| 877 |
-
InputIterator2 first2, InputIterator2 last2,
|
| 878 |
-
OutputIterator result, Compare comp);
|
| 879 |
-
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 880 |
-
class ForwardIterator>
|
| 881 |
-
ForwardIterator set_symmetric_difference(
|
| 882 |
-
ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 883 |
-
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 884 |
-
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 885 |
-
ForwardIterator result);
|
| 886 |
-
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 887 |
-
class ForwardIterator, class Compare>
|
| 888 |
-
ForwardIterator set_symmetric_difference(
|
| 889 |
-
ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 890 |
-
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 891 |
-
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 892 |
-
ForwardIterator result, Compare comp);
|
| 893 |
-
|
| 894 |
-
// [alg.heap.operations], heap operations
|
| 895 |
-
template<class RandomAccessIterator>
|
| 896 |
-
void push_heap(RandomAccessIterator first, RandomAccessIterator last);
|
| 897 |
-
template<class RandomAccessIterator, class Compare>
|
| 898 |
-
void push_heap(RandomAccessIterator first, RandomAccessIterator last,
|
| 899 |
-
Compare comp);
|
| 900 |
-
|
| 901 |
-
template<class RandomAccessIterator>
|
| 902 |
-
void pop_heap(RandomAccessIterator first, RandomAccessIterator last);
|
| 903 |
-
template<class RandomAccessIterator, class Compare>
|
| 904 |
-
void pop_heap(RandomAccessIterator first, RandomAccessIterator last,
|
| 905 |
-
Compare comp);
|
| 906 |
-
|
| 907 |
-
template<class RandomAccessIterator>
|
| 908 |
-
void make_heap(RandomAccessIterator first, RandomAccessIterator last);
|
| 909 |
-
template<class RandomAccessIterator, class Compare>
|
| 910 |
-
void make_heap(RandomAccessIterator first, RandomAccessIterator last,
|
| 911 |
-
Compare comp);
|
| 912 |
-
|
| 913 |
-
template<class RandomAccessIterator>
|
| 914 |
-
void sort_heap(RandomAccessIterator first, RandomAccessIterator last);
|
| 915 |
-
template<class RandomAccessIterator, class Compare>
|
| 916 |
-
void sort_heap(RandomAccessIterator first, RandomAccessIterator last,
|
| 917 |
-
Compare comp);
|
| 918 |
-
|
| 919 |
-
template<class RandomAccessIterator>
|
| 920 |
-
bool is_heap(RandomAccessIterator first, RandomAccessIterator last);
|
| 921 |
-
template<class RandomAccessIterator, class Compare>
|
| 922 |
-
bool is_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
|
| 923 |
-
template<class ExecutionPolicy, class RandomAccessIterator>
|
| 924 |
-
bool is_heap(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 925 |
-
RandomAccessIterator first, RandomAccessIterator last);
|
| 926 |
-
template<class ExecutionPolicy, class RandomAccessIterator, class Compare>
|
| 927 |
-
bool is_heap(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 928 |
-
RandomAccessIterator first, RandomAccessIterator last, Compare comp);
|
| 929 |
-
template<class RandomAccessIterator>
|
| 930 |
-
RandomAccessIterator is_heap_until(RandomAccessIterator first, RandomAccessIterator last);
|
| 931 |
-
template<class RandomAccessIterator, class Compare>
|
| 932 |
-
RandomAccessIterator is_heap_until(RandomAccessIterator first, RandomAccessIterator last,
|
| 933 |
-
Compare comp);
|
| 934 |
-
template<class ExecutionPolicy, class RandomAccessIterator>
|
| 935 |
-
RandomAccessIterator is_heap_until(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 936 |
-
RandomAccessIterator first, RandomAccessIterator last);
|
| 937 |
-
template<class ExecutionPolicy, class RandomAccessIterator, class Compare>
|
| 938 |
-
RandomAccessIterator is_heap_until(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 939 |
-
RandomAccessIterator first, RandomAccessIterator last,
|
| 940 |
-
Compare comp);
|
| 941 |
-
|
| 942 |
-
// [alg.min.max], minimum and maximum
|
| 943 |
-
template<class T> constexpr const T& min(const T& a, const T& b);
|
| 944 |
-
template<class T, class Compare>
|
| 945 |
-
constexpr const T& min(const T& a, const T& b, Compare comp);
|
| 946 |
-
template<class T>
|
| 947 |
-
constexpr T min(initializer_list<T> t);
|
| 948 |
-
template<class T, class Compare>
|
| 949 |
-
constexpr T min(initializer_list<T> t, Compare comp);
|
| 950 |
-
|
| 951 |
-
template<class T> constexpr const T& max(const T& a, const T& b);
|
| 952 |
-
template<class T, class Compare>
|
| 953 |
-
constexpr const T& max(const T& a, const T& b, Compare comp);
|
| 954 |
-
template<class T>
|
| 955 |
-
constexpr T max(initializer_list<T> t);
|
| 956 |
-
template<class T, class Compare>
|
| 957 |
-
constexpr T max(initializer_list<T> t, Compare comp);
|
| 958 |
-
|
| 959 |
-
template<class T> constexpr pair<const T&, const T&> minmax(const T& a, const T& b);
|
| 960 |
-
template<class T, class Compare>
|
| 961 |
-
constexpr pair<const T&, const T&> minmax(const T& a, const T& b, Compare comp);
|
| 962 |
-
template<class T>
|
| 963 |
-
constexpr pair<T, T> minmax(initializer_list<T> t);
|
| 964 |
-
template<class T, class Compare>
|
| 965 |
-
constexpr pair<T, T> minmax(initializer_list<T> t, Compare comp);
|
| 966 |
-
|
| 967 |
-
template<class ForwardIterator>
|
| 968 |
-
constexpr ForwardIterator min_element(ForwardIterator first, ForwardIterator last);
|
| 969 |
-
template<class ForwardIterator, class Compare>
|
| 970 |
-
constexpr ForwardIterator min_element(ForwardIterator first, ForwardIterator last,
|
| 971 |
-
Compare comp);
|
| 972 |
-
template<class ExecutionPolicy, class ForwardIterator>
|
| 973 |
-
ForwardIterator min_element(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 974 |
-
ForwardIterator first, ForwardIterator last);
|
| 975 |
-
template<class ExecutionPolicy, class ForwardIterator, class Compare>
|
| 976 |
-
ForwardIterator min_element(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 977 |
-
ForwardIterator first, ForwardIterator last,
|
| 978 |
-
Compare comp);
|
| 979 |
-
template<class ForwardIterator>
|
| 980 |
-
constexpr ForwardIterator max_element(ForwardIterator first, ForwardIterator last);
|
| 981 |
-
template<class ForwardIterator, class Compare>
|
| 982 |
-
constexpr ForwardIterator max_element(ForwardIterator first, ForwardIterator last,
|
| 983 |
-
Compare comp);
|
| 984 |
-
template<class ExecutionPolicy, class ForwardIterator>
|
| 985 |
-
ForwardIterator max_element(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 986 |
-
ForwardIterator first, ForwardIterator last);
|
| 987 |
-
template<class ExecutionPolicy, class ForwardIterator, class Compare>
|
| 988 |
-
ForwardIterator max_element(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 989 |
-
ForwardIterator first, ForwardIterator last,
|
| 990 |
-
Compare comp);
|
| 991 |
-
template<class ForwardIterator>
|
| 992 |
-
constexpr pair<ForwardIterator, ForwardIterator>
|
| 993 |
-
minmax_element(ForwardIterator first, ForwardIterator last);
|
| 994 |
-
template<class ForwardIterator, class Compare>
|
| 995 |
-
constexpr pair<ForwardIterator, ForwardIterator>
|
| 996 |
-
minmax_element(ForwardIterator first, ForwardIterator last, Compare comp);
|
| 997 |
-
template<class ExecutionPolicy, class ForwardIterator>
|
| 998 |
-
pair<ForwardIterator, ForwardIterator>
|
| 999 |
-
minmax_element(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 1000 |
-
ForwardIterator first, ForwardIterator last);
|
| 1001 |
-
template<class ExecutionPolicy, class ForwardIterator, class Compare>
|
| 1002 |
-
pair<ForwardIterator, ForwardIterator>
|
| 1003 |
-
minmax_element(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 1004 |
-
ForwardIterator first, ForwardIterator last, Compare comp);
|
| 1005 |
-
|
| 1006 |
-
// [alg.clamp], bounded value
|
| 1007 |
-
template<class T>
|
| 1008 |
-
constexpr const T& clamp(const T& v, const T& lo, const T& hi);
|
| 1009 |
-
template<class T, class Compare>
|
| 1010 |
-
constexpr const T& clamp(const T& v, const T& lo, const T& hi, Compare comp);
|
| 1011 |
-
|
| 1012 |
-
// [alg.lex.comparison], lexicographical comparison
|
| 1013 |
-
template<class InputIterator1, class InputIterator2>
|
| 1014 |
-
bool lexicographical_compare(
|
| 1015 |
-
InputIterator1 first1, InputIterator1 last1,
|
| 1016 |
-
InputIterator2 first2, InputIterator2 last2);
|
| 1017 |
-
template<class InputIterator1, class InputIterator2, class Compare>
|
| 1018 |
-
bool lexicographical_compare(
|
| 1019 |
-
InputIterator1 first1, InputIterator1 last1,
|
| 1020 |
-
InputIterator2 first2, InputIterator2 last2,
|
| 1021 |
-
Compare comp);
|
| 1022 |
-
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 1023 |
-
bool lexicographical_compare(
|
| 1024 |
-
ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 1025 |
-
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 1026 |
-
ForwardIterator2 first2, ForwardIterator2 last2);
|
| 1027 |
-
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 1028 |
-
class Compare>
|
| 1029 |
-
bool lexicographical_compare(
|
| 1030 |
-
ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 1031 |
-
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 1032 |
-
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 1033 |
-
Compare comp);
|
| 1034 |
-
|
| 1035 |
-
// [alg.permutation.generators], permutations
|
| 1036 |
-
template<class BidirectionalIterator>
|
| 1037 |
-
bool next_permutation(BidirectionalIterator first,
|
| 1038 |
-
BidirectionalIterator last);
|
| 1039 |
-
template<class BidirectionalIterator, class Compare>
|
| 1040 |
-
bool next_permutation(BidirectionalIterator first,
|
| 1041 |
-
BidirectionalIterator last, Compare comp);
|
| 1042 |
-
template<class BidirectionalIterator>
|
| 1043 |
-
bool prev_permutation(BidirectionalIterator first,
|
| 1044 |
-
BidirectionalIterator last);
|
| 1045 |
-
template<class BidirectionalIterator, class Compare>
|
| 1046 |
-
bool prev_permutation(BidirectionalIterator first,
|
| 1047 |
-
BidirectionalIterator last, Compare comp);
|
| 1048 |
-
}
|
| 1049 |
-
```
|
| 1050 |
-
|
| 1051 |
## Algorithms requirements <a id="algorithms.requirements">[[algorithms.requirements]]</a>
|
| 1052 |
|
| 1053 |
All of the algorithms are separated from the particular implementations
|
| 1054 |
of data structures and are parameterized by iterator types. Because of
|
| 1055 |
this, they can work with program-defined data structures, as long as
|
| 1056 |
these data structures have iterator types satisfying the assumptions on
|
| 1057 |
the algorithms.
|
| 1058 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1059 |
For purposes of determining the existence of data races, algorithms
|
| 1060 |
shall not modify objects referenced through an iterator argument unless
|
| 1061 |
the specification requires such modification.
|
| 1062 |
|
| 1063 |
-
Throughout this Clause, the
|
| 1064 |
-
express type
|
|
|
|
| 1065 |
|
| 1066 |
- If an algorithm’s template parameter is named `InputIterator`,
|
| 1067 |
`InputIterator1`, or `InputIterator2`, the template argument shall
|
| 1068 |
-
|
| 1069 |
- If an algorithm’s template parameter is named `OutputIterator`,
|
| 1070 |
`OutputIterator1`, or `OutputIterator2`, the template argument shall
|
| 1071 |
-
|
| 1072 |
-
[[output.iterators]]).
|
| 1073 |
- If an algorithm’s template parameter is named `ForwardIterator`,
|
| 1074 |
`ForwardIterator1`, or `ForwardIterator2`, the template argument shall
|
| 1075 |
-
|
| 1076 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1077 |
- If an algorithm’s template parameter is named `BidirectionalIterator`,
|
| 1078 |
`BidirectionalIterator1`, or `BidirectionalIterator2`, the template
|
| 1079 |
-
argument shall
|
| 1080 |
-
[[bidirectional.iterators]]
|
| 1081 |
- If an algorithm’s template parameter is named `RandomAccessIterator`,
|
| 1082 |
`RandomAccessIterator1`, or `RandomAccessIterator2`, the template
|
| 1083 |
-
argument shall
|
| 1084 |
-
[[random.access.iterators]]
|
| 1085 |
|
| 1086 |
-
If an algorithm’s *Effects:*
|
| 1087 |
-
iterator passed as an argument is modified, then that algorithm
|
| 1088 |
-
additional type requirement: The type of that argument shall
|
| 1089 |
-
requirements of a mutable iterator
|
| 1090 |
|
| 1091 |
[*Note 1*: This requirement does not affect arguments that are named
|
| 1092 |
`OutputIterator`, `OutputIterator1`, or `OutputIterator2`, because
|
| 1093 |
-
output iterators must always be mutable
|
|
|
|
|
|
|
| 1094 |
|
| 1095 |
-
Both in-place and copying versions are provided for certain
|
| 1096 |
-
|
| 1097 |
-
|
| 1098 |
-
|
| 1099 |
|
| 1100 |
-
|
| 1101 |
-
function object
|
| 1102 |
-
|
| 1103 |
-
`true`. In other words, if an
|
| 1104 |
-
|
| 1105 |
-
|
| 1106 |
-
(
|
| 1107 |
-
non-constant function through
|
|
|
|
|
|
|
|
|
|
| 1108 |
|
| 1109 |
-
|
| 1110 |
-
function object that when applied to the
|
| 1111 |
-
corresponding iterators or to dereferencing
|
| 1112 |
-
when `T` is part of the signature returns a
|
| 1113 |
-
other words, if an algorithm takes
|
| 1114 |
-
argument and `first1` and `first2`
|
| 1115 |
-
|
| 1116 |
-
|
| 1117 |
-
|
| 1118 |
-
|
| 1119 |
-
|
| 1120 |
-
|
| 1121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1122 |
|
| 1123 |
[*Note 2*: Unless otherwise specified, algorithms that take function
|
| 1124 |
objects as arguments are permitted to copy those function objects
|
| 1125 |
freely. Programmers for whom object identity is important should
|
| 1126 |
consider using a wrapper class that points to a noncopied implementation
|
| 1127 |
-
object such as `reference_wrapper<T>`
|
| 1128 |
solution. — *end note*]
|
| 1129 |
|
| 1130 |
When the description of an algorithm gives an expression such as
|
| 1131 |
`*first == value` for a condition, the expression shall evaluate to
|
| 1132 |
either `true` or `false` in boolean contexts.
|
| 1133 |
|
| 1134 |
-
In the description of the algorithms
|
| 1135 |
-
|
| 1136 |
-
|
| 1137 |
|
| 1138 |
``` cpp
|
| 1139 |
-
|
| 1140 |
-
|
|
|
|
| 1141 |
return tmp;
|
| 1142 |
```
|
| 1143 |
|
| 1144 |
-
|
|
|
|
|
|
|
|
|
|
| 1145 |
|
| 1146 |
``` cpp
|
| 1147 |
-
|
|
|
|
|
|
|
| 1148 |
```
|
| 1149 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1150 |
## Parallel algorithms <a id="algorithms.parallel">[[algorithms.parallel]]</a>
|
| 1151 |
|
| 1152 |
-
|
| 1153 |
-
operations on containers and other sequences in parallel.
|
| 1154 |
|
| 1155 |
-
|
|
|
|
|
|
|
| 1156 |
|
| 1157 |
-
A *parallel algorithm* is a function template listed in this
|
| 1158 |
-
|
| 1159 |
-
`ExecutionPolicy`.
|
| 1160 |
|
| 1161 |
Parallel algorithms access objects indirectly accessible via their
|
| 1162 |
arguments by invoking the following functions:
|
| 1163 |
|
| 1164 |
- All operations of the categories of the iterators that the algorithm
|
|
@@ -1166,11 +219,11 @@ arguments by invoking the following functions:
|
|
| 1166 |
- Operations on those sequence elements that are required by its
|
| 1167 |
specification.
|
| 1168 |
- User-provided function objects to be applied during the execution of
|
| 1169 |
the algorithm, if required by the specification.
|
| 1170 |
- Operations on those function objects required by the specification.
|
| 1171 |
-
\[*Note 1*: See [[algorithms.
|
| 1172 |
|
| 1173 |
These functions are herein called *element access functions*.
|
| 1174 |
|
| 1175 |
[*Example 1*:
|
| 1176 |
|
|
@@ -1183,62 +236,123 @@ The `sort` function may invoke the following element access functions:
|
|
| 1183 |
preconditions specified in [[sort]]).
|
| 1184 |
- The user-provided `Compare` function object.
|
| 1185 |
|
| 1186 |
— *end example*]
|
| 1187 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1188 |
### Requirements on user-provided function objects <a id="algorithms.parallel.user">[[algorithms.parallel.user]]</a>
|
| 1189 |
|
| 1190 |
Unless otherwise specified, function objects passed into parallel
|
| 1191 |
algorithms as objects of type `Predicate`, `BinaryPredicate`, `Compare`,
|
| 1192 |
`UnaryOperation`, `BinaryOperation`, `BinaryOperation1`,
|
| 1193 |
`BinaryOperation2`, and the operators used by the analogous overloads to
|
| 1194 |
these parallel algorithms that could be formed by the invocation with
|
| 1195 |
the specified default predicate or operation (where applicable) shall
|
| 1196 |
not directly or indirectly modify objects via their arguments, nor shall
|
| 1197 |
-
they rely on the identity of the provided objects.
|
| 1198 |
|
| 1199 |
### Effect of execution policies on algorithm execution <a id="algorithms.parallel.exec">[[algorithms.parallel.exec]]</a>
|
| 1200 |
|
| 1201 |
-
Parallel algorithms have template parameters named `ExecutionPolicy`
|
| 1202 |
-
[[execpol]]
|
| 1203 |
algorithms may be parallelized and the manner in which they apply the
|
| 1204 |
element access functions.
|
| 1205 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1206 |
Unless otherwise stated, implementations may make arbitrary copies of
|
| 1207 |
elements (with type `T`) from sequences where
|
| 1208 |
`is_trivially_copy_constructible_v<T>` and
|
| 1209 |
`is_trivially_destructible_v<T>` are `true`.
|
| 1210 |
|
| 1211 |
-
[*Note
|
| 1212 |
rely on object identity of arguments for such input sequences. Users for
|
| 1213 |
whom the object identity of the arguments to these function objects is
|
| 1214 |
important should consider using a wrapping iterator that returns a
|
| 1215 |
-
non-copied implementation object such as `reference_wrapper<T>`
|
| 1216 |
-
[[refwrap]]
|
| 1217 |
|
| 1218 |
The invocations of element access functions in parallel algorithms
|
| 1219 |
invoked with an execution policy object of type
|
| 1220 |
`execution::sequenced_policy` all occur in the calling thread of
|
| 1221 |
execution.
|
| 1222 |
|
| 1223 |
-
[*Note
|
| 1224 |
[[intro.execution]]. — *end note*]
|
| 1225 |
|
| 1226 |
The invocations of element access functions in parallel algorithms
|
| 1227 |
invoked with an execution policy object of type
|
| 1228 |
-
`execution::
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1229 |
invoking thread of execution or in a thread of execution implicitly
|
| 1230 |
created by the library to support parallel algorithm execution. If the
|
| 1231 |
-
threads of execution created by `thread`
|
| 1232 |
-
provide concurrent forward progress
|
| 1233 |
-
then a thread of execution implicitly
|
| 1234 |
-
|
| 1235 |
-
forward progress guarantee is
|
| 1236 |
-
invocations executing in the same
|
| 1237 |
-
indeterminately sequenced with respect to each
|
|
|
|
| 1238 |
|
| 1239 |
-
[*Note
|
| 1240 |
invocation does not introduce data races or deadlocks. — *end note*]
|
| 1241 |
|
| 1242 |
[*Example 1*:
|
| 1243 |
|
| 1244 |
``` cpp
|
|
@@ -1258,13 +372,13 @@ to the container `v`.
|
|
| 1258 |
|
| 1259 |
``` cpp
|
| 1260 |
std::atomic<int> x{0};
|
| 1261 |
int a[] = {1,2};
|
| 1262 |
std::for_each(std::execution::par, std::begin(a), std::end(a), [&](int) {
|
| 1263 |
-
x.fetch_add(1, std::
|
| 1264 |
// spin wait for another iteration to change the value of x
|
| 1265 |
-
while (x.load(std::
|
| 1266 |
});
|
| 1267 |
```
|
| 1268 |
|
| 1269 |
The above example depends on the order of execution of the iterations,
|
| 1270 |
and will not terminate if both iterations are executed sequentially on
|
|
@@ -1288,78 +402,51 @@ The above example synchronizes access to object `x` ensuring that it is
|
|
| 1288 |
incremented correctly.
|
| 1289 |
|
| 1290 |
— *end example*]
|
| 1291 |
|
| 1292 |
The invocations of element access functions in parallel algorithms
|
| 1293 |
-
invoked with an execution policy of type
|
| 1294 |
`execution::parallel_unsequenced_policy` are permitted to execute in an
|
| 1295 |
unordered fashion in unspecified threads of execution, and unsequenced
|
| 1296 |
with respect to one another within each thread of execution. These
|
| 1297 |
threads of execution are either the invoking thread of execution or
|
| 1298 |
threads of execution implicitly created by the library; the latter will
|
| 1299 |
provide weakly parallel forward progress guarantees.
|
| 1300 |
|
| 1301 |
-
[*Note
|
| 1302 |
interleaved on a single thread of execution, which overrides the usual
|
| 1303 |
guarantee from [[intro.execution]] that function executions do not
|
| 1304 |
-
|
| 1305 |
|
| 1306 |
-
|
| 1307 |
-
|
| 1308 |
-
|
| 1309 |
-
deadlock. Thus, the synchronization with
|
| 1310 |
-
`execution::parallel_unsequenced_policy` is restricted as follows: A
|
| 1311 |
-
standard library function is *vectorization-unsafe* if it is specified
|
| 1312 |
-
to synchronize with another function invocation, or another function
|
| 1313 |
-
invocation is specified to synchronize with it, and if it is not a
|
| 1314 |
-
memory allocation or deallocation function. Vectorization-unsafe
|
| 1315 |
-
standard library functions may not be invoked by user code called from
|
| 1316 |
-
`execution::parallel_unsequenced_policy` algorithms.
|
| 1317 |
|
| 1318 |
-
[*Note
|
| 1319 |
-
|
| 1320 |
-
|
| 1321 |
-
|
| 1322 |
|
| 1323 |
-
[*
|
| 1324 |
-
|
| 1325 |
-
``
|
| 1326 |
-
|
| 1327 |
-
|
| 1328 |
-
int a[] = {1,2};
|
| 1329 |
-
std::for_each(std::execution::par_unseq, std::begin(a), std::end(a), [&](int) {
|
| 1330 |
-
std::lock_guard<mutex> guard(m); // incorrect: lock_guard constructor calls m.lock()
|
| 1331 |
-
++x;
|
| 1332 |
-
});
|
| 1333 |
-
```
|
| 1334 |
-
|
| 1335 |
-
The above program may result in two consecutive calls to `m.lock()` on
|
| 1336 |
-
the same thread of execution (which may deadlock), because the
|
| 1337 |
-
applications of the function object are not guaranteed to run on
|
| 1338 |
-
different threads of execution.
|
| 1339 |
-
|
| 1340 |
-
— *end example*]
|
| 1341 |
-
|
| 1342 |
-
[*Note 6*: The semantics of the `execution::parallel_policy` or the
|
| 1343 |
-
`execution::parallel_unsequenced_policy` invocation allow the
|
| 1344 |
-
implementation to fall back to sequential execution if the system cannot
|
| 1345 |
-
parallelize an algorithm invocation due to lack of
|
| 1346 |
-
resources. — *end note*]
|
| 1347 |
|
| 1348 |
If an invocation of a parallel algorithm uses threads of execution
|
| 1349 |
implicitly created by the library, then the invoking thread of execution
|
| 1350 |
will either
|
| 1351 |
|
| 1352 |
-
- temporarily block with forward progress guarantee delegation
|
| 1353 |
-
[[intro.progress]]
|
| 1354 |
of execution, or
|
| 1355 |
- eventually execute an element access function;
|
| 1356 |
|
| 1357 |
the thread of execution will continue to do so until the algorithm is
|
| 1358 |
finished.
|
| 1359 |
|
| 1360 |
-
[*Note
|
| 1361 |
this context, a thread of execution created by the library is considered
|
| 1362 |
to have finished execution as soon as it has finished the execution of
|
| 1363 |
the particular element access function that the invoking thread of
|
| 1364 |
execution logically depends on. — *end note*]
|
| 1365 |
|
|
@@ -1397,82 +484,2524 @@ says “at most *expr*” or “exactly *expr*” and does not specify the
|
|
| 1397 |
number of assignments or swaps, and *expr* is not already expressed with
|
| 1398 |
𝑂() notation, the complexity of the algorithm shall be
|
| 1399 |
𝑂(\placeholder{expr}).
|
| 1400 |
|
| 1401 |
Parallel algorithms shall not participate in overload resolution unless
|
| 1402 |
-
`is_execution_policy_v<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1403 |
|
| 1404 |
## Non-modifying sequence operations <a id="alg.nonmodifying">[[alg.nonmodifying]]</a>
|
| 1405 |
|
| 1406 |
-
### All of <a id="alg.
|
| 1407 |
|
| 1408 |
``` cpp
|
| 1409 |
template<class InputIterator, class Predicate>
|
| 1410 |
-
bool all_of(InputIterator first, InputIterator last, Predicate pred);
|
| 1411 |
template<class ExecutionPolicy, class ForwardIterator, class Predicate>
|
| 1412 |
bool all_of(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last,
|
| 1413 |
Predicate pred);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1414 |
```
|
| 1415 |
|
| 1416 |
-
|
| 1417 |
-
`true` for every iterator `i` in the range \[`first`, `last`), and
|
| 1418 |
-
`false` otherwise.
|
| 1419 |
|
| 1420 |
-
|
|
|
|
|
|
|
| 1421 |
|
| 1422 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1423 |
|
| 1424 |
``` cpp
|
| 1425 |
template<class InputIterator, class Predicate>
|
| 1426 |
-
bool any_of(InputIterator first, InputIterator last, Predicate pred);
|
| 1427 |
template<class ExecutionPolicy, class ForwardIterator, class Predicate>
|
| 1428 |
bool any_of(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last,
|
| 1429 |
Predicate pred);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1430 |
```
|
| 1431 |
|
| 1432 |
-
|
| 1433 |
-
iterator `i` in the range \[`first`, `last`) such that `pred(*i)` is
|
| 1434 |
-
`true`, and `true` otherwise.
|
| 1435 |
|
| 1436 |
-
|
|
|
|
|
|
|
| 1437 |
|
| 1438 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1439 |
|
| 1440 |
``` cpp
|
| 1441 |
template<class InputIterator, class Predicate>
|
| 1442 |
-
bool none_of(InputIterator first, InputIterator last, Predicate pred);
|
| 1443 |
template<class ExecutionPolicy, class ForwardIterator, class Predicate>
|
| 1444 |
bool none_of(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last,
|
| 1445 |
Predicate pred);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1446 |
```
|
| 1447 |
|
| 1448 |
-
|
| 1449 |
-
`false` for every iterator `i` in the range \[`first`, `last`), and
|
| 1450 |
-
`false` otherwise.
|
| 1451 |
|
| 1452 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1453 |
|
| 1454 |
### For each <a id="alg.foreach">[[alg.foreach]]</a>
|
| 1455 |
|
| 1456 |
``` cpp
|
| 1457 |
template<class InputIterator, class Function>
|
| 1458 |
-
Function for_each(InputIterator first, InputIterator last, Function f);
|
| 1459 |
```
|
| 1460 |
|
| 1461 |
-
*
|
| 1462 |
-
|
| 1463 |
|
| 1464 |
[*Note 1*: `Function` need not meet the requirements of
|
| 1465 |
-
|
| 1466 |
|
| 1467 |
*Effects:* Applies `f` to the result of dereferencing every iterator in
|
| 1468 |
the range \[`first`, `last`), starting from `first` and proceeding to
|
| 1469 |
`last - 1`.
|
| 1470 |
|
| 1471 |
-
[*Note 2*: If the type of `first`
|
| 1472 |
-
|
| 1473 |
-
|
| 1474 |
|
| 1475 |
*Returns:* `f`.
|
| 1476 |
|
| 1477 |
*Complexity:* Applies `f` exactly `last - first` times.
|
| 1478 |
|
|
@@ -1483,19 +3012,19 @@ template<class ExecutionPolicy, class ForwardIterator, class Function>
|
|
| 1483 |
void for_each(ExecutionPolicy&& exec,
|
| 1484 |
ForwardIterator first, ForwardIterator last,
|
| 1485 |
Function f);
|
| 1486 |
```
|
| 1487 |
|
| 1488 |
-
*
|
| 1489 |
-
|
| 1490 |
|
| 1491 |
*Effects:* Applies `f` to the result of dereferencing every iterator in
|
| 1492 |
the range \[`first`, `last`).
|
| 1493 |
|
| 1494 |
-
[*Note 3*: If the type of `first`
|
| 1495 |
-
|
| 1496 |
-
|
| 1497 |
|
| 1498 |
*Complexity:* Applies `f` exactly `last - first` times.
|
| 1499 |
|
| 1500 |
*Remarks:* If `f` returns a result, the result is ignored.
|
| 1501 |
Implementations do not have the freedom granted under
|
|
@@ -1504,29 +3033,59 @@ the input sequence.
|
|
| 1504 |
|
| 1505 |
[*Note 4*: Does not return a copy of its `Function` parameter, since
|
| 1506 |
parallelization may not permit efficient state
|
| 1507 |
accumulation. — *end note*]
|
| 1508 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1509 |
``` cpp
|
| 1510 |
template<class InputIterator, class Size, class Function>
|
| 1511 |
-
InputIterator for_each_n(InputIterator first, Size n, Function f);
|
| 1512 |
```
|
| 1513 |
|
| 1514 |
-
*
|
| 1515 |
-
|
| 1516 |
|
| 1517 |
-
|
| 1518 |
-
|
| 1519 |
|
| 1520 |
-
*
|
|
|
|
|
|
|
|
|
|
| 1521 |
|
| 1522 |
*Effects:* Applies `f` to the result of dereferencing every iterator in
|
| 1523 |
the range \[`first`, `first + n`) in order.
|
| 1524 |
|
| 1525 |
-
[*Note
|
| 1526 |
-
|
| 1527 |
-
|
| 1528 |
|
| 1529 |
*Returns:* `first + n`.
|
| 1530 |
|
| 1531 |
*Remarks:* If `f` returns a result, the result is ignored.
|
| 1532 |
|
|
@@ -1534,350 +3093,540 @@ dereferenced iterator. — *end note*]
|
|
| 1534 |
template<class ExecutionPolicy, class ForwardIterator, class Size, class Function>
|
| 1535 |
ForwardIterator for_each_n(ExecutionPolicy&& exec, ForwardIterator first, Size n,
|
| 1536 |
Function f);
|
| 1537 |
```
|
| 1538 |
|
| 1539 |
-
*
|
| 1540 |
-
|
| 1541 |
|
| 1542 |
-
*
|
|
|
|
|
|
|
|
|
|
| 1543 |
|
| 1544 |
*Effects:* Applies `f` to the result of dereferencing every iterator in
|
| 1545 |
the range \[`first`, `first + n`).
|
| 1546 |
|
| 1547 |
-
[*Note
|
| 1548 |
-
|
| 1549 |
-
|
| 1550 |
|
| 1551 |
*Returns:* `first + n`.
|
| 1552 |
|
| 1553 |
*Remarks:* If `f` returns a result, the result is ignored.
|
| 1554 |
Implementations do not have the freedom granted under
|
| 1555 |
[[algorithms.parallel.exec]] to make arbitrary copies of elements from
|
| 1556 |
the input sequence.
|
| 1557 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1558 |
### Find <a id="alg.find">[[alg.find]]</a>
|
| 1559 |
|
| 1560 |
``` cpp
|
| 1561 |
template<class InputIterator, class T>
|
| 1562 |
-
InputIterator find(InputIterator first, InputIterator last,
|
| 1563 |
const T& value);
|
| 1564 |
template<class ExecutionPolicy, class ForwardIterator, class T>
|
| 1565 |
ForwardIterator find(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last,
|
| 1566 |
const T& value);
|
| 1567 |
|
| 1568 |
template<class InputIterator, class Predicate>
|
| 1569 |
-
InputIterator find_if(InputIterator first, InputIterator last,
|
| 1570 |
Predicate pred);
|
| 1571 |
template<class ExecutionPolicy, class ForwardIterator, class Predicate>
|
| 1572 |
ForwardIterator find_if(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last,
|
| 1573 |
Predicate pred);
|
| 1574 |
|
| 1575 |
template<class InputIterator, class Predicate>
|
| 1576 |
-
InputIterator find_if_not(InputIterator first, InputIterator last,
|
| 1577 |
Predicate pred);
|
| 1578 |
template<class ExecutionPolicy, class ForwardIterator, class Predicate>
|
| 1579 |
-
ForwardIterator find_if_not(ExecutionPolicy&& exec,
|
|
|
|
| 1580 |
Predicate pred);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1581 |
```
|
| 1582 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1583 |
*Returns:* The first iterator `i` in the range \[`first`, `last`) for
|
| 1584 |
-
which
|
| 1585 |
-
`pred(*i) != false`, `pred(*i) == false`. Returns `last` if no such
|
| 1586 |
-
iterator is found.
|
| 1587 |
|
| 1588 |
*Complexity:* At most `last - first` applications of the corresponding
|
| 1589 |
-
predicate.
|
| 1590 |
|
| 1591 |
### Find end <a id="alg.find.end">[[alg.find.end]]</a>
|
| 1592 |
|
| 1593 |
``` cpp
|
| 1594 |
template<class ForwardIterator1, class ForwardIterator2>
|
| 1595 |
-
ForwardIterator1
|
| 1596 |
find_end(ForwardIterator1 first1, ForwardIterator1 last1,
|
| 1597 |
ForwardIterator2 first2, ForwardIterator2 last2);
|
| 1598 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 1599 |
ForwardIterator1
|
| 1600 |
find_end(ExecutionPolicy&& exec,
|
| 1601 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 1602 |
ForwardIterator2 first2, ForwardIterator2 last2);
|
| 1603 |
|
| 1604 |
template<class ForwardIterator1, class ForwardIterator2,
|
| 1605 |
class BinaryPredicate>
|
| 1606 |
-
ForwardIterator1
|
| 1607 |
find_end(ForwardIterator1 first1, ForwardIterator1 last1,
|
| 1608 |
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 1609 |
BinaryPredicate pred);
|
| 1610 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 1611 |
class BinaryPredicate>
|
| 1612 |
ForwardIterator1
|
| 1613 |
find_end(ExecutionPolicy&& exec,
|
| 1614 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 1615 |
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 1616 |
BinaryPredicate pred);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1617 |
```
|
| 1618 |
|
| 1619 |
-
|
| 1620 |
|
| 1621 |
-
|
| 1622 |
-
|
| 1623 |
-
`
|
| 1624 |
-
`
|
| 1625 |
-
|
| 1626 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1627 |
|
| 1628 |
*Complexity:* At most
|
| 1629 |
`(last2 - first2) * (last1 - first1 - (last2 - first2) + 1)`
|
| 1630 |
-
applications of the corresponding predicate.
|
| 1631 |
|
| 1632 |
### Find first <a id="alg.find.first.of">[[alg.find.first.of]]</a>
|
| 1633 |
|
| 1634 |
``` cpp
|
| 1635 |
template<class InputIterator, class ForwardIterator>
|
| 1636 |
-
InputIterator
|
| 1637 |
find_first_of(InputIterator first1, InputIterator last1,
|
| 1638 |
ForwardIterator first2, ForwardIterator last2);
|
| 1639 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 1640 |
ForwardIterator1
|
| 1641 |
find_first_of(ExecutionPolicy&& exec,
|
| 1642 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 1643 |
ForwardIterator2 first2, ForwardIterator2 last2);
|
| 1644 |
|
| 1645 |
template<class InputIterator, class ForwardIterator,
|
| 1646 |
class BinaryPredicate>
|
| 1647 |
-
InputIterator
|
| 1648 |
find_first_of(InputIterator first1, InputIterator last1,
|
| 1649 |
ForwardIterator first2, ForwardIterator last2,
|
| 1650 |
BinaryPredicate pred);
|
| 1651 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 1652 |
class BinaryPredicate>
|
| 1653 |
ForwardIterator1
|
| 1654 |
find_first_of(ExecutionPolicy&& exec,
|
| 1655 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 1656 |
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 1657 |
BinaryPredicate pred);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1658 |
```
|
| 1659 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1660 |
*Effects:* Finds an element that matches one of a set of values.
|
| 1661 |
|
| 1662 |
*Returns:* The first iterator `i` in the range \[`first1`, `last1`) such
|
| 1663 |
-
that for some iterator `j` in the range \[`first2`, `last2`)
|
| 1664 |
-
|
| 1665 |
-
|
| 1666 |
-
found.
|
| 1667 |
|
| 1668 |
*Complexity:* At most `(last1-first1) * (last2-first2)` applications of
|
| 1669 |
-
the corresponding predicate.
|
| 1670 |
|
| 1671 |
### Adjacent find <a id="alg.adjacent.find">[[alg.adjacent.find]]</a>
|
| 1672 |
|
| 1673 |
``` cpp
|
| 1674 |
template<class ForwardIterator>
|
| 1675 |
-
|
|
|
|
| 1676 |
template<class ExecutionPolicy, class ForwardIterator>
|
| 1677 |
-
ForwardIterator
|
|
|
|
| 1678 |
ForwardIterator first, ForwardIterator last);
|
| 1679 |
|
| 1680 |
template<class ForwardIterator, class BinaryPredicate>
|
| 1681 |
-
|
|
|
|
| 1682 |
BinaryPredicate pred);
|
| 1683 |
template<class ExecutionPolicy, class ForwardIterator, class BinaryPredicate>
|
| 1684 |
-
ForwardIterator
|
|
|
|
| 1685 |
ForwardIterator first, ForwardIterator last,
|
| 1686 |
BinaryPredicate pred);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1687 |
```
|
| 1688 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1689 |
*Returns:* The first iterator `i` such that both `i` and `i + 1` are in
|
| 1690 |
-
the range \[`first`, `last`) for which
|
| 1691 |
-
|
| 1692 |
-
`last` if no such iterator is found.
|
| 1693 |
|
| 1694 |
*Complexity:* For the overloads with no `ExecutionPolicy`, exactly
|
| 1695 |
-
|
| 1696 |
-
corresponding predicate, where `i` is
|
| 1697 |
-
For the overloads with an
|
| 1698 |
-
applications of the corresponding
|
|
|
|
|
|
|
| 1699 |
|
| 1700 |
### Count <a id="alg.count">[[alg.count]]</a>
|
| 1701 |
|
| 1702 |
``` cpp
|
| 1703 |
template<class InputIterator, class T>
|
| 1704 |
-
typename iterator_traits<InputIterator>::difference_type
|
| 1705 |
count(InputIterator first, InputIterator last, const T& value);
|
| 1706 |
template<class ExecutionPolicy, class ForwardIterator, class T>
|
| 1707 |
typename iterator_traits<ForwardIterator>::difference_type
|
| 1708 |
-
count(ExecutionPolicy&& exec,
|
|
|
|
| 1709 |
|
| 1710 |
template<class InputIterator, class Predicate>
|
| 1711 |
-
typename iterator_traits<InputIterator>::difference_type
|
| 1712 |
count_if(InputIterator first, InputIterator last, Predicate pred);
|
| 1713 |
template<class ExecutionPolicy, class ForwardIterator, class Predicate>
|
| 1714 |
typename iterator_traits<ForwardIterator>::difference_type
|
| 1715 |
-
count_if(ExecutionPolicy&& exec,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1716 |
```
|
| 1717 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1718 |
*Effects:* Returns the number of iterators `i` in the range \[`first`,
|
| 1719 |
-
`last`) for which
|
| 1720 |
-
`*i == value, pred(*i) != false`.
|
| 1721 |
|
| 1722 |
*Complexity:* Exactly `last - first` applications of the corresponding
|
| 1723 |
-
predicate.
|
| 1724 |
|
| 1725 |
### Mismatch <a id="mismatch">[[mismatch]]</a>
|
| 1726 |
|
| 1727 |
``` cpp
|
| 1728 |
template<class InputIterator1, class InputIterator2>
|
| 1729 |
-
pair<InputIterator1, InputIterator2>
|
| 1730 |
mismatch(InputIterator1 first1, InputIterator1 last1,
|
| 1731 |
InputIterator2 first2);
|
| 1732 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 1733 |
pair<ForwardIterator1, ForwardIterator2>
|
| 1734 |
mismatch(ExecutionPolicy&& exec,
|
| 1735 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 1736 |
ForwardIterator2 first2);
|
| 1737 |
|
| 1738 |
template<class InputIterator1, class InputIterator2,
|
| 1739 |
class BinaryPredicate>
|
| 1740 |
-
pair<InputIterator1, InputIterator2>
|
| 1741 |
mismatch(InputIterator1 first1, InputIterator1 last1,
|
| 1742 |
InputIterator2 first2, BinaryPredicate pred);
|
| 1743 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 1744 |
class BinaryPredicate>
|
| 1745 |
pair<ForwardIterator1, ForwardIterator2>
|
| 1746 |
mismatch(ExecutionPolicy&& exec,
|
| 1747 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 1748 |
ForwardIterator2 first2, BinaryPredicate pred);
|
| 1749 |
|
| 1750 |
template<class InputIterator1, class InputIterator2>
|
| 1751 |
-
pair<InputIterator1, InputIterator2>
|
| 1752 |
mismatch(InputIterator1 first1, InputIterator1 last1,
|
| 1753 |
InputIterator2 first2, InputIterator2 last2);
|
| 1754 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 1755 |
pair<ForwardIterator1, ForwardIterator2>
|
| 1756 |
mismatch(ExecutionPolicy&& exec,
|
| 1757 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 1758 |
ForwardIterator2 first2, ForwardIterator2 last2);
|
| 1759 |
|
| 1760 |
template<class InputIterator1, class InputIterator2,
|
| 1761 |
class BinaryPredicate>
|
| 1762 |
-
pair<InputIterator1, InputIterator2>
|
| 1763 |
mismatch(InputIterator1 first1, InputIterator1 last1,
|
| 1764 |
InputIterator2 first2, InputIterator2 last2,
|
| 1765 |
BinaryPredicate pred);
|
| 1766 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 1767 |
class BinaryPredicate>
|
| 1768 |
pair<ForwardIterator1, ForwardIterator2>
|
| 1769 |
mismatch(ExecutionPolicy&& exec,
|
| 1770 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 1771 |
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 1772 |
BinaryPredicate pred);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1773 |
```
|
| 1774 |
|
| 1775 |
-
|
| 1776 |
-
`
|
| 1777 |
|
| 1778 |
-
|
| 1779 |
-
is the smallest integer such that, respectively,
|
| 1780 |
|
| 1781 |
-
- `!(*(first1 + n) == *(first2 + n))`
|
| 1782 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1783 |
|
| 1784 |
-
|
| 1785 |
|
| 1786 |
-
*
|
| 1787 |
-
|
|
|
|
|
|
|
|
|
|
| 1788 |
|
| 1789 |
### Equal <a id="alg.equal">[[alg.equal]]</a>
|
| 1790 |
|
| 1791 |
``` cpp
|
| 1792 |
template<class InputIterator1, class InputIterator2>
|
| 1793 |
-
bool equal(InputIterator1 first1, InputIterator1 last1,
|
| 1794 |
InputIterator2 first2);
|
| 1795 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 1796 |
bool equal(ExecutionPolicy&& exec,
|
| 1797 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 1798 |
ForwardIterator2 first2);
|
| 1799 |
|
| 1800 |
template<class InputIterator1, class InputIterator2,
|
| 1801 |
class BinaryPredicate>
|
| 1802 |
-
bool equal(InputIterator1 first1, InputIterator1 last1,
|
| 1803 |
InputIterator2 first2, BinaryPredicate pred);
|
| 1804 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 1805 |
class BinaryPredicate>
|
| 1806 |
bool equal(ExecutionPolicy&& exec,
|
| 1807 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 1808 |
ForwardIterator2 first2, BinaryPredicate pred);
|
| 1809 |
|
| 1810 |
template<class InputIterator1, class InputIterator2>
|
| 1811 |
-
bool equal(InputIterator1 first1, InputIterator1 last1,
|
| 1812 |
InputIterator2 first2, InputIterator2 last2);
|
| 1813 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 1814 |
bool equal(ExecutionPolicy&& exec,
|
| 1815 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 1816 |
ForwardIterator2 first2, ForwardIterator2 last2);
|
| 1817 |
|
| 1818 |
template<class InputIterator1, class InputIterator2,
|
| 1819 |
class BinaryPredicate>
|
| 1820 |
-
bool equal(InputIterator1 first1, InputIterator1 last1,
|
| 1821 |
InputIterator2 first2, InputIterator2 last2,
|
| 1822 |
BinaryPredicate pred);
|
| 1823 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 1824 |
class BinaryPredicate>
|
| 1825 |
bool equal(ExecutionPolicy&& exec,
|
| 1826 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 1827 |
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 1828 |
BinaryPredicate pred);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1829 |
```
|
| 1830 |
|
| 1831 |
-
|
| 1832 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1833 |
|
| 1834 |
*Returns:* If `last1 - first1 != last2 - first2`, return `false`.
|
| 1835 |
-
Otherwise return `true` if for every iterator `i` in the range
|
| 1836 |
-
\[`first1`, `last1`)
|
| 1837 |
-
`*i == *(first2 + (i - first1)), pred(*i, *(first2 + (i - first1))) != false`.
|
| 1838 |
-
Otherwise, returns `false`.
|
| 1839 |
|
| 1840 |
-
*Complexity:*
|
| 1841 |
|
| 1842 |
-
-
|
| 1843 |
-
|
| 1844 |
-
|
| 1845 |
-
|
| 1846 |
-
|
| 1847 |
-
- at most min(`last1 - first1`, `last2 - first2`) applications of the
|
| 1848 |
-
corresponding predicate.
|
| 1849 |
-
- For the overloads with no `ExecutionPolicy`,
|
| 1850 |
-
- if `ForwardIterator1` and `ForwardIterator2` meet the requirements
|
| 1851 |
-
of random access iterators and `last1 - first1 != last2 - first2`,
|
| 1852 |
-
then no applications of the corresponding predicate; otherwise,
|
| 1853 |
-
- 𝑂(min(`last1 - first1`, `last2 - first2`)) applications of the
|
| 1854 |
-
corresponding predicate.
|
| 1855 |
|
| 1856 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1857 |
|
| 1858 |
``` cpp
|
| 1859 |
template<class ForwardIterator1, class ForwardIterator2>
|
| 1860 |
-
bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
|
| 1861 |
ForwardIterator2 first2);
|
| 1862 |
template<class ForwardIterator1, class ForwardIterator2,
|
| 1863 |
class BinaryPredicate>
|
| 1864 |
-
bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
|
| 1865 |
ForwardIterator2 first2, BinaryPredicate pred);
|
| 1866 |
template<class ForwardIterator1, class ForwardIterator2>
|
| 1867 |
-
bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
|
| 1868 |
ForwardIterator2 first2, ForwardIterator2 last2);
|
| 1869 |
template<class ForwardIterator1, class ForwardIterator2,
|
| 1870 |
class BinaryPredicate>
|
| 1871 |
-
bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
|
| 1872 |
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 1873 |
BinaryPredicate pred);
|
| 1874 |
```
|
| 1875 |
|
| 1876 |
-
*
|
| 1877 |
-
|
| 1878 |
-
|
|
|
|
| 1879 |
|
| 1880 |
*Remarks:* If `last2` was not given in the argument list, it denotes
|
| 1881 |
`first2 + (last1 - first1)` below.
|
| 1882 |
|
| 1883 |
*Returns:* If `last1 - first1 != last2 - first2`, return `false`.
|
|
@@ -1891,30 +3640,65 @@ otherwise, returns `false`.
|
|
| 1891 |
`ForwardIterator1` and `ForwardIterator2` meet the requirements of
|
| 1892 |
random access iterators and `last1 - first1 != last2 - first2`.
|
| 1893 |
Otherwise, exactly `last1 - first1` applications of the corresponding
|
| 1894 |
predicate if `equal(first1, last1, first2, last2)` would return `true`
|
| 1895 |
if `pred` was not given in the argument list or
|
| 1896 |
-
`equal(first1, last1, first2, last2, pred)` would return `true` if
|
| 1897 |
-
was given in the argument list; otherwise, at worst 𝑂(N^2), where
|
| 1898 |
-
the value `last1 - first1`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1899 |
|
| 1900 |
### Search <a id="alg.search">[[alg.search]]</a>
|
| 1901 |
|
| 1902 |
``` cpp
|
| 1903 |
template<class ForwardIterator1, class ForwardIterator2>
|
| 1904 |
-
ForwardIterator1
|
| 1905 |
search(ForwardIterator1 first1, ForwardIterator1 last1,
|
| 1906 |
ForwardIterator2 first2, ForwardIterator2 last2);
|
| 1907 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 1908 |
ForwardIterator1
|
| 1909 |
search(ExecutionPolicy&& exec,
|
| 1910 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 1911 |
ForwardIterator2 first2, ForwardIterator2 last2);
|
| 1912 |
|
| 1913 |
template<class ForwardIterator1, class ForwardIterator2,
|
| 1914 |
class BinaryPredicate>
|
| 1915 |
-
ForwardIterator1
|
| 1916 |
search(ForwardIterator1 first1, ForwardIterator1 last1,
|
| 1917 |
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 1918 |
BinaryPredicate pred);
|
| 1919 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 1920 |
class BinaryPredicate>
|
|
@@ -1923,103 +3707,166 @@ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
|
| 1923 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 1924 |
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 1925 |
BinaryPredicate pred);
|
| 1926 |
```
|
| 1927 |
|
| 1928 |
-
*Effects:* Finds a subsequence of equal values in a sequence.
|
| 1929 |
-
|
| 1930 |
*Returns:* The first iterator `i` in the range \[`first1`,
|
| 1931 |
`last1 - (last2-first2)`) such that for every non-negative integer `n`
|
| 1932 |
less than `last2 - first2` the following corresponding conditions hold:
|
| 1933 |
`*(i + n) == *(first2 + n), pred(*(i + n), *(first2 + n)) != false`.
|
| 1934 |
Returns `first1` if \[`first2`, `last2`) is empty, otherwise returns
|
| 1935 |
`last1` if no such iterator is found.
|
| 1936 |
|
| 1937 |
*Complexity:* At most `(last1 - first1) * (last2 - first2)` applications
|
| 1938 |
of the corresponding predicate.
|
| 1939 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1940 |
``` cpp
|
| 1941 |
template<class ForwardIterator, class Size, class T>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1942 |
ForwardIterator
|
| 1943 |
-
search_n(
|
| 1944 |
-
|
|
|
|
| 1945 |
|
| 1946 |
template<class ForwardIterator, class Size, class T,
|
| 1947 |
class BinaryPredicate>
|
| 1948 |
-
ForwardIterator
|
| 1949 |
-
search_n(ForwardIterator first, ForwardIterator last,
|
| 1950 |
-
const T& value,
|
| 1951 |
-
|
| 1952 |
-
template<class ExecutionPolicy, class ForwardIterator, class Size, class T>
|
| 1953 |
-
ForwardIterator
|
| 1954 |
-
search_n(ExecutionPolicy&& exec,
|
| 1955 |
-
ForwardIterator first, ForwardIterator last,
|
| 1956 |
-
Size count, const T& value);
|
| 1957 |
template<class ExecutionPolicy, class ForwardIterator, class Size, class T,
|
| 1958 |
class BinaryPredicate>
|
| 1959 |
ForwardIterator
|
| 1960 |
search_n(ExecutionPolicy&& exec,
|
| 1961 |
ForwardIterator first, ForwardIterator last,
|
| 1962 |
Size count, const T& value,
|
| 1963 |
BinaryPredicate pred);
|
| 1964 |
```
|
| 1965 |
|
| 1966 |
-
*
|
| 1967 |
type ([[conv.integral]], [[class.conv]]).
|
| 1968 |
|
| 1969 |
-
*Effects:* Finds a subsequence of equal values in a sequence.
|
| 1970 |
-
|
| 1971 |
*Returns:* The first iterator `i` in the range \[`first`, `last-count`)
|
| 1972 |
such that for every non-negative integer `n` less than `count` the
|
| 1973 |
following corresponding conditions hold:
|
| 1974 |
`*(i + n) == value, pred(*(i + n),value) != false`. Returns `last` if no
|
| 1975 |
such iterator is found.
|
| 1976 |
|
| 1977 |
*Complexity:* At most `last - first` applications of the corresponding
|
| 1978 |
predicate.
|
| 1979 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1980 |
``` cpp
|
| 1981 |
template<class ForwardIterator, class Searcher>
|
| 1982 |
-
|
| 1983 |
-
|
| 1984 |
```
|
| 1985 |
|
| 1986 |
*Effects:* Equivalent to: `return searcher(first, last).first;`
|
| 1987 |
|
| 1988 |
-
*Remarks:* `Searcher` need not meet the
|
| 1989 |
requirements.
|
| 1990 |
|
| 1991 |
## Mutating sequence operations <a id="alg.modifying.operations">[[alg.modifying.operations]]</a>
|
| 1992 |
|
| 1993 |
### Copy <a id="alg.copy">[[alg.copy]]</a>
|
| 1994 |
|
| 1995 |
``` cpp
|
| 1996 |
template<class InputIterator, class OutputIterator>
|
| 1997 |
-
OutputIterator copy(InputIterator first, InputIterator last,
|
| 1998 |
OutputIterator result);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1999 |
```
|
| 2000 |
|
| 2001 |
-
|
|
|
|
|
|
|
| 2002 |
|
| 2003 |
*Effects:* Copies elements in the range \[`first`, `last`) into the
|
| 2004 |
-
range \[`result`, `result +
|
| 2005 |
-
|
| 2006 |
-
`
|
| 2007 |
|
| 2008 |
-
*Returns:*
|
| 2009 |
|
| 2010 |
-
|
|
|
|
|
|
|
|
|
|
| 2011 |
|
| 2012 |
``` cpp
|
| 2013 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 2014 |
ForwardIterator2 copy(ExecutionPolicy&& policy,
|
| 2015 |
ForwardIterator1 first, ForwardIterator1 last,
|
| 2016 |
ForwardIterator2 result);
|
| 2017 |
```
|
| 2018 |
|
| 2019 |
-
*
|
| 2020 |
-
`result + (last - first)`)
|
| 2021 |
|
| 2022 |
*Effects:* Copies elements in the range \[`first`, `last`) into the
|
| 2023 |
range \[`result`, `result + (last - first)`). For each non-negative
|
| 2024 |
integer `n < (last - first)`, performs `*(result + n) = *(first + n)`.
|
| 2025 |
|
|
@@ -2027,247 +3874,436 @@ integer `n < (last - first)`, performs `*(result + n) = *(first + n)`.
|
|
| 2027 |
|
| 2028 |
*Complexity:* Exactly `last - first` assignments.
|
| 2029 |
|
| 2030 |
``` cpp
|
| 2031 |
template<class InputIterator, class Size, class OutputIterator>
|
| 2032 |
-
OutputIterator copy_n(InputIterator first, Size n,
|
| 2033 |
OutputIterator result);
|
| 2034 |
template<class ExecutionPolicy, class ForwardIterator1, class Size, class ForwardIterator2>
|
| 2035 |
ForwardIterator2 copy_n(ExecutionPolicy&& exec,
|
| 2036 |
ForwardIterator1 first, Size n,
|
| 2037 |
ForwardIterator2 result);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2038 |
```
|
| 2039 |
|
| 2040 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2041 |
`*(result + i) = *(first + i)`.
|
| 2042 |
|
| 2043 |
-
*Returns:*
|
| 2044 |
|
| 2045 |
-
|
|
|
|
|
|
|
|
|
|
| 2046 |
|
| 2047 |
``` cpp
|
| 2048 |
template<class InputIterator, class OutputIterator, class Predicate>
|
| 2049 |
-
OutputIterator copy_if(InputIterator first, InputIterator last,
|
| 2050 |
OutputIterator result, Predicate pred);
|
| 2051 |
-
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
|
|
|
| 2052 |
ForwardIterator2 copy_if(ExecutionPolicy&& exec,
|
| 2053 |
ForwardIterator1 first, ForwardIterator1 last,
|
| 2054 |
ForwardIterator2 result, Predicate pred);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2055 |
```
|
| 2056 |
|
| 2057 |
-
|
| 2058 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2059 |
|
| 2060 |
[*Note 1*: For the overload with an `ExecutionPolicy`, there may be a
|
| 2061 |
performance cost if `iterator_traits<ForwardIterator1>::value_type` is
|
| 2062 |
-
not
|
| 2063 |
-
(
|
| 2064 |
|
| 2065 |
*Effects:* Copies all of the elements referred to by the iterator `i` in
|
| 2066 |
-
the range \[`first`, `last`) for which
|
| 2067 |
|
| 2068 |
-
*Returns:*
|
|
|
|
|
|
|
|
|
|
| 2069 |
|
| 2070 |
*Complexity:* Exactly `last - first` applications of the corresponding
|
| 2071 |
-
predicate.
|
| 2072 |
|
| 2073 |
-
*Remarks:* Stable
|
| 2074 |
|
| 2075 |
``` cpp
|
| 2076 |
template<class BidirectionalIterator1, class BidirectionalIterator2>
|
| 2077 |
-
BidirectionalIterator2
|
| 2078 |
copy_backward(BidirectionalIterator1 first,
|
| 2079 |
BidirectionalIterator1 last,
|
| 2080 |
BidirectionalIterator2 result);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2081 |
```
|
| 2082 |
|
| 2083 |
-
|
|
|
|
|
|
|
| 2084 |
|
| 2085 |
*Effects:* Copies elements in the range \[`first`, `last`) into the
|
| 2086 |
-
range \[`result -
|
| 2087 |
-
|
| 2088 |
-
`
|
| 2089 |
|
| 2090 |
-
*Returns:*
|
| 2091 |
|
| 2092 |
-
|
|
|
|
|
|
|
|
|
|
| 2093 |
|
| 2094 |
### Move <a id="alg.move">[[alg.move]]</a>
|
| 2095 |
|
| 2096 |
``` cpp
|
| 2097 |
template<class InputIterator, class OutputIterator>
|
| 2098 |
-
OutputIterator move(InputIterator first, InputIterator last,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2099 |
```
|
| 2100 |
|
| 2101 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2102 |
|
| 2103 |
*Effects:* Moves elements in the range \[`first`, `last`) into the range
|
| 2104 |
-
\[`result`, `result +
|
| 2105 |
-
|
| 2106 |
-
|
| 2107 |
|
| 2108 |
-
*Returns:*
|
| 2109 |
|
| 2110 |
-
|
|
|
|
|
|
|
|
|
|
| 2111 |
|
| 2112 |
``` cpp
|
| 2113 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 2114 |
ForwardIterator2 move(ExecutionPolicy&& policy,
|
| 2115 |
ForwardIterator1 first, ForwardIterator1 last,
|
| 2116 |
ForwardIterator2 result);
|
| 2117 |
```
|
| 2118 |
|
| 2119 |
-
|
| 2120 |
-
|
|
|
|
|
|
|
| 2121 |
|
| 2122 |
*Effects:* Moves elements in the range \[`first`, `last`) into the range
|
| 2123 |
-
\[`result`, `result +
|
| 2124 |
-
`n
|
| 2125 |
-
`*(result + n) = std::move(*(first + n))`.
|
| 2126 |
|
| 2127 |
-
*Returns:* `result +
|
| 2128 |
|
| 2129 |
-
*Complexity:* Exactly
|
| 2130 |
|
| 2131 |
``` cpp
|
| 2132 |
template<class BidirectionalIterator1, class BidirectionalIterator2>
|
| 2133 |
-
BidirectionalIterator2
|
| 2134 |
-
move_backward(BidirectionalIterator1 first,
|
| 2135 |
-
BidirectionalIterator1 last,
|
| 2136 |
BidirectionalIterator2 result);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2137 |
```
|
| 2138 |
|
| 2139 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2140 |
|
| 2141 |
*Effects:* Moves elements in the range \[`first`, `last`) into the range
|
| 2142 |
-
\[`result -
|
| 2143 |
-
|
| 2144 |
-
`
|
| 2145 |
-
`*(result - n) = std::move(*(last - n))`.
|
| 2146 |
|
| 2147 |
-
*Returns:*
|
| 2148 |
|
| 2149 |
-
|
|
|
|
|
|
|
|
|
|
| 2150 |
|
| 2151 |
### Swap <a id="alg.swap">[[alg.swap]]</a>
|
| 2152 |
|
| 2153 |
``` cpp
|
| 2154 |
template<class ForwardIterator1, class ForwardIterator2>
|
| 2155 |
-
ForwardIterator2
|
| 2156 |
swap_ranges(ForwardIterator1 first1, ForwardIterator1 last1,
|
| 2157 |
ForwardIterator2 first2);
|
| 2158 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 2159 |
ForwardIterator2
|
| 2160 |
swap_ranges(ExecutionPolicy&& exec,
|
| 2161 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 2162 |
ForwardIterator2 first2);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2163 |
```
|
| 2164 |
|
| 2165 |
-
|
| 2166 |
-
`first2 + (last1 - first1)`) shall not overlap. `*(first1 + n)` shall be
|
| 2167 |
-
swappable with ([[swappable.requirements]]) `*(first2 + n)`.
|
| 2168 |
|
| 2169 |
-
|
| 2170 |
-
|
|
|
|
| 2171 |
|
| 2172 |
-
*
|
|
|
|
|
|
|
|
|
|
| 2173 |
|
| 2174 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2175 |
|
| 2176 |
``` cpp
|
| 2177 |
template<class ForwardIterator1, class ForwardIterator2>
|
| 2178 |
-
void iter_swap(ForwardIterator1 a, ForwardIterator2 b);
|
| 2179 |
```
|
| 2180 |
|
| 2181 |
-
*
|
| 2182 |
-
|
| 2183 |
|
| 2184 |
*Effects:* As if by `swap(*a, *b)`.
|
| 2185 |
|
| 2186 |
### Transform <a id="alg.transform">[[alg.transform]]</a>
|
| 2187 |
|
| 2188 |
``` cpp
|
| 2189 |
template<class InputIterator, class OutputIterator,
|
| 2190 |
class UnaryOperation>
|
| 2191 |
-
OutputIterator
|
| 2192 |
-
transform(InputIterator
|
| 2193 |
OutputIterator result, UnaryOperation op);
|
| 2194 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 2195 |
class UnaryOperation>
|
| 2196 |
ForwardIterator2
|
| 2197 |
transform(ExecutionPolicy&& exec,
|
| 2198 |
-
ForwardIterator1
|
| 2199 |
ForwardIterator2 result, UnaryOperation op);
|
| 2200 |
|
| 2201 |
template<class InputIterator1, class InputIterator2,
|
| 2202 |
class OutputIterator, class BinaryOperation>
|
| 2203 |
-
OutputIterator
|
| 2204 |
transform(InputIterator1 first1, InputIterator1 last1,
|
| 2205 |
InputIterator2 first2, OutputIterator result,
|
| 2206 |
BinaryOperation binary_op);
|
| 2207 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 2208 |
class ForwardIterator, class BinaryOperation>
|
| 2209 |
ForwardIterator
|
| 2210 |
transform(ExecutionPolicy&& exec,
|
| 2211 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 2212 |
ForwardIterator2 first2, ForwardIterator result,
|
| 2213 |
BinaryOperation binary_op);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2214 |
```
|
| 2215 |
|
| 2216 |
-
|
| 2217 |
-
subranges, or modify elements in the ranges
|
| 2218 |
|
| 2219 |
-
-
|
| 2220 |
-
|
| 2221 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2222 |
|
| 2223 |
*Effects:* Assigns through every iterator `i` in the range \[`result`,
|
| 2224 |
-
`result +
|
| 2225 |
-
`op(*(first1 + (i - result)))` or
|
| 2226 |
-
`binary_op(*(first1 + (i - result)), *(first2 + (i - result)))`.
|
| 2227 |
|
| 2228 |
-
*Returns:*
|
| 2229 |
|
| 2230 |
-
|
| 2231 |
-
`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2232 |
`ExecutionPolicy`.
|
| 2233 |
|
| 2234 |
-
*Remarks:* `result` may be equal to `
|
| 2235 |
-
or to `first1` or `first2` in case of binary transform.
|
| 2236 |
|
| 2237 |
### Replace <a id="alg.replace">[[alg.replace]]</a>
|
| 2238 |
|
| 2239 |
``` cpp
|
| 2240 |
template<class ForwardIterator, class T>
|
| 2241 |
-
void replace(ForwardIterator first, ForwardIterator last,
|
| 2242 |
const T& old_value, const T& new_value);
|
| 2243 |
template<class ExecutionPolicy, class ForwardIterator, class T>
|
| 2244 |
void replace(ExecutionPolicy&& exec,
|
| 2245 |
ForwardIterator first, ForwardIterator last,
|
| 2246 |
const T& old_value, const T& new_value);
|
| 2247 |
|
| 2248 |
template<class ForwardIterator, class Predicate, class T>
|
| 2249 |
-
void replace_if(ForwardIterator first, ForwardIterator last,
|
| 2250 |
Predicate pred, const T& new_value);
|
| 2251 |
template<class ExecutionPolicy, class ForwardIterator, class Predicate, class T>
|
| 2252 |
void replace_if(ExecutionPolicy&& exec,
|
| 2253 |
ForwardIterator first, ForwardIterator last,
|
| 2254 |
Predicate pred, const T& new_value);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2255 |
```
|
| 2256 |
|
| 2257 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2258 |
|
| 2259 |
*Effects:* Substitutes elements referred by the iterator `i` in the
|
| 2260 |
-
range \[`first`, `last`) with `new_value`, when
|
| 2261 |
-
|
|
|
|
| 2262 |
|
| 2263 |
*Complexity:* Exactly `last - first` applications of the corresponding
|
| 2264 |
-
predicate.
|
| 2265 |
|
| 2266 |
``` cpp
|
| 2267 |
template<class InputIterator, class OutputIterator, class T>
|
| 2268 |
-
OutputIterator
|
| 2269 |
replace_copy(InputIterator first, InputIterator last,
|
| 2270 |
OutputIterator result,
|
| 2271 |
const T& old_value, const T& new_value);
|
| 2272 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class T>
|
| 2273 |
ForwardIterator2
|
|
@@ -2275,401 +4311,642 @@ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
|
| 2275 |
ForwardIterator1 first, ForwardIterator1 last,
|
| 2276 |
ForwardIterator2 result,
|
| 2277 |
const T& old_value, const T& new_value);
|
| 2278 |
|
| 2279 |
template<class InputIterator, class OutputIterator, class Predicate, class T>
|
| 2280 |
-
OutputIterator
|
| 2281 |
replace_copy_if(InputIterator first, InputIterator last,
|
| 2282 |
OutputIterator result,
|
| 2283 |
Predicate pred, const T& new_value);
|
| 2284 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 2285 |
class Predicate, class T>
|
| 2286 |
ForwardIterator2
|
| 2287 |
replace_copy_if(ExecutionPolicy&& exec,
|
| 2288 |
ForwardIterator1 first, ForwardIterator1 last,
|
| 2289 |
ForwardIterator2 result,
|
| 2290 |
Predicate pred, const T& new_value);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2291 |
```
|
| 2292 |
|
| 2293 |
-
|
| 2294 |
-
shall be writable ([[iterator.requirements.general]]) to the `result`
|
| 2295 |
-
output iterator. The ranges \[`first`, `last`) and \[`result`,
|
| 2296 |
-
`result + (last - first)`) shall not overlap.
|
| 2297 |
|
| 2298 |
-
*
|
| 2299 |
-
`
|
| 2300 |
-
`*(first + (i - result))
|
| 2301 |
-
|
|
|
|
|
|
|
| 2302 |
|
| 2303 |
-
```
|
| 2304 |
-
|
| 2305 |
-
|
| 2306 |
-
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2307 |
|
| 2308 |
-
|
|
|
|
|
|
|
| 2309 |
|
| 2310 |
*Complexity:* Exactly `last - first` applications of the corresponding
|
| 2311 |
-
predicate.
|
| 2312 |
|
| 2313 |
### Fill <a id="alg.fill">[[alg.fill]]</a>
|
| 2314 |
|
| 2315 |
``` cpp
|
| 2316 |
template<class ForwardIterator, class T>
|
| 2317 |
-
void fill(ForwardIterator first, ForwardIterator last, const T& value);
|
| 2318 |
template<class ExecutionPolicy, class ForwardIterator, class T>
|
| 2319 |
void fill(ExecutionPolicy&& exec,
|
| 2320 |
ForwardIterator first, ForwardIterator last, const T& value);
|
| 2321 |
|
| 2322 |
template<class OutputIterator, class Size, class T>
|
| 2323 |
-
OutputIterator fill_n(OutputIterator first, Size n, const T& value);
|
| 2324 |
template<class ExecutionPolicy, class ForwardIterator, class Size, class T>
|
| 2325 |
ForwardIterator fill_n(ExecutionPolicy&& exec,
|
| 2326 |
ForwardIterator first, Size n, const T& value);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2327 |
```
|
| 2328 |
|
| 2329 |
-
|
| 2330 |
-
|
| 2331 |
-
The type `Size` shall be convertible to an integral
|
| 2332 |
-
type ([[conv.integral]], [[class.conv]]).
|
| 2333 |
|
| 2334 |
-
*
|
| 2335 |
-
|
| 2336 |
-
|
| 2337 |
-
|
| 2338 |
|
| 2339 |
-
*
|
| 2340 |
-
|
| 2341 |
|
| 2342 |
-
*
|
| 2343 |
-
|
|
|
|
| 2344 |
|
| 2345 |
### Generate <a id="alg.generate">[[alg.generate]]</a>
|
| 2346 |
|
| 2347 |
``` cpp
|
| 2348 |
template<class ForwardIterator, class Generator>
|
| 2349 |
-
void generate(ForwardIterator first, ForwardIterator last,
|
| 2350 |
Generator gen);
|
| 2351 |
template<class ExecutionPolicy, class ForwardIterator, class Generator>
|
| 2352 |
void generate(ExecutionPolicy&& exec,
|
| 2353 |
ForwardIterator first, ForwardIterator last,
|
| 2354 |
Generator gen);
|
| 2355 |
|
| 2356 |
template<class OutputIterator, class Size, class Generator>
|
| 2357 |
-
OutputIterator generate_n(OutputIterator first, Size n, Generator gen);
|
| 2358 |
template<class ExecutionPolicy, class ForwardIterator, class Size, class Generator>
|
| 2359 |
ForwardIterator generate_n(ExecutionPolicy&& exec,
|
| 2360 |
ForwardIterator first, Size n, Generator gen);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2361 |
```
|
| 2362 |
|
| 2363 |
-
|
| 2364 |
-
|
| 2365 |
|
| 2366 |
-
*
|
| 2367 |
-
|
| 2368 |
-
range \[`first`, `last`). The `generate_n` algorithms invoke the
|
| 2369 |
-
function object `gen` and assign the return value of `gen` through all
|
| 2370 |
-
the iterators in the range \[`first`, `first + n`) if `n` is positive,
|
| 2371 |
-
otherwise they do nothing.
|
| 2372 |
|
| 2373 |
-
*
|
| 2374 |
-
|
| 2375 |
|
| 2376 |
-
*
|
| 2377 |
-
|
|
|
|
| 2378 |
|
| 2379 |
### Remove <a id="alg.remove">[[alg.remove]]</a>
|
| 2380 |
|
| 2381 |
``` cpp
|
| 2382 |
template<class ForwardIterator, class T>
|
| 2383 |
-
ForwardIterator remove(ForwardIterator first, ForwardIterator last,
|
| 2384 |
const T& value);
|
| 2385 |
template<class ExecutionPolicy, class ForwardIterator, class T>
|
| 2386 |
ForwardIterator remove(ExecutionPolicy&& exec,
|
| 2387 |
ForwardIterator first, ForwardIterator last,
|
| 2388 |
const T& value);
|
| 2389 |
|
| 2390 |
template<class ForwardIterator, class Predicate>
|
| 2391 |
-
ForwardIterator remove_if(ForwardIterator first, ForwardIterator last,
|
| 2392 |
Predicate pred);
|
| 2393 |
template<class ExecutionPolicy, class ForwardIterator, class Predicate>
|
| 2394 |
ForwardIterator remove_if(ExecutionPolicy&& exec,
|
| 2395 |
ForwardIterator first, ForwardIterator last,
|
| 2396 |
Predicate pred);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2397 |
```
|
| 2398 |
|
| 2399 |
-
|
| 2400 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2401 |
|
| 2402 |
*Effects:* Eliminates all the elements referred to by iterator `i` in
|
| 2403 |
-
the range \[`first`, `last`) for which
|
| 2404 |
-
conditions hold: `*i == value, pred(*i) != false`.
|
| 2405 |
|
| 2406 |
-
*Returns:*
|
| 2407 |
|
| 2408 |
-
|
|
|
|
|
|
|
|
|
|
| 2409 |
|
| 2410 |
*Complexity:* Exactly `last - first` applications of the corresponding
|
| 2411 |
-
predicate.
|
| 2412 |
|
| 2413 |
[*Note 1*: Each element in the range \[`ret`, `last`), where `ret` is
|
| 2414 |
the returned value, has a valid but unspecified state, because the
|
| 2415 |
algorithms can eliminate elements by moving from elements that were
|
| 2416 |
originally in that range. — *end note*]
|
| 2417 |
|
| 2418 |
``` cpp
|
| 2419 |
template<class InputIterator, class OutputIterator, class T>
|
| 2420 |
-
OutputIterator
|
| 2421 |
remove_copy(InputIterator first, InputIterator last,
|
| 2422 |
OutputIterator result, const T& value);
|
| 2423 |
-
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
|
|
|
| 2424 |
ForwardIterator2
|
| 2425 |
remove_copy(ExecutionPolicy&& exec,
|
| 2426 |
ForwardIterator1 first, ForwardIterator1 last,
|
| 2427 |
ForwardIterator2 result, const T& value);
|
| 2428 |
|
| 2429 |
template<class InputIterator, class OutputIterator, class Predicate>
|
| 2430 |
-
OutputIterator
|
| 2431 |
remove_copy_if(InputIterator first, InputIterator last,
|
| 2432 |
OutputIterator result, Predicate pred);
|
| 2433 |
-
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
|
|
|
| 2434 |
ForwardIterator2
|
| 2435 |
remove_copy_if(ExecutionPolicy&& exec,
|
| 2436 |
ForwardIterator1 first, ForwardIterator1 last,
|
| 2437 |
ForwardIterator2 result, Predicate pred);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2438 |
```
|
| 2439 |
|
| 2440 |
-
|
| 2441 |
-
|
| 2442 |
-
`*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2443 |
|
| 2444 |
[*Note 2*: For the overloads with an `ExecutionPolicy`, there may be a
|
| 2445 |
-
performance cost if `iterator_traits<ForwardIterator1>::value_type`
|
| 2446 |
-
not
|
| 2447 |
-
|
| 2448 |
|
| 2449 |
*Effects:* Copies all the elements referred to by the iterator `i` in
|
| 2450 |
-
the range \[`first`, `last`) for which
|
| 2451 |
-
conditions do not hold: `*i == value, pred(*i) != false`.
|
| 2452 |
|
| 2453 |
-
*Returns:*
|
|
|
|
|
|
|
|
|
|
| 2454 |
|
| 2455 |
*Complexity:* Exactly `last - first` applications of the corresponding
|
| 2456 |
-
predicate.
|
| 2457 |
|
| 2458 |
-
*Remarks:* Stable
|
| 2459 |
|
| 2460 |
### Unique <a id="alg.unique">[[alg.unique]]</a>
|
| 2461 |
|
| 2462 |
``` cpp
|
| 2463 |
template<class ForwardIterator>
|
| 2464 |
-
ForwardIterator unique(ForwardIterator first, ForwardIterator last);
|
| 2465 |
template<class ExecutionPolicy, class ForwardIterator>
|
| 2466 |
ForwardIterator unique(ExecutionPolicy&& exec,
|
| 2467 |
ForwardIterator first, ForwardIterator last);
|
| 2468 |
|
| 2469 |
template<class ForwardIterator, class BinaryPredicate>
|
| 2470 |
-
ForwardIterator unique(ForwardIterator first, ForwardIterator last,
|
| 2471 |
BinaryPredicate pred);
|
| 2472 |
template<class ExecutionPolicy, class ForwardIterator, class BinaryPredicate>
|
| 2473 |
ForwardIterator unique(ExecutionPolicy&& exec,
|
| 2474 |
ForwardIterator first, ForwardIterator last,
|
| 2475 |
BinaryPredicate pred);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2476 |
```
|
| 2477 |
|
| 2478 |
-
|
| 2479 |
-
|
| 2480 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2481 |
|
| 2482 |
*Effects:* For a nonempty range, eliminates all but the first element
|
| 2483 |
from every consecutive group of equivalent elements referred to by the
|
| 2484 |
-
iterator `i` in the range \[`first + 1`, `last`) for which
|
| 2485 |
-
conditions hold: `*(i - 1) == *i` or `pred(*(i - 1), *i) != false`.
|
| 2486 |
|
| 2487 |
-
*Returns:*
|
|
|
|
|
|
|
|
|
|
| 2488 |
|
| 2489 |
*Complexity:* For nonempty ranges, exactly `(last - first) - 1`
|
| 2490 |
-
applications of the corresponding predicate
|
|
|
|
| 2491 |
|
| 2492 |
``` cpp
|
| 2493 |
template<class InputIterator, class OutputIterator>
|
| 2494 |
-
OutputIterator
|
| 2495 |
unique_copy(InputIterator first, InputIterator last,
|
| 2496 |
OutputIterator result);
|
| 2497 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 2498 |
ForwardIterator2
|
| 2499 |
unique_copy(ExecutionPolicy&& exec,
|
| 2500 |
ForwardIterator1 first, ForwardIterator1 last,
|
| 2501 |
ForwardIterator2 result);
|
| 2502 |
|
| 2503 |
template<class InputIterator, class OutputIterator,
|
| 2504 |
class BinaryPredicate>
|
| 2505 |
-
OutputIterator
|
| 2506 |
unique_copy(InputIterator first, InputIterator last,
|
| 2507 |
OutputIterator result, BinaryPredicate pred);
|
| 2508 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 2509 |
class BinaryPredicate>
|
| 2510 |
ForwardIterator2
|
| 2511 |
unique_copy(ExecutionPolicy&& exec,
|
| 2512 |
ForwardIterator1 first, ForwardIterator1 last,
|
| 2513 |
ForwardIterator2 result, BinaryPredicate pred);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2514 |
```
|
| 2515 |
|
| 2516 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2517 |
|
| 2518 |
-
- The comparison function shall be an equivalence relation.
|
| 2519 |
- The ranges \[`first`, `last`) and \[`result`, `result+(last-first)`)
|
| 2520 |
-
|
| 2521 |
-
-
|
| 2522 |
-
-
|
| 2523 |
-
|
| 2524 |
-
|
| 2525 |
-
|
| 2526 |
-
|
| 2527 |
-
|
| 2528 |
-
|
| 2529 |
-
|
| 2530 |
-
|
| 2531 |
-
|
| 2532 |
-
|
|
|
|
|
|
|
|
|
|
| 2533 |
|
| 2534 |
*Effects:* Copies only the first element from every consecutive group of
|
| 2535 |
equal elements referred to by the iterator `i` in the range \[`first`,
|
| 2536 |
-
`last`) for which
|
| 2537 |
-
`*i == *(i - 1)` or `pred(*i, *(i - 1)) != false`.
|
| 2538 |
|
| 2539 |
-
*Returns:*
|
| 2540 |
|
| 2541 |
-
|
| 2542 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2543 |
|
| 2544 |
### Reverse <a id="alg.reverse">[[alg.reverse]]</a>
|
| 2545 |
|
| 2546 |
``` cpp
|
| 2547 |
template<class BidirectionalIterator>
|
| 2548 |
-
void reverse(BidirectionalIterator first, BidirectionalIterator last);
|
| 2549 |
template<class ExecutionPolicy, class BidirectionalIterator>
|
| 2550 |
void reverse(ExecutionPolicy&& exec,
|
| 2551 |
BidirectionalIterator first, BidirectionalIterator last);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2552 |
```
|
| 2553 |
|
| 2554 |
-
*
|
|
|
|
|
|
|
| 2555 |
|
| 2556 |
*Effects:* For each non-negative integer `i < (last - first) / 2`,
|
| 2557 |
-
applies `iter_swap`
|
|
|
|
| 2558 |
`first + i, (last - i) - 1`.
|
| 2559 |
|
| 2560 |
-
*
|
| 2561 |
-
`ValueSwappable` ([[swappable.requirements]]).
|
| 2562 |
|
| 2563 |
*Complexity:* Exactly `(last - first)/2` swaps.
|
| 2564 |
|
| 2565 |
``` cpp
|
| 2566 |
template<class BidirectionalIterator, class OutputIterator>
|
| 2567 |
-
OutputIterator
|
| 2568 |
reverse_copy(BidirectionalIterator first, BidirectionalIterator last,
|
| 2569 |
OutputIterator result);
|
| 2570 |
template<class ExecutionPolicy, class BidirectionalIterator, class ForwardIterator>
|
| 2571 |
ForwardIterator
|
| 2572 |
reverse_copy(ExecutionPolicy&& exec,
|
| 2573 |
BidirectionalIterator first, BidirectionalIterator last,
|
| 2574 |
ForwardIterator result);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2575 |
```
|
| 2576 |
|
| 2577 |
-
|
| 2578 |
-
|
|
|
|
|
|
|
| 2579 |
|
| 2580 |
*Effects:* Copies the range \[`first`, `last`) to the range \[`result`,
|
| 2581 |
-
`result +
|
| 2582 |
-
|
| 2583 |
-
`*(result +
|
| 2584 |
|
| 2585 |
-
*Returns:*
|
| 2586 |
|
| 2587 |
-
|
|
|
|
|
|
|
|
|
|
| 2588 |
|
| 2589 |
### Rotate <a id="alg.rotate">[[alg.rotate]]</a>
|
| 2590 |
|
| 2591 |
``` cpp
|
| 2592 |
template<class ForwardIterator>
|
| 2593 |
-
ForwardIterator
|
| 2594 |
rotate(ForwardIterator first, ForwardIterator middle, ForwardIterator last);
|
| 2595 |
template<class ExecutionPolicy, class ForwardIterator>
|
| 2596 |
ForwardIterator
|
| 2597 |
rotate(ExecutionPolicy&& exec,
|
| 2598 |
ForwardIterator first, ForwardIterator middle, ForwardIterator last);
|
|
|
|
|
|
|
|
|
|
| 2599 |
```
|
| 2600 |
|
| 2601 |
-
*
|
| 2602 |
-
ranges.
|
| 2603 |
-
|
| 2604 |
-
|
| 2605 |
-
(
|
| 2606 |
-
|
| 2607 |
|
| 2608 |
*Effects:* For each non-negative integer `i < (last - first)`, places
|
| 2609 |
the element from the position `first + i` into position
|
| 2610 |
`first + (i + (last - middle)) % (last - first)`.
|
| 2611 |
|
| 2612 |
-
*
|
| 2613 |
|
| 2614 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2615 |
|
| 2616 |
*Complexity:* At most `last - first` swaps.
|
| 2617 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2618 |
``` cpp
|
| 2619 |
template<class ForwardIterator, class OutputIterator>
|
| 2620 |
-
OutputIterator
|
| 2621 |
rotate_copy(ForwardIterator first, ForwardIterator middle, ForwardIterator last,
|
| 2622 |
OutputIterator result);
|
| 2623 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 2624 |
ForwardIterator2
|
| 2625 |
rotate_copy(ExecutionPolicy&& exec,
|
| 2626 |
ForwardIterator1 first, ForwardIterator1 middle, ForwardIterator1 last,
|
| 2627 |
ForwardIterator2 result);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2628 |
```
|
| 2629 |
|
| 2630 |
-
|
| 2631 |
-
|
|
|
|
|
|
|
|
|
|
| 2632 |
|
| 2633 |
*Effects:* Copies the range \[`first`, `last`) to the range \[`result`,
|
| 2634 |
-
`result +
|
| 2635 |
-
|
| 2636 |
-
`*(result + i) = *(first + (i + (middle - first)) %
|
| 2637 |
|
| 2638 |
-
*Returns:*
|
| 2639 |
|
| 2640 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2641 |
|
| 2642 |
### Sample <a id="alg.random.sample">[[alg.random.sample]]</a>
|
| 2643 |
|
| 2644 |
``` cpp
|
| 2645 |
template<class PopulationIterator, class SampleIterator,
|
| 2646 |
class Distance, class UniformRandomBitGenerator>
|
| 2647 |
SampleIterator sample(PopulationIterator first, PopulationIterator last,
|
| 2648 |
SampleIterator out, Distance n,
|
| 2649 |
UniformRandomBitGenerator&& g);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2650 |
```
|
| 2651 |
|
| 2652 |
-
*
|
|
|
|
|
|
|
| 2653 |
|
| 2654 |
-
|
| 2655 |
-
|
| 2656 |
-
- `SampleIterator` shall satisfy the requirements of an output
|
| 2657 |
-
iterator ([[output.iterators]]).
|
| 2658 |
-
- `SampleIterator` shall satisfy the additional requirements of a random
|
| 2659 |
-
access iterator ([[random.access.iterators]]) unless
|
| 2660 |
-
`PopulationIterator` satisfies the additional requirements of a
|
| 2661 |
-
forward iterator ([[forward.iterators]]).
|
| 2662 |
-
- `PopulationIterator`’s value type shall be
|
| 2663 |
-
writable ([[iterator.requirements.general]]) to `out`.
|
| 2664 |
-
- `Distance` shall be an integer type.
|
| 2665 |
-
- `remove_reference_t<UniformRandomBitGenerator>` shall meet the
|
| 2666 |
-
requirements of a uniform random bit generator type
|
| 2667 |
-
([[rand.req.urng]]) whose return type is convertible to `Distance`.
|
| 2668 |
-
- `out` shall not be in the range \[`first`, `last`).
|
| 2669 |
|
| 2670 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2671 |
\[`first`, `last`) (the *population*) to `out` such that each possible
|
| 2672 |
sample has equal probability of appearance.
|
| 2673 |
|
| 2674 |
[*Note 1*: Algorithms that obtain such effects include *selection
|
| 2675 |
sampling* and *reservoir sampling*. — *end note*]
|
|
@@ -2678,56 +4955,122 @@ sampling* and *reservoir sampling*. — *end note*]
|
|
| 2678 |
|
| 2679 |
*Complexity:* 𝑂(`last - first`).
|
| 2680 |
|
| 2681 |
*Remarks:*
|
| 2682 |
|
| 2683 |
-
-
|
| 2684 |
-
|
|
|
|
|
|
|
| 2685 |
- To the extent that the implementation of this function makes use of
|
| 2686 |
-
random numbers, the object `g`
|
| 2687 |
-
|
| 2688 |
|
| 2689 |
### Shuffle <a id="alg.random.shuffle">[[alg.random.shuffle]]</a>
|
| 2690 |
|
| 2691 |
``` cpp
|
| 2692 |
template<class RandomAccessIterator, class UniformRandomBitGenerator>
|
| 2693 |
void shuffle(RandomAccessIterator first,
|
| 2694 |
RandomAccessIterator last,
|
| 2695 |
UniformRandomBitGenerator&& g);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2696 |
```
|
| 2697 |
|
| 2698 |
-
*
|
| 2699 |
-
|
| 2700 |
-
`
|
| 2701 |
-
requirements
|
| 2702 |
-
|
| 2703 |
-
|
| 2704 |
|
| 2705 |
*Effects:* Permutes the elements in the range \[`first`, `last`) such
|
| 2706 |
that each possible permutation of those elements has equal probability
|
| 2707 |
of appearance.
|
| 2708 |
|
|
|
|
|
|
|
| 2709 |
*Complexity:* Exactly `(last - first) - 1` swaps.
|
| 2710 |
|
| 2711 |
*Remarks:* To the extent that the implementation of this function makes
|
| 2712 |
-
use of random numbers, the object `g` shall serve as the
|
| 2713 |
implementation’s source of randomness.
|
| 2714 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2715 |
## Sorting and related operations <a id="alg.sorting">[[alg.sorting]]</a>
|
| 2716 |
|
| 2717 |
-
|
| 2718 |
-
a function object of type `Compare`
|
|
|
|
| 2719 |
|
| 2720 |
-
`Compare`
|
| 2721 |
-
|
| 2722 |
-
|
| 2723 |
-
|
| 2724 |
-
|
| 2725 |
-
|
| 2726 |
-
|
| 2727 |
-
ordering relation. It is assumed that `comp` will not apply any
|
| 2728 |
-
non-constant function through the dereferenced iterator.
|
| 2729 |
|
| 2730 |
For all algorithms that take `Compare`, there is a version that uses
|
| 2731 |
`operator<` instead. That is, `comp(*i, *j) != false` defaults to
|
| 2732 |
`*i < *j != false`. For algorithms other than those described in
|
| 2733 |
[[alg.binary.search]], `comp` shall induce a strict weak ordering on the
|
|
@@ -2745,21 +5088,27 @@ for a partial ordering. If we define `equiv(a, b)` as
|
|
| 2745 |
|
| 2746 |
[*Note 1*:
|
| 2747 |
|
| 2748 |
Under these conditions, it can be shown that
|
| 2749 |
|
| 2750 |
-
- `equiv` is an equivalence relation
|
| 2751 |
- `comp` induces a well-defined relation on the equivalence classes
|
| 2752 |
-
determined by `equiv`
|
| 2753 |
-
-
|
| 2754 |
|
| 2755 |
— *end note*]
|
| 2756 |
|
| 2757 |
-
A sequence is *sorted with respect to a
|
| 2758 |
-
|
| 2759 |
-
|
| 2760 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2761 |
|
| 2762 |
A sequence \[`start`, `finish`) is *partitioned with respect to an
|
| 2763 |
expression* `f(e)` if there exists an integer `n` such that for all
|
| 2764 |
`0 <= i < (finish - start)`, `f(*(start + i))` is `true` if and only if
|
| 2765 |
`i < n`.
|
|
@@ -2775,33 +5124,50 @@ equivalent if and only if `!(a < b) && !(b < a)`.
|
|
| 2775 |
|
| 2776 |
#### `sort` <a id="sort">[[sort]]</a>
|
| 2777 |
|
| 2778 |
``` cpp
|
| 2779 |
template<class RandomAccessIterator>
|
| 2780 |
-
void sort(RandomAccessIterator first, RandomAccessIterator last);
|
| 2781 |
template<class ExecutionPolicy, class RandomAccessIterator>
|
| 2782 |
void sort(ExecutionPolicy&& exec,
|
| 2783 |
RandomAccessIterator first, RandomAccessIterator last);
|
| 2784 |
|
| 2785 |
template<class RandomAccessIterator, class Compare>
|
| 2786 |
-
void sort(RandomAccessIterator first, RandomAccessIterator last,
|
| 2787 |
Compare comp);
|
| 2788 |
template<class ExecutionPolicy, class RandomAccessIterator, class Compare>
|
| 2789 |
void sort(ExecutionPolicy&& exec,
|
| 2790 |
RandomAccessIterator first, RandomAccessIterator last,
|
| 2791 |
Compare comp);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2792 |
```
|
| 2793 |
|
| 2794 |
-
|
| 2795 |
-
|
| 2796 |
-
shall satisfy the requirements of `MoveConstructible`
|
| 2797 |
-
(Table [[tab:moveconstructible]]) and of `MoveAssignable`
|
| 2798 |
-
(Table [[tab:moveassignable]]).
|
| 2799 |
|
| 2800 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2801 |
|
| 2802 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2803 |
|
| 2804 |
#### `stable_sort` <a id="stable.sort">[[stable.sort]]</a>
|
| 2805 |
|
| 2806 |
``` cpp
|
| 2807 |
template<class RandomAccessIterator>
|
|
@@ -2815,70 +5181,112 @@ template<class RandomAccessIterator, class Compare>
|
|
| 2815 |
Compare comp);
|
| 2816 |
template<class ExecutionPolicy, class RandomAccessIterator, class Compare>
|
| 2817 |
void stable_sort(ExecutionPolicy&& exec,
|
| 2818 |
RandomAccessIterator first, RandomAccessIterator last,
|
| 2819 |
Compare comp);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2820 |
```
|
| 2821 |
|
| 2822 |
-
|
| 2823 |
-
|
| 2824 |
-
shall satisfy the requirements of `MoveConstructible`
|
| 2825 |
-
(Table [[tab:moveconstructible]]) and of `MoveAssignable`
|
| 2826 |
-
(Table [[tab:moveassignable]]).
|
| 2827 |
|
| 2828 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2829 |
|
| 2830 |
-
*
|
| 2831 |
-
|
| 2832 |
|
| 2833 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2834 |
|
| 2835 |
#### `partial_sort` <a id="partial.sort">[[partial.sort]]</a>
|
| 2836 |
|
| 2837 |
``` cpp
|
| 2838 |
template<class RandomAccessIterator>
|
| 2839 |
-
void partial_sort(RandomAccessIterator first,
|
| 2840 |
RandomAccessIterator middle,
|
| 2841 |
RandomAccessIterator last);
|
| 2842 |
template<class ExecutionPolicy, class RandomAccessIterator>
|
| 2843 |
void partial_sort(ExecutionPolicy&& exec,
|
| 2844 |
RandomAccessIterator first,
|
| 2845 |
RandomAccessIterator middle,
|
| 2846 |
RandomAccessIterator last);
|
| 2847 |
|
| 2848 |
template<class RandomAccessIterator, class Compare>
|
| 2849 |
-
void partial_sort(RandomAccessIterator first,
|
| 2850 |
RandomAccessIterator middle,
|
| 2851 |
RandomAccessIterator last,
|
| 2852 |
Compare comp);
|
| 2853 |
template<class ExecutionPolicy, class RandomAccessIterator, class Compare>
|
| 2854 |
void partial_sort(ExecutionPolicy&& exec,
|
| 2855 |
RandomAccessIterator first,
|
| 2856 |
RandomAccessIterator middle,
|
| 2857 |
RandomAccessIterator last,
|
| 2858 |
Compare comp);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2859 |
```
|
| 2860 |
|
| 2861 |
-
|
| 2862 |
-
|
| 2863 |
-
shall satisfy the requirements of `MoveConstructible`
|
| 2864 |
-
(Table [[tab:moveconstructible]]) and of `MoveAssignable`
|
| 2865 |
-
(Table [[tab:moveassignable]]).
|
| 2866 |
|
| 2867 |
-
*
|
| 2868 |
-
|
| 2869 |
-
|
| 2870 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2871 |
|
| 2872 |
*Complexity:* Approximately `(last - first) * log(middle - first)`
|
| 2873 |
-
comparisons.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2874 |
|
| 2875 |
#### `partial_sort_copy` <a id="partial.sort.copy">[[partial.sort.copy]]</a>
|
| 2876 |
|
| 2877 |
``` cpp
|
| 2878 |
template<class InputIterator, class RandomAccessIterator>
|
| 2879 |
-
RandomAccessIterator
|
| 2880 |
partial_sort_copy(InputIterator first, InputIterator last,
|
| 2881 |
RandomAccessIterator result_first,
|
| 2882 |
RandomAccessIterator result_last);
|
| 2883 |
template<class ExecutionPolicy, class ForwardIterator, class RandomAccessIterator>
|
| 2884 |
RandomAccessIterator
|
|
@@ -2887,11 +5295,11 @@ template<class ExecutionPolicy, class ForwardIterator, class RandomAccessIterato
|
|
| 2887 |
RandomAccessIterator result_first,
|
| 2888 |
RandomAccessIterator result_last);
|
| 2889 |
|
| 2890 |
template<class InputIterator, class RandomAccessIterator,
|
| 2891 |
class Compare>
|
| 2892 |
-
RandomAccessIterator
|
| 2893 |
partial_sort_copy(InputIterator first, InputIterator last,
|
| 2894 |
RandomAccessIterator result_first,
|
| 2895 |
RandomAccessIterator result_last,
|
| 2896 |
Compare comp);
|
| 2897 |
template<class ExecutionPolicy, class ForwardIterator, class RandomAccessIterator,
|
|
@@ -2900,398 +5308,611 @@ template<class ExecutionPolicy, class ForwardIterator, class RandomAccessIterato
|
|
| 2900 |
partial_sort_copy(ExecutionPolicy&& exec,
|
| 2901 |
ForwardIterator first, ForwardIterator last,
|
| 2902 |
RandomAccessIterator result_first,
|
| 2903 |
RandomAccessIterator result_last,
|
| 2904 |
Compare comp);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2905 |
```
|
| 2906 |
|
| 2907 |
-
|
| 2908 |
-
`
|
| 2909 |
-
|
| 2910 |
-
|
| 2911 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2912 |
|
| 2913 |
-
*
|
| 2914 |
-
`min(last - first, result_last - result_first)` sorted elements into the
|
| 2915 |
-
range \[`result_first`,
|
| 2916 |
-
`result_first + min(last - first, result_last - result_first)`).
|
| 2917 |
|
| 2918 |
-
|
| 2919 |
-
`result_first +
|
| 2920 |
|
| 2921 |
-
*Complexity:* Approximately
|
| 2922 |
-
|
| 2923 |
-
comparisons.
|
| 2924 |
|
| 2925 |
#### `is_sorted` <a id="is.sorted">[[is.sorted]]</a>
|
| 2926 |
|
| 2927 |
``` cpp
|
| 2928 |
template<class ForwardIterator>
|
| 2929 |
-
bool is_sorted(ForwardIterator first, ForwardIterator last);
|
| 2930 |
```
|
| 2931 |
|
| 2932 |
-
*
|
| 2933 |
|
| 2934 |
``` cpp
|
| 2935 |
template<class ExecutionPolicy, class ForwardIterator>
|
| 2936 |
bool is_sorted(ExecutionPolicy&& exec,
|
| 2937 |
ForwardIterator first, ForwardIterator last);
|
| 2938 |
```
|
| 2939 |
|
| 2940 |
-
*
|
| 2941 |
-
|
|
|
|
|
|
|
|
|
|
| 2942 |
|
| 2943 |
``` cpp
|
| 2944 |
template<class ForwardIterator, class Compare>
|
| 2945 |
-
bool is_sorted(ForwardIterator first, ForwardIterator last,
|
| 2946 |
Compare comp);
|
| 2947 |
```
|
| 2948 |
|
| 2949 |
-
*
|
|
|
|
| 2950 |
|
| 2951 |
``` cpp
|
| 2952 |
template<class ExecutionPolicy, class ForwardIterator, class Compare>
|
| 2953 |
bool is_sorted(ExecutionPolicy&& exec,
|
| 2954 |
ForwardIterator first, ForwardIterator last,
|
| 2955 |
Compare comp);
|
| 2956 |
```
|
| 2957 |
|
| 2958 |
-
*
|
| 2959 |
|
| 2960 |
``` cpp
|
| 2961 |
-
is_sorted_until(std::forward<ExecutionPolicy>(exec), first, last, comp) == last
|
| 2962 |
```
|
| 2963 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2964 |
``` cpp
|
| 2965 |
template<class ForwardIterator>
|
| 2966 |
-
|
|
|
|
| 2967 |
template<class ExecutionPolicy, class ForwardIterator>
|
| 2968 |
-
ForwardIterator
|
|
|
|
| 2969 |
ForwardIterator first, ForwardIterator last);
|
| 2970 |
|
| 2971 |
template<class ForwardIterator, class Compare>
|
| 2972 |
-
|
|
|
|
| 2973 |
Compare comp);
|
| 2974 |
template<class ExecutionPolicy, class ForwardIterator, class Compare>
|
| 2975 |
-
ForwardIterator
|
|
|
|
| 2976 |
ForwardIterator first, ForwardIterator last,
|
| 2977 |
Compare comp);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2978 |
```
|
| 2979 |
|
| 2980 |
-
|
| 2981 |
-
|
| 2982 |
-
|
|
|
|
|
|
|
| 2983 |
|
| 2984 |
*Complexity:* Linear.
|
| 2985 |
|
| 2986 |
### Nth element <a id="alg.nth.element">[[alg.nth.element]]</a>
|
| 2987 |
|
| 2988 |
``` cpp
|
| 2989 |
template<class RandomAccessIterator>
|
| 2990 |
-
void nth_element(RandomAccessIterator first, RandomAccessIterator nth,
|
| 2991 |
RandomAccessIterator last);
|
| 2992 |
template<class ExecutionPolicy, class RandomAccessIterator>
|
| 2993 |
void nth_element(ExecutionPolicy&& exec,
|
| 2994 |
RandomAccessIterator first, RandomAccessIterator nth,
|
| 2995 |
RandomAccessIterator last);
|
| 2996 |
|
| 2997 |
template<class RandomAccessIterator, class Compare>
|
| 2998 |
-
void nth_element(RandomAccessIterator first, RandomAccessIterator nth,
|
| 2999 |
RandomAccessIterator last, Compare comp);
|
| 3000 |
template<class ExecutionPolicy, class RandomAccessIterator, class Compare>
|
| 3001 |
void nth_element(ExecutionPolicy&& exec,
|
| 3002 |
RandomAccessIterator first, RandomAccessIterator nth,
|
| 3003 |
RandomAccessIterator last, Compare comp);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3004 |
```
|
| 3005 |
|
| 3006 |
-
|
| 3007 |
-
|
| 3008 |
-
|
| 3009 |
-
|
| 3010 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3011 |
|
| 3012 |
*Effects:* After `nth_element` the element in the position pointed to by
|
| 3013 |
`nth` is the element that would be in that position if the whole range
|
| 3014 |
-
were sorted, unless `nth == last`.
|
| 3015 |
-
|
| 3016 |
-
|
|
|
|
|
|
|
|
|
|
| 3017 |
|
| 3018 |
*Complexity:* For the overloads with no `ExecutionPolicy`, linear on
|
| 3019 |
average. For the overloads with an `ExecutionPolicy`, 𝑂(N) applications
|
| 3020 |
of the predicate, and 𝑂(N log N) swaps, where N = `last - first`.
|
| 3021 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3022 |
### Binary search <a id="alg.binary.search">[[alg.binary.search]]</a>
|
| 3023 |
|
| 3024 |
-
All of the algorithms in this
|
| 3025 |
-
assume that the sequence being searched is partitioned with respect
|
| 3026 |
-
an expression formed by binding the search key to an argument of the
|
| 3027 |
-
|
| 3028 |
-
|
| 3029 |
-
|
| 3030 |
-
|
| 3031 |
-
|
| 3032 |
-
|
| 3033 |
|
| 3034 |
#### `lower_bound` <a id="lower.bound">[[lower.bound]]</a>
|
| 3035 |
|
| 3036 |
``` cpp
|
| 3037 |
template<class ForwardIterator, class T>
|
| 3038 |
-
ForwardIterator
|
| 3039 |
lower_bound(ForwardIterator first, ForwardIterator last,
|
| 3040 |
const T& value);
|
| 3041 |
|
| 3042 |
template<class ForwardIterator, class T, class Compare>
|
| 3043 |
-
ForwardIterator
|
| 3044 |
lower_bound(ForwardIterator first, ForwardIterator last,
|
| 3045 |
const T& value, Compare comp);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3046 |
```
|
| 3047 |
|
| 3048 |
-
|
| 3049 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3050 |
|
| 3051 |
*Returns:* The furthermost iterator `i` in the range \[`first`, `last`\]
|
| 3052 |
-
such that for every iterator `j` in the range \[`first`, `i`)
|
| 3053 |
-
|
| 3054 |
-
`comp(*j, value) != false`.
|
| 3055 |
|
| 3056 |
-
*Complexity:* At most log₂(`last - first`) + 𝑂(1) comparisons
|
|
|
|
| 3057 |
|
| 3058 |
#### `upper_bound` <a id="upper.bound">[[upper.bound]]</a>
|
| 3059 |
|
| 3060 |
``` cpp
|
| 3061 |
template<class ForwardIterator, class T>
|
| 3062 |
-
ForwardIterator
|
| 3063 |
upper_bound(ForwardIterator first, ForwardIterator last,
|
| 3064 |
const T& value);
|
| 3065 |
|
| 3066 |
template<class ForwardIterator, class T, class Compare>
|
| 3067 |
-
ForwardIterator
|
| 3068 |
upper_bound(ForwardIterator first, ForwardIterator last,
|
| 3069 |
const T& value, Compare comp);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3070 |
```
|
| 3071 |
|
| 3072 |
-
|
| 3073 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3074 |
|
| 3075 |
*Returns:* The furthermost iterator `i` in the range \[`first`, `last`\]
|
| 3076 |
-
such that for every iterator `j` in the range \[`first`, `i`)
|
| 3077 |
-
|
| 3078 |
-
`comp(value, *j) == false`.
|
| 3079 |
|
| 3080 |
-
*Complexity:* At most log₂(`last - first`) + 𝑂(1) comparisons
|
|
|
|
| 3081 |
|
| 3082 |
#### `equal_range` <a id="equal.range">[[equal.range]]</a>
|
| 3083 |
|
| 3084 |
``` cpp
|
| 3085 |
template<class ForwardIterator, class T>
|
| 3086 |
-
pair<ForwardIterator, ForwardIterator>
|
| 3087 |
equal_range(ForwardIterator first,
|
| 3088 |
ForwardIterator last, const T& value);
|
| 3089 |
|
| 3090 |
template<class ForwardIterator, class T, class Compare>
|
| 3091 |
-
pair<ForwardIterator, ForwardIterator>
|
| 3092 |
equal_range(ForwardIterator first,
|
| 3093 |
ForwardIterator last, const T& value,
|
| 3094 |
Compare comp);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3095 |
```
|
| 3096 |
|
| 3097 |
-
|
| 3098 |
-
|
| 3099 |
-
|
| 3100 |
-
|
| 3101 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3102 |
|
| 3103 |
*Returns:*
|
| 3104 |
|
|
|
|
| 3105 |
``` cpp
|
| 3106 |
-
|
| 3107 |
-
|
| 3108 |
```
|
| 3109 |
-
|
| 3110 |
-
or
|
| 3111 |
-
|
| 3112 |
``` cpp
|
| 3113 |
-
|
| 3114 |
-
|
| 3115 |
```
|
| 3116 |
|
| 3117 |
-
*Complexity:* At most 2 * log₂(`last - first`) + 𝑂(1) comparisons
|
|
|
|
| 3118 |
|
| 3119 |
#### `binary_search` <a id="binary.search">[[binary.search]]</a>
|
| 3120 |
|
| 3121 |
``` cpp
|
| 3122 |
template<class ForwardIterator, class T>
|
| 3123 |
-
|
|
|
|
| 3124 |
const T& value);
|
| 3125 |
|
| 3126 |
template<class ForwardIterator, class T, class Compare>
|
| 3127 |
-
|
|
|
|
| 3128 |
const T& value, Compare comp);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3129 |
```
|
| 3130 |
|
| 3131 |
-
|
| 3132 |
-
|
| 3133 |
-
`comp(e, value)` and `!comp(value, e)`. Also, for all elements `e` of
|
| 3134 |
-
`[first, last)`, `e < value` implies `!(value < e)` or `comp(e, value)`
|
| 3135 |
-
implies `!comp(value, e)`.
|
| 3136 |
|
| 3137 |
-
*
|
| 3138 |
-
|
| 3139 |
-
`
|
| 3140 |
-
`
|
|
|
|
|
|
|
| 3141 |
|
| 3142 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3143 |
|
| 3144 |
### Partitions <a id="alg.partitions">[[alg.partitions]]</a>
|
| 3145 |
|
| 3146 |
``` cpp
|
| 3147 |
template<class InputIterator, class Predicate>
|
| 3148 |
-
bool is_partitioned(InputIterator first, InputIterator last, Predicate pred);
|
| 3149 |
template<class ExecutionPolicy, class ForwardIterator, class Predicate>
|
| 3150 |
bool is_partitioned(ExecutionPolicy&& exec,
|
| 3151 |
ForwardIterator first, ForwardIterator last, Predicate pred);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3152 |
```
|
| 3153 |
|
| 3154 |
-
|
| 3155 |
-
`
|
| 3156 |
-
argument type. For the overload with an `ExecutionPolicy`,
|
| 3157 |
-
`ForwardIterator`’s value type shall be convertible to `Predicate`’s
|
| 3158 |
-
argument type.
|
| 3159 |
|
| 3160 |
-
*Returns:* `true` if
|
| 3161 |
-
|
| 3162 |
-
`pred
|
| 3163 |
|
| 3164 |
-
*Complexity:* Linear. At most `last - first` applications of `pred`
|
|
|
|
| 3165 |
|
| 3166 |
``` cpp
|
| 3167 |
template<class ForwardIterator, class Predicate>
|
| 3168 |
-
ForwardIterator
|
| 3169 |
partition(ForwardIterator first, ForwardIterator last, Predicate pred);
|
| 3170 |
template<class ExecutionPolicy, class ForwardIterator, class Predicate>
|
| 3171 |
ForwardIterator
|
| 3172 |
partition(ExecutionPolicy&& exec,
|
| 3173 |
ForwardIterator first, ForwardIterator last, Predicate pred);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3174 |
```
|
| 3175 |
|
| 3176 |
-
|
| 3177 |
-
`
|
| 3178 |
|
| 3179 |
-
*
|
| 3180 |
-
|
| 3181 |
|
| 3182 |
-
*
|
| 3183 |
-
|
| 3184 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3185 |
|
| 3186 |
*Complexity:* Let N = `last - first`:
|
| 3187 |
|
| 3188 |
- For the overload with no `ExecutionPolicy`, exactly N applications of
|
| 3189 |
-
the predicate. At most N / 2 swaps if
|
| 3190 |
-
`
|
|
|
|
|
|
|
| 3191 |
- For the overload with an `ExecutionPolicy`, 𝑂(N log N) swaps and 𝑂(N)
|
| 3192 |
applications of the predicate.
|
| 3193 |
|
| 3194 |
``` cpp
|
| 3195 |
template<class BidirectionalIterator, class Predicate>
|
| 3196 |
BidirectionalIterator
|
| 3197 |
-
stable_partition(BidirectionalIterator first, BidirectionalIterator last,
|
| 3198 |
-
Predicate pred);
|
| 3199 |
template<class ExecutionPolicy, class BidirectionalIterator, class Predicate>
|
| 3200 |
BidirectionalIterator
|
| 3201 |
stable_partition(ExecutionPolicy&& exec,
|
| 3202 |
-
BidirectionalIterator first, BidirectionalIterator last,
|
| 3203 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3204 |
```
|
| 3205 |
|
| 3206 |
-
|
| 3207 |
-
`
|
| 3208 |
-
|
| 3209 |
-
|
| 3210 |
-
|
| 3211 |
-
|
| 3212 |
-
*
|
| 3213 |
-
|
| 3214 |
-
|
| 3215 |
-
*
|
| 3216 |
-
|
| 3217 |
-
|
| 3218 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3219 |
|
| 3220 |
*Complexity:* Let N = `last - first`:
|
| 3221 |
|
| 3222 |
-
- For the
|
| 3223 |
-
only 𝑂(N) swaps if there is enough extra memory. Exactly N
|
| 3224 |
-
applications of the predicate.
|
| 3225 |
- For the overload with an `ExecutionPolicy`, 𝑂(N log N) swaps and 𝑂(N)
|
| 3226 |
applications of the predicate.
|
| 3227 |
|
| 3228 |
``` cpp
|
| 3229 |
template<class InputIterator, class OutputIterator1,
|
| 3230 |
class OutputIterator2, class Predicate>
|
| 3231 |
-
pair<OutputIterator1, OutputIterator2>
|
| 3232 |
partition_copy(InputIterator first, InputIterator last,
|
| 3233 |
-
OutputIterator1 out_true, OutputIterator2 out_false,
|
| 3234 |
-
Predicate pred);
|
| 3235 |
template<class ExecutionPolicy, class ForwardIterator, class ForwardIterator1,
|
| 3236 |
class ForwardIterator2, class Predicate>
|
| 3237 |
pair<ForwardIterator1, ForwardIterator2>
|
| 3238 |
partition_copy(ExecutionPolicy&& exec,
|
| 3239 |
ForwardIterator first, ForwardIterator last,
|
| 3240 |
-
ForwardIterator1 out_true, ForwardIterator2 out_false,
|
| 3241 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3242 |
```
|
| 3243 |
|
| 3244 |
-
|
|
|
|
| 3245 |
|
| 3246 |
-
|
| 3247 |
-
|
| 3248 |
-
|
| 3249 |
-
|
| 3250 |
-
|
| 3251 |
-
|
| 3252 |
-
|
| 3253 |
-
|
| 3254 |
-
|
| 3255 |
-
performance cost if `ForwardIterator`’s value type is not
|
| 3256 |
-
`CopyConstructible`. — *end note*]
|
| 3257 |
-
- For both overloads, the input range shall not overlap with either of
|
| 3258 |
-
the output ranges.
|
| 3259 |
|
| 3260 |
*Effects:* For each iterator `i` in \[`first`, `last`), copies `*i` to
|
| 3261 |
-
the output range beginning with `out_true` if
|
| 3262 |
-
|
| 3263 |
|
| 3264 |
-
*Returns:*
|
| 3265 |
-
|
| 3266 |
-
|
| 3267 |
|
| 3268 |
-
|
|
|
|
|
|
|
|
|
|
| 3269 |
|
| 3270 |
``` cpp
|
| 3271 |
template<class ForwardIterator, class Predicate>
|
| 3272 |
-
|
| 3273 |
-
|
| 3274 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3275 |
```
|
| 3276 |
|
| 3277 |
-
|
| 3278 |
-
`
|
| 3279 |
-
`pred`, i.e. all elements that satisfy `pred` shall appear before those
|
| 3280 |
-
that do not.
|
| 3281 |
|
| 3282 |
-
*
|
| 3283 |
-
|
| 3284 |
|
| 3285 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3286 |
|
| 3287 |
### Merge <a id="alg.merge">[[alg.merge]]</a>
|
| 3288 |
|
| 3289 |
``` cpp
|
| 3290 |
template<class InputIterator1, class InputIterator2,
|
| 3291 |
class OutputIterator>
|
| 3292 |
-
OutputIterator
|
| 3293 |
merge(InputIterator1 first1, InputIterator1 last1,
|
| 3294 |
InputIterator2 first2, InputIterator2 last2,
|
| 3295 |
OutputIterator result);
|
| 3296 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 3297 |
class ForwardIterator>
|
|
@@ -3301,43 +5922,67 @@ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
|
| 3301 |
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 3302 |
ForwardIterator result);
|
| 3303 |
|
| 3304 |
template<class InputIterator1, class InputIterator2,
|
| 3305 |
class OutputIterator, class Compare>
|
| 3306 |
-
OutputIterator
|
| 3307 |
merge(InputIterator1 first1, InputIterator1 last1,
|
| 3308 |
InputIterator2 first2, InputIterator2 last2,
|
| 3309 |
OutputIterator result, Compare comp);
|
| 3310 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 3311 |
class ForwardIterator, class Compare>
|
| 3312 |
ForwardIterator
|
| 3313 |
merge(ExecutionPolicy&& exec,
|
| 3314 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 3315 |
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 3316 |
ForwardIterator result, Compare comp);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3317 |
```
|
| 3318 |
|
| 3319 |
-
|
| 3320 |
-
|
| 3321 |
-
|
| 3322 |
|
| 3323 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3324 |
`last1`) and \[`first2`, `last2`) into the range \[`result`,
|
| 3325 |
-
`result_last`), where `result_last` is
|
| 3326 |
-
`
|
| 3327 |
-
|
| 3328 |
-
`
|
|
|
|
|
|
|
| 3329 |
|
| 3330 |
-
*Returns:*
|
| 3331 |
|
| 3332 |
-
|
|
|
|
| 3333 |
|
| 3334 |
-
|
| 3335 |
-
|
|
|
|
|
|
|
| 3336 |
- For the overloads with an `ExecutionPolicy`, 𝑂(N) comparisons.
|
| 3337 |
|
| 3338 |
-
*Remarks:* Stable
|
| 3339 |
|
| 3340 |
``` cpp
|
| 3341 |
template<class BidirectionalIterator>
|
| 3342 |
void inplace_merge(BidirectionalIterator first,
|
| 3343 |
BidirectionalIterator middle,
|
|
@@ -3355,81 +6000,124 @@ template<class BidirectionalIterator, class Compare>
|
|
| 3355 |
template<class ExecutionPolicy, class BidirectionalIterator, class Compare>
|
| 3356 |
void inplace_merge(ExecutionPolicy&& exec,
|
| 3357 |
BidirectionalIterator first,
|
| 3358 |
BidirectionalIterator middle,
|
| 3359 |
BidirectionalIterator last, Compare comp);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3360 |
```
|
| 3361 |
|
| 3362 |
-
|
| 3363 |
-
|
| 3364 |
-
|
| 3365 |
-
`
|
| 3366 |
-
|
| 3367 |
-
|
| 3368 |
-
|
|
|
|
|
|
|
| 3369 |
|
| 3370 |
*Effects:* Merges two sorted consecutive ranges \[`first`, `middle`) and
|
| 3371 |
\[`middle`, `last`), putting the result of the merge into the range
|
| 3372 |
-
\[`first`, `last`). The resulting range
|
| 3373 |
-
|
| 3374 |
-
|
| 3375 |
-
|
| 3376 |
|
| 3377 |
*Complexity:* Let N = `last - first`:
|
| 3378 |
|
| 3379 |
-
- For the overloads with no `ExecutionPolicy`, if enough additional
|
| 3380 |
memory is available, exactly N - 1 comparisons.
|
| 3381 |
-
-
|
| 3382 |
-
available, 𝑂(N log N) comparisons.
|
| 3383 |
-
- For the overloads with an `ExecutionPolicy`, 𝑂(N log N) comparisons.
|
| 3384 |
|
| 3385 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3386 |
|
| 3387 |
### Set operations on sorted structures <a id="alg.set.operations">[[alg.set.operations]]</a>
|
| 3388 |
|
| 3389 |
-
This
|
| 3390 |
-
They also work with `multiset`s
|
| 3391 |
-
copies of equivalent elements. The semantics of the set
|
| 3392 |
-
generalized to `multiset`s in a standard way by defining
|
| 3393 |
-
to contain the maximum number of occurrences of every
|
| 3394 |
-
`set_intersection
|
| 3395 |
|
| 3396 |
#### `includes` <a id="includes">[[includes]]</a>
|
| 3397 |
|
| 3398 |
``` cpp
|
| 3399 |
template<class InputIterator1, class InputIterator2>
|
| 3400 |
-
bool includes(InputIterator1 first1, InputIterator1 last1,
|
| 3401 |
InputIterator2 first2, InputIterator2 last2);
|
| 3402 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 3403 |
bool includes(ExecutionPolicy&& exec,
|
| 3404 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 3405 |
ForwardIterator2 first2, ForwardIterator2 last2);
|
| 3406 |
|
| 3407 |
template<class InputIterator1, class InputIterator2, class Compare>
|
| 3408 |
-
bool includes(InputIterator1 first1, InputIterator1 last1,
|
| 3409 |
InputIterator2 first2, InputIterator2 last2,
|
| 3410 |
Compare comp);
|
| 3411 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class Compare>
|
| 3412 |
bool includes(ExecutionPolicy&& exec,
|
| 3413 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 3414 |
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 3415 |
Compare comp);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3416 |
```
|
| 3417 |
|
| 3418 |
-
|
| 3419 |
-
|
| 3420 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3421 |
|
| 3422 |
*Complexity:* At most `2 * ((last1 - first1) + (last2 - first2)) - 1`
|
| 3423 |
-
comparisons.
|
| 3424 |
|
| 3425 |
#### `set_union` <a id="set.union">[[set.union]]</a>
|
| 3426 |
|
| 3427 |
``` cpp
|
| 3428 |
template<class InputIterator1, class InputIterator2,
|
| 3429 |
class OutputIterator>
|
| 3430 |
-
OutputIterator
|
| 3431 |
set_union(InputIterator1 first1, InputIterator1 last1,
|
| 3432 |
InputIterator2 first2, InputIterator2 last2,
|
| 3433 |
OutputIterator result);
|
| 3434 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 3435 |
class ForwardIterator>
|
|
@@ -3439,48 +6127,71 @@ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
|
| 3439 |
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 3440 |
ForwardIterator result);
|
| 3441 |
|
| 3442 |
template<class InputIterator1, class InputIterator2,
|
| 3443 |
class OutputIterator, class Compare>
|
| 3444 |
-
OutputIterator
|
| 3445 |
set_union(InputIterator1 first1, InputIterator1 last1,
|
| 3446 |
InputIterator2 first2, InputIterator2 last2,
|
| 3447 |
OutputIterator result, Compare comp);
|
| 3448 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 3449 |
class ForwardIterator, class Compare>
|
| 3450 |
ForwardIterator
|
| 3451 |
set_union(ExecutionPolicy&& exec,
|
| 3452 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 3453 |
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 3454 |
ForwardIterator result, Compare comp);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3455 |
```
|
| 3456 |
|
| 3457 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3458 |
original ranges.
|
| 3459 |
|
| 3460 |
*Effects:* Constructs a sorted union of the elements from the two
|
| 3461 |
ranges; that is, the set of elements that are present in one or both of
|
| 3462 |
the ranges.
|
| 3463 |
|
| 3464 |
-
*Returns:*
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3465 |
|
| 3466 |
*Complexity:* At most `2 * ((last1 - first1) + (last2 - first2)) - 1`
|
| 3467 |
-
comparisons.
|
| 3468 |
|
| 3469 |
-
*Remarks:* If \[`first1`, `last1`) contains
|
| 3470 |
-
equivalent to each other and \[`first2`, `last2`)
|
| 3471 |
-
that are equivalent to them, then all m elements
|
| 3472 |
-
|
| 3473 |
-
elements from the second range
|
| 3474 |
-
order.
|
| 3475 |
|
| 3476 |
#### `set_intersection` <a id="set.intersection">[[set.intersection]]</a>
|
| 3477 |
|
| 3478 |
``` cpp
|
| 3479 |
template<class InputIterator1, class InputIterator2,
|
| 3480 |
class OutputIterator>
|
| 3481 |
-
OutputIterator
|
| 3482 |
set_intersection(InputIterator1 first1, InputIterator1 last1,
|
| 3483 |
InputIterator2 first2, InputIterator2 last2,
|
| 3484 |
OutputIterator result);
|
| 3485 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 3486 |
class ForwardIterator>
|
|
@@ -3490,46 +6201,69 @@ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
|
| 3490 |
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 3491 |
ForwardIterator result);
|
| 3492 |
|
| 3493 |
template<class InputIterator1, class InputIterator2,
|
| 3494 |
class OutputIterator, class Compare>
|
| 3495 |
-
OutputIterator
|
| 3496 |
set_intersection(InputIterator1 first1, InputIterator1 last1,
|
| 3497 |
InputIterator2 first2, InputIterator2 last2,
|
| 3498 |
OutputIterator result, Compare comp);
|
| 3499 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 3500 |
class ForwardIterator, class Compare>
|
| 3501 |
ForwardIterator
|
| 3502 |
set_intersection(ExecutionPolicy&& exec,
|
| 3503 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 3504 |
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 3505 |
ForwardIterator result, Compare comp);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3506 |
```
|
| 3507 |
|
| 3508 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3509 |
original ranges.
|
| 3510 |
|
| 3511 |
*Effects:* Constructs a sorted intersection of the elements from the two
|
| 3512 |
ranges; that is, the set of elements that are present in both of the
|
| 3513 |
ranges.
|
| 3514 |
|
| 3515 |
-
*Returns:*
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3516 |
|
| 3517 |
*Complexity:* At most `2 * ((last1 - first1) + (last2 - first2)) - 1`
|
| 3518 |
-
comparisons.
|
| 3519 |
|
| 3520 |
-
*Remarks:* If \[`first1`, `last1`) contains
|
| 3521 |
-
equivalent to each other and \[`first2`, `last2`)
|
| 3522 |
-
that are equivalent to them, the first min(m, n)
|
| 3523 |
-
copied from the first range to the output range, in order.
|
| 3524 |
|
| 3525 |
#### `set_difference` <a id="set.difference">[[set.difference]]</a>
|
| 3526 |
|
| 3527 |
``` cpp
|
| 3528 |
template<class InputIterator1, class InputIterator2,
|
| 3529 |
class OutputIterator>
|
| 3530 |
-
OutputIterator
|
| 3531 |
set_difference(InputIterator1 first1, InputIterator1 last1,
|
| 3532 |
InputIterator2 first2, InputIterator2 last2,
|
| 3533 |
OutputIterator result);
|
| 3534 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 3535 |
class ForwardIterator>
|
|
@@ -3539,46 +6273,69 @@ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
|
| 3539 |
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 3540 |
ForwardIterator result);
|
| 3541 |
|
| 3542 |
template<class InputIterator1, class InputIterator2,
|
| 3543 |
class OutputIterator, class Compare>
|
| 3544 |
-
OutputIterator
|
| 3545 |
set_difference(InputIterator1 first1, InputIterator1 last1,
|
| 3546 |
InputIterator2 first2, InputIterator2 last2,
|
| 3547 |
OutputIterator result, Compare comp);
|
| 3548 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 3549 |
class ForwardIterator, class Compare>
|
| 3550 |
ForwardIterator
|
| 3551 |
set_difference(ExecutionPolicy&& exec,
|
| 3552 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 3553 |
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 3554 |
ForwardIterator result, Compare comp);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3555 |
```
|
| 3556 |
|
| 3557 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3558 |
original ranges.
|
| 3559 |
|
| 3560 |
*Effects:* Copies the elements of the range \[`first1`, `last1`) which
|
| 3561 |
are not present in the range \[`first2`, `last2`) to the range beginning
|
| 3562 |
at `result`. The elements in the constructed range are sorted.
|
| 3563 |
|
| 3564 |
-
*Returns:*
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3565 |
|
| 3566 |
*Complexity:* At most `2 * ((last1 - first1) + (last2 - first2)) - 1`
|
| 3567 |
-
comparisons.
|
| 3568 |
|
| 3569 |
*Remarks:* If \[`first1`, `last1`) contains m elements that are
|
| 3570 |
equivalent to each other and \[`first2`, `last2`) contains n elements
|
| 3571 |
that are equivalent to them, the last max(m - n, 0) elements from
|
| 3572 |
-
\[`first1`, `last1`)
|
| 3573 |
|
| 3574 |
#### `set_symmetric_difference` <a id="set.symmetric.difference">[[set.symmetric.difference]]</a>
|
| 3575 |
|
| 3576 |
``` cpp
|
| 3577 |
template<class InputIterator1, class InputIterator2,
|
| 3578 |
class OutputIterator>
|
| 3579 |
-
OutputIterator
|
| 3580 |
set_symmetric_difference(InputIterator1 first1, InputIterator1 last1,
|
| 3581 |
InputIterator2 first2, InputIterator2 last2,
|
| 3582 |
OutputIterator result);
|
| 3583 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 3584 |
class ForwardIterator>
|
|
@@ -3588,308 +6345,497 @@ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
|
| 3588 |
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 3589 |
ForwardIterator result);
|
| 3590 |
|
| 3591 |
template<class InputIterator1, class InputIterator2,
|
| 3592 |
class OutputIterator, class Compare>
|
| 3593 |
-
OutputIterator
|
| 3594 |
set_symmetric_difference(InputIterator1 first1, InputIterator1 last1,
|
| 3595 |
InputIterator2 first2, InputIterator2 last2,
|
| 3596 |
OutputIterator result, Compare comp);
|
| 3597 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 3598 |
class ForwardIterator, class Compare>
|
| 3599 |
ForwardIterator
|
| 3600 |
set_symmetric_difference(ExecutionPolicy&& exec,
|
| 3601 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 3602 |
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 3603 |
ForwardIterator result, Compare comp);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3604 |
```
|
| 3605 |
|
| 3606 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3607 |
original ranges.
|
| 3608 |
|
| 3609 |
*Effects:* Copies the elements of the range \[`first1`, `last1`) that
|
| 3610 |
are not present in the range \[`first2`, `last2`), and the elements of
|
| 3611 |
the range \[`first2`, `last2`) that are not present in the range
|
| 3612 |
\[`first1`, `last1`) to the range beginning at `result`. The elements in
|
| 3613 |
the constructed range are sorted.
|
| 3614 |
|
| 3615 |
-
*Returns:*
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3616 |
|
| 3617 |
*Complexity:* At most `2 * ((last1 - first1) + (last2 - first2)) - 1`
|
| 3618 |
-
comparisons.
|
| 3619 |
|
| 3620 |
-
*Remarks:* If \[`first1`, `last1`) contains
|
| 3621 |
-
equivalent to each other and \[`first2`, `last2`)
|
| 3622 |
-
that are equivalent to them, then |m - n| of those
|
| 3623 |
-
copied to the output range: the last m - n of these
|
| 3624 |
-
\[`first1`, `last1`) if m > n, and the last n - m of these
|
| 3625 |
-
\[`first2`, `last2`) if m < n.
|
|
|
|
| 3626 |
|
| 3627 |
### Heap operations <a id="alg.heap.operations">[[alg.heap.operations]]</a>
|
| 3628 |
|
| 3629 |
-
A
|
| 3630 |
-
|
|
|
|
| 3631 |
|
| 3632 |
- With `N = b - a`, for all i, 0 < i < N,
|
| 3633 |
-
`comp(a[\left \lfloor{\frac{i - 1}{2}}\right \rfloor], a[i])`
|
| 3634 |
-
`false`.
|
| 3635 |
-
- `*a` may be removed by `pop_heap
|
| 3636 |
-
`push_heap
|
| 3637 |
|
| 3638 |
These properties make heaps useful as priority queues.
|
| 3639 |
|
| 3640 |
-
`make_heap
|
| 3641 |
-
|
| 3642 |
-
converts a range into a heap and `sort_heap()` turns a heap into a
|
| 3643 |
-
sorted sequence.
|
| 3644 |
|
| 3645 |
#### `push_heap` <a id="push.heap">[[push.heap]]</a>
|
| 3646 |
|
| 3647 |
``` cpp
|
| 3648 |
template<class RandomAccessIterator>
|
| 3649 |
-
void push_heap(RandomAccessIterator first, RandomAccessIterator last);
|
| 3650 |
|
| 3651 |
template<class RandomAccessIterator, class Compare>
|
| 3652 |
-
void push_heap(RandomAccessIterator first, RandomAccessIterator last,
|
| 3653 |
Compare comp);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3654 |
```
|
| 3655 |
|
| 3656 |
-
|
| 3657 |
-
|
| 3658 |
-
|
| 3659 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3660 |
|
| 3661 |
*Effects:* Places the value in the location `last - 1` into the
|
| 3662 |
resulting heap \[`first`, `last`).
|
| 3663 |
|
| 3664 |
-
*
|
|
|
|
|
|
|
|
|
|
| 3665 |
|
| 3666 |
#### `pop_heap` <a id="pop.heap">[[pop.heap]]</a>
|
| 3667 |
|
| 3668 |
``` cpp
|
| 3669 |
template<class RandomAccessIterator>
|
| 3670 |
-
void pop_heap(RandomAccessIterator first, RandomAccessIterator last);
|
| 3671 |
|
| 3672 |
template<class RandomAccessIterator, class Compare>
|
| 3673 |
-
void pop_heap(RandomAccessIterator first, RandomAccessIterator last,
|
| 3674 |
Compare comp);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3675 |
```
|
| 3676 |
|
| 3677 |
-
|
| 3678 |
-
|
| 3679 |
-
|
| 3680 |
-
|
| 3681 |
-
|
| 3682 |
-
|
|
|
|
|
|
|
|
|
|
| 3683 |
|
| 3684 |
*Effects:* Swaps the value in the location `first` with the value in the
|
| 3685 |
-
location `last - 1` and makes \[`first`, `last - 1`) into a heap
|
|
|
|
| 3686 |
|
| 3687 |
-
*
|
|
|
|
|
|
|
|
|
|
| 3688 |
|
| 3689 |
#### `make_heap` <a id="make.heap">[[make.heap]]</a>
|
| 3690 |
|
| 3691 |
``` cpp
|
| 3692 |
template<class RandomAccessIterator>
|
| 3693 |
-
void make_heap(RandomAccessIterator first, RandomAccessIterator last);
|
| 3694 |
|
| 3695 |
template<class RandomAccessIterator, class Compare>
|
| 3696 |
-
void make_heap(RandomAccessIterator first, RandomAccessIterator last,
|
| 3697 |
Compare comp);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3698 |
```
|
| 3699 |
|
| 3700 |
-
|
| 3701 |
-
|
| 3702 |
-
requirements (Table [[tab:moveassignable]]).
|
| 3703 |
|
| 3704 |
-
*
|
|
|
|
|
|
|
|
|
|
| 3705 |
|
| 3706 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3707 |
|
| 3708 |
#### `sort_heap` <a id="sort.heap">[[sort.heap]]</a>
|
| 3709 |
|
| 3710 |
``` cpp
|
| 3711 |
template<class RandomAccessIterator>
|
| 3712 |
-
void sort_heap(RandomAccessIterator first, RandomAccessIterator last);
|
| 3713 |
|
| 3714 |
template<class RandomAccessIterator, class Compare>
|
| 3715 |
-
void sort_heap(RandomAccessIterator first, RandomAccessIterator last,
|
| 3716 |
Compare comp);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3717 |
```
|
| 3718 |
|
| 3719 |
-
|
| 3720 |
-
|
| 3721 |
-
`ValueSwappable` ([[swappable.requirements]]). The type of `*first`
|
| 3722 |
-
shall satisfy the requirements of `MoveConstructible`
|
| 3723 |
-
(Table [[tab:moveconstructible]]) and of `MoveAssignable`
|
| 3724 |
-
(Table [[tab:moveassignable]]).
|
| 3725 |
|
| 3726 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3727 |
|
| 3728 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3729 |
|
| 3730 |
#### `is_heap` <a id="is.heap">[[is.heap]]</a>
|
| 3731 |
|
| 3732 |
``` cpp
|
| 3733 |
template<class RandomAccessIterator>
|
| 3734 |
-
bool is_heap(RandomAccessIterator first, RandomAccessIterator last);
|
| 3735 |
```
|
| 3736 |
|
| 3737 |
-
*
|
| 3738 |
|
| 3739 |
``` cpp
|
| 3740 |
template<class ExecutionPolicy, class RandomAccessIterator>
|
| 3741 |
bool is_heap(ExecutionPolicy&& exec,
|
| 3742 |
RandomAccessIterator first, RandomAccessIterator last);
|
| 3743 |
```
|
| 3744 |
|
| 3745 |
-
*
|
| 3746 |
-
|
|
|
|
|
|
|
|
|
|
| 3747 |
|
| 3748 |
``` cpp
|
| 3749 |
template<class RandomAccessIterator, class Compare>
|
| 3750 |
-
bool is_heap(RandomAccessIterator first, RandomAccessIterator last,
|
|
|
|
| 3751 |
```
|
| 3752 |
|
| 3753 |
-
*
|
|
|
|
| 3754 |
|
| 3755 |
``` cpp
|
| 3756 |
template<class ExecutionPolicy, class RandomAccessIterator, class Compare>
|
| 3757 |
bool is_heap(ExecutionPolicy&& exec,
|
| 3758 |
-
RandomAccessIterator first, RandomAccessIterator last,
|
|
|
|
| 3759 |
```
|
| 3760 |
|
| 3761 |
-
*
|
| 3762 |
|
| 3763 |
``` cpp
|
| 3764 |
-
is_heap_until(std::forward<ExecutionPolicy>(exec), first, last, comp) == last
|
| 3765 |
```
|
| 3766 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3767 |
``` cpp
|
| 3768 |
template<class RandomAccessIterator>
|
| 3769 |
-
|
|
|
|
| 3770 |
template<class ExecutionPolicy, class RandomAccessIterator>
|
| 3771 |
-
RandomAccessIterator
|
|
|
|
| 3772 |
RandomAccessIterator first, RandomAccessIterator last);
|
| 3773 |
|
| 3774 |
template<class RandomAccessIterator, class Compare>
|
| 3775 |
-
|
|
|
|
| 3776 |
Compare comp);
|
| 3777 |
template<class ExecutionPolicy, class RandomAccessIterator, class Compare>
|
| 3778 |
-
RandomAccessIterator
|
|
|
|
| 3779 |
RandomAccessIterator first, RandomAccessIterator last,
|
| 3780 |
Compare comp);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3781 |
```
|
| 3782 |
|
| 3783 |
-
|
| 3784 |
-
|
| 3785 |
-
|
|
|
|
|
|
|
| 3786 |
|
| 3787 |
*Complexity:* Linear.
|
| 3788 |
|
| 3789 |
### Minimum and maximum <a id="alg.min.max">[[alg.min.max]]</a>
|
| 3790 |
|
| 3791 |
``` cpp
|
| 3792 |
-
template<class T>
|
|
|
|
| 3793 |
template<class T, class Compare>
|
| 3794 |
constexpr const T& min(const T& a, const T& b, Compare comp);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3795 |
```
|
| 3796 |
|
| 3797 |
-
*
|
| 3798 |
-
(
|
| 3799 |
|
| 3800 |
*Returns:* The smaller value.
|
| 3801 |
|
| 3802 |
*Remarks:* Returns the first argument when the arguments are equivalent.
|
|
|
|
|
|
|
| 3803 |
|
| 3804 |
-
*Complexity:* Exactly one comparison
|
|
|
|
| 3805 |
|
| 3806 |
``` cpp
|
| 3807 |
template<class T>
|
| 3808 |
-
constexpr T min(initializer_list<T>
|
| 3809 |
template<class T, class Compare>
|
| 3810 |
-
constexpr T min(initializer_list<T>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3811 |
```
|
| 3812 |
|
| 3813 |
-
*
|
| 3814 |
-
|
|
|
|
|
|
|
| 3815 |
|
| 3816 |
-
*Returns:* The smallest value in the
|
| 3817 |
|
| 3818 |
-
*Remarks:* Returns a copy of the leftmost
|
| 3819 |
-
|
|
|
|
|
|
|
| 3820 |
|
| 3821 |
-
*Complexity:* Exactly `
|
|
|
|
| 3822 |
|
| 3823 |
``` cpp
|
| 3824 |
-
template<class T>
|
|
|
|
| 3825 |
template<class T, class Compare>
|
| 3826 |
constexpr const T& max(const T& a, const T& b, Compare comp);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3827 |
```
|
| 3828 |
|
| 3829 |
-
*
|
| 3830 |
-
(
|
| 3831 |
|
| 3832 |
*Returns:* The larger value.
|
| 3833 |
|
| 3834 |
*Remarks:* Returns the first argument when the arguments are equivalent.
|
|
|
|
|
|
|
| 3835 |
|
| 3836 |
-
*Complexity:* Exactly one comparison
|
|
|
|
| 3837 |
|
| 3838 |
``` cpp
|
| 3839 |
template<class T>
|
| 3840 |
-
constexpr T max(initializer_list<T>
|
| 3841 |
template<class T, class Compare>
|
| 3842 |
-
constexpr T max(initializer_list<T>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3843 |
```
|
| 3844 |
|
| 3845 |
-
*
|
| 3846 |
-
|
|
|
|
|
|
|
| 3847 |
|
| 3848 |
-
*Returns:* The largest value in the
|
| 3849 |
|
| 3850 |
-
*Remarks:* Returns a copy of the leftmost
|
| 3851 |
-
|
|
|
|
|
|
|
| 3852 |
|
| 3853 |
-
*Complexity:* Exactly `
|
|
|
|
| 3854 |
|
| 3855 |
``` cpp
|
| 3856 |
-
template<class T>
|
|
|
|
| 3857 |
template<class T, class Compare>
|
| 3858 |
constexpr pair<const T&, const T&> minmax(const T& a, const T& b, Compare comp);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3859 |
```
|
| 3860 |
|
| 3861 |
-
*
|
| 3862 |
-
(
|
| 3863 |
|
| 3864 |
-
*Returns:* `
|
| 3865 |
-
and `pair<const T&, const T&>(a, b)` otherwise.
|
| 3866 |
|
| 3867 |
-
*Remarks:*
|
| 3868 |
-
|
| 3869 |
|
| 3870 |
-
*Complexity:* Exactly one comparison
|
|
|
|
| 3871 |
|
| 3872 |
``` cpp
|
| 3873 |
template<class T>
|
| 3874 |
constexpr pair<T, T> minmax(initializer_list<T> t);
|
| 3875 |
template<class T, class Compare>
|
| 3876 |
constexpr pair<T, T> minmax(initializer_list<T> t, Compare comp);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3877 |
```
|
| 3878 |
|
| 3879 |
-
*
|
| 3880 |
-
|
|
|
|
|
|
|
| 3881 |
|
| 3882 |
-
*Returns:* `
|
| 3883 |
-
the
|
|
|
|
| 3884 |
|
| 3885 |
-
*Remarks:*
|
| 3886 |
-
|
| 3887 |
-
when several arguments are equivalent to the largest.
|
| 3888 |
|
| 3889 |
-
*Complexity:* At most (3/2)`
|
| 3890 |
-
predicate
|
|
|
|
| 3891 |
|
| 3892 |
``` cpp
|
| 3893 |
template<class ForwardIterator>
|
| 3894 |
constexpr ForwardIterator min_element(ForwardIterator first, ForwardIterator last);
|
| 3895 |
|
|
@@ -3902,19 +6848,34 @@ template<class ForwardIterator, class Compare>
|
|
| 3902 |
Compare comp);
|
| 3903 |
template<class ExecutionPolicy, class ForwardIterator, class Compare>
|
| 3904 |
ForwardIterator min_element(ExecutionPolicy&& exec,
|
| 3905 |
ForwardIterator first, ForwardIterator last,
|
| 3906 |
Compare comp);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3907 |
```
|
| 3908 |
|
|
|
|
|
|
|
|
|
|
| 3909 |
*Returns:* The first iterator `i` in the range \[`first`, `last`) such
|
| 3910 |
-
that for every iterator `j` in the range \[`first`, `last`)
|
| 3911 |
-
following corresponding conditions hold: `!(*j < *i)` or
|
| 3912 |
-
`comp(*j, *i) == false`. Returns `last` if `first == last`.
|
| 3913 |
|
| 3914 |
-
|
| 3915 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3916 |
|
| 3917 |
``` cpp
|
| 3918 |
template<class ForwardIterator>
|
| 3919 |
constexpr ForwardIterator max_element(ForwardIterator first, ForwardIterator last);
|
| 3920 |
template<class ExecutionPolicy, class ForwardIterator>
|
|
@@ -3926,19 +6887,34 @@ template<class ForwardIterator, class Compare>
|
|
| 3926 |
Compare comp);
|
| 3927 |
template<class ExecutionPolicy, class ForwardIterator, class Compare>
|
| 3928 |
ForwardIterator max_element(ExecutionPolicy&& exec,
|
| 3929 |
ForwardIterator first, ForwardIterator last,
|
| 3930 |
Compare comp);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3931 |
```
|
| 3932 |
|
|
|
|
|
|
|
|
|
|
| 3933 |
*Returns:* The first iterator `i` in the range \[`first`, `last`) such
|
| 3934 |
-
that for every iterator `j` in the range \[`first`, `last`)
|
| 3935 |
-
following corresponding conditions hold: `!(*i < *j)` or
|
| 3936 |
-
`comp(*i, *j) == false`. Returns `last` if `first == last`.
|
| 3937 |
|
| 3938 |
-
|
| 3939 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3940 |
|
| 3941 |
``` cpp
|
| 3942 |
template<class ForwardIterator>
|
| 3943 |
constexpr pair<ForwardIterator, ForwardIterator>
|
| 3944 |
minmax_element(ForwardIterator first, ForwardIterator last);
|
|
@@ -3952,156 +6928,1828 @@ template<class ForwardIterator, class Compare>
|
|
| 3952 |
minmax_element(ForwardIterator first, ForwardIterator last, Compare comp);
|
| 3953 |
template<class ExecutionPolicy, class ForwardIterator, class Compare>
|
| 3954 |
pair<ForwardIterator, ForwardIterator>
|
| 3955 |
minmax_element(ExecutionPolicy&& exec,
|
| 3956 |
ForwardIterator first, ForwardIterator last, Compare comp);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3957 |
```
|
| 3958 |
|
| 3959 |
-
*Returns:* `
|
| 3960 |
-
|
| 3961 |
-
|
| 3962 |
-
|
| 3963 |
-
|
| 3964 |
|
| 3965 |
-
*Complexity:* At most
|
| 3966 |
-
$\max(\bigl\lfloor{\frac{3}{2}} (N-1)\bigr\rfloor, 0)$
|
| 3967 |
-
|
| 3968 |
|
| 3969 |
### Bounded value <a id="alg.clamp">[[alg.clamp]]</a>
|
| 3970 |
|
| 3971 |
``` cpp
|
| 3972 |
template<class T>
|
| 3973 |
constexpr const T& clamp(const T& v, const T& lo, const T& hi);
|
| 3974 |
template<class T, class Compare>
|
| 3975 |
constexpr const T& clamp(const T& v, const T& lo, const T& hi, Compare comp);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3976 |
```
|
| 3977 |
|
| 3978 |
-
|
| 3979 |
-
|
| 3980 |
-
(Table [[tab:lessthancomparable]]).
|
| 3981 |
|
| 3982 |
-
*
|
| 3983 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3984 |
|
| 3985 |
[*Note 1*: If NaN is avoided, `T` can be a floating-point
|
| 3986 |
type. — *end note*]
|
| 3987 |
|
| 3988 |
-
*Complexity:* At most two comparisons
|
|
|
|
| 3989 |
|
| 3990 |
### Lexicographical comparison <a id="alg.lex.comparison">[[alg.lex.comparison]]</a>
|
| 3991 |
|
| 3992 |
``` cpp
|
| 3993 |
template<class InputIterator1, class InputIterator2>
|
| 3994 |
-
bool
|
| 3995 |
lexicographical_compare(InputIterator1 first1, InputIterator1 last1,
|
| 3996 |
InputIterator2 first2, InputIterator2 last2);
|
| 3997 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 3998 |
bool
|
| 3999 |
lexicographical_compare(ExecutionPolicy&& exec,
|
| 4000 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 4001 |
ForwardIterator2 first2, ForwardIterator2 last2);
|
| 4002 |
|
| 4003 |
template<class InputIterator1, class InputIterator2, class Compare>
|
| 4004 |
-
bool
|
| 4005 |
lexicographical_compare(InputIterator1 first1, InputIterator1 last1,
|
| 4006 |
InputIterator2 first2, InputIterator2 last2,
|
| 4007 |
Compare comp);
|
| 4008 |
-
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
|
|
|
| 4009 |
bool
|
| 4010 |
lexicographical_compare(ExecutionPolicy&& exec,
|
| 4011 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 4012 |
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 4013 |
Compare comp);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4014 |
```
|
| 4015 |
|
| 4016 |
-
*Returns:* `true` if the sequence of elements defined by the
|
| 4017 |
-
\[`first1`, `last1`) is lexicographically less than the sequence
|
| 4018 |
-
elements defined by the range \[`first2`, `last2`)
|
| 4019 |
-
otherwise.
|
| 4020 |
|
| 4021 |
*Complexity:* At most 2 min(`last1 - first1`, `last2 - first2`)
|
| 4022 |
-
applications of the corresponding comparison
|
|
|
|
| 4023 |
|
| 4024 |
*Remarks:* If two sequences have the same number of elements and their
|
| 4025 |
corresponding elements (if any) are equivalent, then neither sequence is
|
| 4026 |
-
lexicographically less than the other. If one sequence is a
|
| 4027 |
-
the other, then the shorter sequence is lexicographically less
|
| 4028 |
-
longer sequence. Otherwise, the lexicographical comparison of
|
| 4029 |
-
sequences yields the same result as the comparison of the first
|
| 4030 |
corresponding pair of elements that are not equivalent.
|
| 4031 |
|
| 4032 |
[*Example 1*:
|
| 4033 |
|
| 4034 |
-
|
|
|
|
| 4035 |
|
| 4036 |
``` cpp
|
| 4037 |
for ( ; first1 != last1 && first2 != last2 ; ++first1, (void) ++first2) {
|
| 4038 |
-
if (*first1
|
| 4039 |
-
if (*first2
|
| 4040 |
}
|
| 4041 |
return first1 == last1 && first2 != last2;
|
| 4042 |
```
|
| 4043 |
|
| 4044 |
— *end example*]
|
| 4045 |
|
| 4046 |
[*Note 1*: An empty sequence is lexicographically less than any
|
| 4047 |
non-empty sequence, but not less than any empty sequence. — *end note*]
|
| 4048 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4049 |
### Permutation generators <a id="alg.permutation.generators">[[alg.permutation.generators]]</a>
|
| 4050 |
|
| 4051 |
``` cpp
|
| 4052 |
template<class BidirectionalIterator>
|
| 4053 |
-
bool next_permutation(BidirectionalIterator first,
|
| 4054 |
BidirectionalIterator last);
|
| 4055 |
|
| 4056 |
template<class BidirectionalIterator, class Compare>
|
| 4057 |
-
bool next_permutation(BidirectionalIterator first,
|
| 4058 |
BidirectionalIterator last, Compare comp);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4059 |
```
|
| 4060 |
|
| 4061 |
-
|
| 4062 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4063 |
|
| 4064 |
*Effects:* Takes a sequence defined by the range \[`first`, `last`) and
|
| 4065 |
transforms it into the next permutation. The next permutation is found
|
| 4066 |
by assuming that the set of all permutations is lexicographically sorted
|
| 4067 |
-
with respect to `
|
|
|
|
|
|
|
| 4068 |
|
| 4069 |
-
*Returns:* `true` if
|
| 4070 |
-
|
| 4071 |
-
|
|
|
|
|
|
|
| 4072 |
|
| 4073 |
*Complexity:* At most `(last - first) / 2` swaps.
|
| 4074 |
|
| 4075 |
``` cpp
|
| 4076 |
template<class BidirectionalIterator>
|
| 4077 |
-
bool prev_permutation(BidirectionalIterator first,
|
| 4078 |
BidirectionalIterator last);
|
| 4079 |
|
| 4080 |
template<class BidirectionalIterator, class Compare>
|
| 4081 |
-
bool prev_permutation(BidirectionalIterator first,
|
| 4082 |
BidirectionalIterator last, Compare comp);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4083 |
```
|
| 4084 |
|
| 4085 |
-
|
| 4086 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4087 |
|
| 4088 |
*Effects:* Takes a sequence defined by the range \[`first`, `last`) and
|
| 4089 |
transforms it into the previous permutation. The previous permutation is
|
| 4090 |
found by assuming that the set of all permutations is lexicographically
|
| 4091 |
-
sorted with respect to `
|
|
|
|
|
|
|
| 4092 |
|
| 4093 |
-
*Returns:* `true` if
|
| 4094 |
-
|
| 4095 |
-
|
|
|
|
|
|
|
| 4096 |
|
| 4097 |
*Complexity:* At most `(last - first) / 2` swaps.
|
| 4098 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4099 |
## C library algorithms <a id="alg.c.library">[[alg.c.library]]</a>
|
| 4100 |
|
| 4101 |
-
[*Note 1*: The header `<cstdlib>`
|
| 4102 |
-
|
| 4103 |
|
| 4104 |
``` cpp
|
| 4105 |
void* bsearch(const void* key, const void* base, size_t nmemb, size_t size,
|
| 4106 |
c-compare-pred* compar);
|
| 4107 |
void* bsearch(const void* key, const void* base, size_t nmemb, size_t size,
|
|
@@ -4111,22 +8759,24 @@ void qsort(void* base, size_t nmemb, size_t size, compare-pred* compar);
|
|
| 4111 |
```
|
| 4112 |
|
| 4113 |
*Effects:* These functions have the semantics specified in the C
|
| 4114 |
standard library.
|
| 4115 |
|
| 4116 |
-
*
|
| 4117 |
-
|
| 4118 |
|
| 4119 |
-
*Throws:* Any exception thrown by
|
| 4120 |
-
|
| 4121 |
|
| 4122 |
ISO C 7.22.5.
|
| 4123 |
|
| 4124 |
<!-- Link reference definitions -->
|
|
|
|
|
|
|
| 4125 |
[alg.adjacent.find]: #alg.adjacent.find
|
| 4126 |
-
[alg.
|
| 4127 |
-
[alg.
|
| 4128 |
[alg.binary.search]: #alg.binary.search
|
| 4129 |
[alg.c.library]: #alg.c.library
|
| 4130 |
[alg.clamp]: #alg.clamp
|
| 4131 |
[alg.copy]: #alg.copy
|
| 4132 |
[alg.count]: #alg.count
|
|
@@ -4136,17 +8786,17 @@ ISO C 7.22.5.
|
|
| 4136 |
[alg.find.end]: #alg.find.end
|
| 4137 |
[alg.find.first.of]: #alg.find.first.of
|
| 4138 |
[alg.foreach]: #alg.foreach
|
| 4139 |
[alg.generate]: #alg.generate
|
| 4140 |
[alg.heap.operations]: #alg.heap.operations
|
| 4141 |
-
[alg.
|
| 4142 |
[alg.lex.comparison]: #alg.lex.comparison
|
| 4143 |
[alg.merge]: #alg.merge
|
| 4144 |
[alg.min.max]: #alg.min.max
|
| 4145 |
[alg.modifying.operations]: #alg.modifying.operations
|
| 4146 |
[alg.move]: #alg.move
|
| 4147 |
-
[alg.
|
| 4148 |
[alg.nonmodifying]: #alg.nonmodifying
|
| 4149 |
[alg.nth.element]: #alg.nth.element
|
| 4150 |
[alg.partitions]: #alg.partitions
|
| 4151 |
[alg.permutation.generators]: #alg.permutation.generators
|
| 4152 |
[alg.random.sample]: #alg.random.sample
|
|
@@ -4155,13 +8805,15 @@ ISO C 7.22.5.
|
|
| 4155 |
[alg.replace]: #alg.replace
|
| 4156 |
[alg.reverse]: #alg.reverse
|
| 4157 |
[alg.rotate]: #alg.rotate
|
| 4158 |
[alg.search]: #alg.search
|
| 4159 |
[alg.set.operations]: #alg.set.operations
|
|
|
|
| 4160 |
[alg.sort]: #alg.sort
|
| 4161 |
[alg.sorting]: #alg.sorting
|
| 4162 |
[alg.swap]: #alg.swap
|
|
|
|
| 4163 |
[alg.transform]: #alg.transform
|
| 4164 |
[alg.unique]: #alg.unique
|
| 4165 |
[algorithm.stable]: library.md#algorithm.stable
|
| 4166 |
[algorithm.syn]: #algorithm.syn
|
| 4167 |
[algorithms]: #algorithms
|
|
@@ -4171,70 +8823,120 @@ ISO C 7.22.5.
|
|
| 4171 |
[algorithms.parallel.exceptions]: #algorithms.parallel.exceptions
|
| 4172 |
[algorithms.parallel.exec]: #algorithms.parallel.exec
|
| 4173 |
[algorithms.parallel.overloads]: #algorithms.parallel.overloads
|
| 4174 |
[algorithms.parallel.user]: #algorithms.parallel.user
|
| 4175 |
[algorithms.requirements]: #algorithms.requirements
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4176 |
[bidirectional.iterators]: iterators.md#bidirectional.iterators
|
| 4177 |
[binary.search]: #binary.search
|
| 4178 |
-
[class.conv]:
|
| 4179 |
[containers]: containers.md#containers
|
| 4180 |
-
[conv]:
|
| 4181 |
-
[conv.integral]:
|
| 4182 |
-
[
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4183 |
[equal.range]: #equal.range
|
|
|
|
| 4184 |
[execpol]: utilities.md#execpol
|
|
|
|
|
|
|
| 4185 |
[forward.iterators]: iterators.md#forward.iterators
|
| 4186 |
[function.objects]: utilities.md#function.objects
|
| 4187 |
[includes]: #includes
|
|
|
|
|
|
|
| 4188 |
[input.iterators]: iterators.md#input.iterators
|
| 4189 |
-
[intro.execution]:
|
| 4190 |
-
[intro.
|
|
|
|
| 4191 |
[is.heap]: #is.heap
|
| 4192 |
[is.sorted]: #is.sorted
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4193 |
[iterator.requirements]: iterators.md#iterator.requirements
|
| 4194 |
[iterator.requirements.general]: iterators.md#iterator.requirements.general
|
| 4195 |
[lower.bound]: #lower.bound
|
| 4196 |
[make.heap]: #make.heap
|
| 4197 |
[mismatch]: #mismatch
|
| 4198 |
[multiset]: containers.md#multiset
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4199 |
[output.iterators]: iterators.md#output.iterators
|
| 4200 |
[partial.sort]: #partial.sort
|
| 4201 |
[partial.sort.copy]: #partial.sort.copy
|
|
|
|
| 4202 |
[pop.heap]: #pop.heap
|
| 4203 |
[push.heap]: #push.heap
|
| 4204 |
[rand.req.urng]: numerics.md#rand.req.urng
|
| 4205 |
[random.access.iterators]: iterators.md#random.access.iterators
|
|
|
|
|
|
|
| 4206 |
[refwrap]: utilities.md#refwrap
|
| 4207 |
[res.on.exception.handling]: library.md#res.on.exception.handling
|
| 4208 |
[set.difference]: #set.difference
|
| 4209 |
[set.intersection]: #set.intersection
|
| 4210 |
[set.symmetric.difference]: #set.symmetric.difference
|
| 4211 |
[set.union]: #set.union
|
| 4212 |
[sort]: #sort
|
| 4213 |
[sort.heap]: #sort.heap
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4214 |
[stable.sort]: #stable.sort
|
| 4215 |
[swappable.requirements]: library.md#swappable.requirements
|
| 4216 |
-
[
|
| 4217 |
-
[
|
| 4218 |
-
[tab:copyconstructible]: #tab:copyconstructible
|
| 4219 |
-
[tab:lessthancomparable]: #tab:lessthancomparable
|
| 4220 |
-
[tab:moveassignable]: #tab:moveassignable
|
| 4221 |
-
[tab:moveconstructible]: #tab:moveconstructible
|
| 4222 |
[thread.thread.class]: thread.md#thread.thread.class
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4223 |
[upper.bound]: #upper.bound
|
| 4224 |
|
| 4225 |
[^1]: The decision whether to include a copying version was usually
|
| 4226 |
based on complexity considerations. When the cost of doing the
|
| 4227 |
operation dominates the cost of copy, the copying version is not
|
| 4228 |
included. For example, `sort_copy` is not included because the cost
|
| 4229 |
of sorting is much more significant, and users might as well do
|
| 4230 |
`copy` followed by `sort`.
|
| 4231 |
|
| 4232 |
[^2]: `copy_backward` should be used instead of copy when `last` is in
|
| 4233 |
-
the range \[`result -
|
| 4234 |
|
| 4235 |
-
[^3]: `move_backward` should be used instead of move when last is in
|
| 4236 |
-
range \[`result -
|
| 4237 |
|
| 4238 |
[^4]: The use of fully closed ranges is intentional.
|
| 4239 |
|
| 4240 |
-
[^5]: This behavior intentionally differs from `max_element
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
# Algorithms library <a id="algorithms">[[algorithms]]</a>
|
| 2 |
|
| 3 |
## General <a id="algorithms.general">[[algorithms.general]]</a>
|
| 4 |
|
| 5 |
This Clause describes components that C++ programs may use to perform
|
| 6 |
+
algorithmic operations on containers [[containers]] and other sequences.
|
|
|
|
| 7 |
|
| 8 |
The following subclauses describe components for non-modifying sequence
|
| 9 |
+
operations, mutating sequence operations, sorting and related
|
| 10 |
operations, and algorithms from the ISO C library, as summarized in
|
| 11 |
+
[[algorithms.summary]].
|
| 12 |
|
| 13 |
+
**Table: Algorithms library summary** <a id="algorithms.summary">[algorithms.summary]</a>
|
| 14 |
|
| 15 |
| Subclause | | Header |
|
| 16 |
| ---------------------------- | --------------------------------- | ------------- |
|
| 17 |
+
| [[algorithms.requirements]] | Algorithms requirements | |
|
| 18 |
+
| [[algorithms.parallel]] | Parallel algorithms | |
|
| 19 |
+
| [[alg.nonmodifying]] | Non-modifying sequence operations | `<algorithm>` |
|
| 20 |
+
| [[alg.modifying.operations]] | Mutating sequence operations | |
|
| 21 |
| [[alg.sorting]] | Sorting and related operations | |
|
| 22 |
+
| [[numeric.ops]] | Generalized numeric operations | `<numeric>` |
|
| 23 |
+
| [[specialized.algorithms]] | Specialized `<memory>` algorithms | `<memory>` |
|
| 24 |
| [[alg.c.library]] | C library algorithms | `<cstdlib>` |
|
| 25 |
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
## Algorithms requirements <a id="algorithms.requirements">[[algorithms.requirements]]</a>
|
| 28 |
|
| 29 |
All of the algorithms are separated from the particular implementations
|
| 30 |
of data structures and are parameterized by iterator types. Because of
|
| 31 |
this, they can work with program-defined data structures, as long as
|
| 32 |
these data structures have iterator types satisfying the assumptions on
|
| 33 |
the algorithms.
|
| 34 |
|
| 35 |
+
The entities defined in the `std::ranges` namespace in this Clause are
|
| 36 |
+
not found by argument-dependent name lookup [[basic.lookup.argdep]].
|
| 37 |
+
When found by unqualified [[basic.lookup.unqual]] name lookup for the
|
| 38 |
+
*postfix-expression* in a function call [[expr.call]], they inhibit
|
| 39 |
+
argument-dependent name lookup.
|
| 40 |
+
|
| 41 |
+
[*Example 1*:
|
| 42 |
+
|
| 43 |
+
``` cpp
|
| 44 |
+
void foo() {
|
| 45 |
+
using namespace std::ranges;
|
| 46 |
+
std::vector<int> vec{1,2,3};
|
| 47 |
+
find(begin(vec), end(vec), 2); // #1
|
| 48 |
+
}
|
| 49 |
+
```
|
| 50 |
+
|
| 51 |
+
The function call expression at `#1` invokes `std::ranges::find`, not
|
| 52 |
+
`std::find`, despite that (a) the iterator type returned from
|
| 53 |
+
`begin(vec)` and `end(vec)` may be associated with namespace `std` and
|
| 54 |
+
(b) `std::find` is more specialized [[temp.func.order]] than
|
| 55 |
+
`std::ranges::find` since the former requires its first two parameters
|
| 56 |
+
to have the same type.
|
| 57 |
+
|
| 58 |
+
— *end example*]
|
| 59 |
+
|
| 60 |
For purposes of determining the existence of data races, algorithms
|
| 61 |
shall not modify objects referenced through an iterator argument unless
|
| 62 |
the specification requires such modification.
|
| 63 |
|
| 64 |
+
Throughout this Clause, where the template parameters are not
|
| 65 |
+
constrained, the names of template parameters are used to express type
|
| 66 |
+
requirements.
|
| 67 |
|
| 68 |
- If an algorithm’s template parameter is named `InputIterator`,
|
| 69 |
`InputIterator1`, or `InputIterator2`, the template argument shall
|
| 70 |
+
meet the *Cpp17InputIterator* requirements [[input.iterators]].
|
| 71 |
- If an algorithm’s template parameter is named `OutputIterator`,
|
| 72 |
`OutputIterator1`, or `OutputIterator2`, the template argument shall
|
| 73 |
+
meet the *Cpp17OutputIterator* requirements [[output.iterators]].
|
|
|
|
| 74 |
- If an algorithm’s template parameter is named `ForwardIterator`,
|
| 75 |
`ForwardIterator1`, or `ForwardIterator2`, the template argument shall
|
| 76 |
+
meet the *Cpp17ForwardIterator* requirements [[forward.iterators]].
|
| 77 |
+
- If an algorithm’s template parameter is named
|
| 78 |
+
`NoThrowForwardIterator`, the template argument shall meet the
|
| 79 |
+
*Cpp17ForwardIterator* requirements [[forward.iterators]], and is
|
| 80 |
+
required to have the property that no exceptions are thrown from
|
| 81 |
+
increment, assignment, or comparison of, or indirection through, valid
|
| 82 |
+
iterators.
|
| 83 |
- If an algorithm’s template parameter is named `BidirectionalIterator`,
|
| 84 |
`BidirectionalIterator1`, or `BidirectionalIterator2`, the template
|
| 85 |
+
argument shall meet the *Cpp17BidirectionalIterator* requirements
|
| 86 |
+
[[bidirectional.iterators]].
|
| 87 |
- If an algorithm’s template parameter is named `RandomAccessIterator`,
|
| 88 |
`RandomAccessIterator1`, or `RandomAccessIterator2`, the template
|
| 89 |
+
argument shall meet the *Cpp17RandomAccessIterator* requirements
|
| 90 |
+
[[random.access.iterators]].
|
| 91 |
|
| 92 |
+
If an algorithm’s *Effects:* element specifies that a value pointed to
|
| 93 |
+
by any iterator passed as an argument is modified, then that algorithm
|
| 94 |
+
has an additional type requirement: The type of that argument shall meet
|
| 95 |
+
the requirements of a mutable iterator [[iterator.requirements]].
|
| 96 |
|
| 97 |
[*Note 1*: This requirement does not affect arguments that are named
|
| 98 |
`OutputIterator`, `OutputIterator1`, or `OutputIterator2`, because
|
| 99 |
+
output iterators must always be mutable, nor does it affect arguments
|
| 100 |
+
that are constrained, for which mutability requirements are expressed
|
| 101 |
+
explicitly. — *end note*]
|
| 102 |
|
| 103 |
+
Both in-place and copying versions are provided for certain algorithms.
|
| 104 |
+
[^1] When such a version is provided for *algorithm* it is called
|
| 105 |
+
*algorithm`_copy`*. Algorithms that take predicates end with the suffix
|
| 106 |
+
`_if` (which follows the suffix `_copy`).
|
| 107 |
|
| 108 |
+
When not otherwise constrained, the `Predicate` parameter is used
|
| 109 |
+
whenever an algorithm expects a function object [[function.objects]]
|
| 110 |
+
that, when applied to the result of dereferencing the corresponding
|
| 111 |
+
iterator, returns a value testable as `true`. In other words, if an
|
| 112 |
+
algorithm takes `Predicate pred` as its argument and `first` as its
|
| 113 |
+
iterator argument with value type `T`, it should work correctly in the
|
| 114 |
+
construct `pred(*first)` contextually converted to `bool` [[conv]]. The
|
| 115 |
+
function object `pred` shall not apply any non-constant function through
|
| 116 |
+
the dereferenced iterator. Given a glvalue `u` of type (possibly
|
| 117 |
+
`const`) `T` that designates the same object as `*first`, `pred(u)`
|
| 118 |
+
shall be a valid expression that is equal to `pred(*first)`.
|
| 119 |
|
| 120 |
+
When not otherwise constrained, the `BinaryPredicate` parameter is used
|
| 121 |
+
whenever an algorithm expects a function object that when applied to the
|
| 122 |
+
result of dereferencing two corresponding iterators or to dereferencing
|
| 123 |
+
an iterator and type `T` when `T` is part of the signature returns a
|
| 124 |
+
value testable as `true`. In other words, if an algorithm takes
|
| 125 |
+
`BinaryPredicate binary_pred` as its argument and `first1` and `first2`
|
| 126 |
+
as its iterator arguments with respective value types `T1` and `T2`, it
|
| 127 |
+
should work correctly in the construct `binary_pred(*first1, *first2)`
|
| 128 |
+
contextually converted to `bool` [[conv]]. Unless otherwise specified,
|
| 129 |
+
`BinaryPredicate` always takes the first iterator’s `value_type` as its
|
| 130 |
+
first argument, that is, in those cases when `T value` is part of the
|
| 131 |
+
signature, it should work correctly in the construct
|
| 132 |
+
`binary_pred(*first1, value)` contextually converted to `bool` [[conv]].
|
| 133 |
+
`binary_pred` shall not apply any non-constant function through the
|
| 134 |
+
dereferenced iterators. Given a glvalue `u` of type (possibly `const`)
|
| 135 |
+
`T1` that designates the same object as `*first1`, and a glvalue `v` of
|
| 136 |
+
type (possibly `const`) `T2` that designates the same object as
|
| 137 |
+
`*first2`, `binary_pred(u, *first2)`, `binary_pred(*first1, v)`, and
|
| 138 |
+
`binary_pred(u, v)` shall each be a valid expression that is equal to
|
| 139 |
+
`binary_pred(*first1, *first2)`, and `binary_pred(u, value)` shall be a
|
| 140 |
+
valid expression that is equal to `binary_pred(*first1, value)`.
|
| 141 |
+
|
| 142 |
+
The parameters `UnaryOperation`, `BinaryOperation`, `BinaryOperation1`,
|
| 143 |
+
and `BinaryOperation2` are used whenever an algorithm expects a function
|
| 144 |
+
object [[function.objects]].
|
| 145 |
|
| 146 |
[*Note 2*: Unless otherwise specified, algorithms that take function
|
| 147 |
objects as arguments are permitted to copy those function objects
|
| 148 |
freely. Programmers for whom object identity is important should
|
| 149 |
consider using a wrapper class that points to a noncopied implementation
|
| 150 |
+
object such as `reference_wrapper<T>` [[refwrap]], or some equivalent
|
| 151 |
solution. — *end note*]
|
| 152 |
|
| 153 |
When the description of an algorithm gives an expression such as
|
| 154 |
`*first == value` for a condition, the expression shall evaluate to
|
| 155 |
either `true` or `false` in boolean contexts.
|
| 156 |
|
| 157 |
+
In the description of the algorithms, operator `+` is used for some of
|
| 158 |
+
the iterator categories for which it does not have to be defined. In
|
| 159 |
+
these cases the semantics of `a + n` are the same as those of
|
| 160 |
|
| 161 |
``` cpp
|
| 162 |
+
auto tmp = a;
|
| 163 |
+
for (; n < 0; ++n) --tmp;
|
| 164 |
+
for (; n > 0; --n) ++tmp;
|
| 165 |
return tmp;
|
| 166 |
```
|
| 167 |
|
| 168 |
+
Similarly, operator `-` is used for some combinations of iterators and
|
| 169 |
+
sentinel types for which it does not have to be defined. If \[`a`, `b`)
|
| 170 |
+
denotes a range, the semantics of `b - a` in these cases are the same as
|
| 171 |
+
those of
|
| 172 |
|
| 173 |
``` cpp
|
| 174 |
+
iter_difference_t<decltype(a)> n = 0;
|
| 175 |
+
for (auto tmp = a; tmp != b; ++tmp) ++n;
|
| 176 |
+
return n;
|
| 177 |
```
|
| 178 |
|
| 179 |
+
and if \[`b`, `a`) denotes a range, the same as those of
|
| 180 |
+
|
| 181 |
+
``` cpp
|
| 182 |
+
iter_difference_t<decltype(b)> n = 0;
|
| 183 |
+
for (auto tmp = b; tmp != a; ++tmp) --n;
|
| 184 |
+
return n;
|
| 185 |
+
```
|
| 186 |
+
|
| 187 |
+
In the description of algorithm return values, a sentinel value `s`
|
| 188 |
+
denoting the end of a range \[`i`, `s`) is sometimes returned where an
|
| 189 |
+
iterator is expected. In these cases, the semantics are as if the
|
| 190 |
+
sentinel is converted into an iterator using `ranges::next(i, s)`.
|
| 191 |
+
|
| 192 |
+
Overloads of algorithms that take `range` arguments [[range.range]]
|
| 193 |
+
behave as if they are implemented by calling `ranges::begin` and
|
| 194 |
+
`ranges::end` on the `range`(s) and dispatching to the overload in
|
| 195 |
+
namespace `ranges` that takes separate iterator and sentinel arguments.
|
| 196 |
+
|
| 197 |
+
The number and order of deducible template parameters for algorithm
|
| 198 |
+
declarations are unspecified, except where explicitly stated otherwise.
|
| 199 |
+
|
| 200 |
+
[*Note 3*: Consequently, the algorithms may not be called with
|
| 201 |
+
explicitly-specified template argument lists. — *end note*]
|
| 202 |
+
|
| 203 |
## Parallel algorithms <a id="algorithms.parallel">[[algorithms.parallel]]</a>
|
| 204 |
|
| 205 |
+
### Preamble <a id="algorithms.parallel.defns">[[algorithms.parallel.defns]]</a>
|
|
|
|
| 206 |
|
| 207 |
+
Subclause [[algorithms.parallel]] describes components that C++ programs
|
| 208 |
+
may use to perform operations on containers and other sequences in
|
| 209 |
+
parallel.
|
| 210 |
|
| 211 |
+
A *parallel algorithm* is a function template listed in this document
|
| 212 |
+
with a template parameter named `ExecutionPolicy`.
|
|
|
|
| 213 |
|
| 214 |
Parallel algorithms access objects indirectly accessible via their
|
| 215 |
arguments by invoking the following functions:
|
| 216 |
|
| 217 |
- All operations of the categories of the iterators that the algorithm
|
|
|
|
| 219 |
- Operations on those sequence elements that are required by its
|
| 220 |
specification.
|
| 221 |
- User-provided function objects to be applied during the execution of
|
| 222 |
the algorithm, if required by the specification.
|
| 223 |
- Operations on those function objects required by the specification.
|
| 224 |
+
\[*Note 1*: See [[algorithms.requirements]]. — *end note*]
|
| 225 |
|
| 226 |
These functions are herein called *element access functions*.
|
| 227 |
|
| 228 |
[*Example 1*:
|
| 229 |
|
|
|
|
| 236 |
preconditions specified in [[sort]]).
|
| 237 |
- The user-provided `Compare` function object.
|
| 238 |
|
| 239 |
— *end example*]
|
| 240 |
|
| 241 |
+
A standard library function is *vectorization-unsafe* if it is specified
|
| 242 |
+
to synchronize with another function invocation, or another function
|
| 243 |
+
invocation is specified to synchronize with it, and if it is not a
|
| 244 |
+
memory allocation or deallocation function.
|
| 245 |
+
|
| 246 |
+
[*Note 2*: Implementations must ensure that internal synchronization
|
| 247 |
+
inside standard library functions does not prevent forward progress when
|
| 248 |
+
those functions are executed by threads of execution with weakly
|
| 249 |
+
parallel forward progress guarantees. — *end note*]
|
| 250 |
+
|
| 251 |
+
[*Example 2*:
|
| 252 |
+
|
| 253 |
+
``` cpp
|
| 254 |
+
int x = 0;
|
| 255 |
+
std::mutex m;
|
| 256 |
+
void f() {
|
| 257 |
+
int a[] = {1,2};
|
| 258 |
+
std::for_each(std::execution::par_unseq, std::begin(a), std::end(a), [&](int) {
|
| 259 |
+
std::lock_guard<mutex> guard(m); // incorrect: lock_guard constructor calls m.lock()
|
| 260 |
+
++x;
|
| 261 |
+
});
|
| 262 |
+
}
|
| 263 |
+
```
|
| 264 |
+
|
| 265 |
+
The above program may result in two consecutive calls to `m.lock()` on
|
| 266 |
+
the same thread of execution (which may deadlock), because the
|
| 267 |
+
applications of the function object are not guaranteed to run on
|
| 268 |
+
different threads of execution.
|
| 269 |
+
|
| 270 |
+
— *end example*]
|
| 271 |
+
|
| 272 |
### Requirements on user-provided function objects <a id="algorithms.parallel.user">[[algorithms.parallel.user]]</a>
|
| 273 |
|
| 274 |
Unless otherwise specified, function objects passed into parallel
|
| 275 |
algorithms as objects of type `Predicate`, `BinaryPredicate`, `Compare`,
|
| 276 |
`UnaryOperation`, `BinaryOperation`, `BinaryOperation1`,
|
| 277 |
`BinaryOperation2`, and the operators used by the analogous overloads to
|
| 278 |
these parallel algorithms that could be formed by the invocation with
|
| 279 |
the specified default predicate or operation (where applicable) shall
|
| 280 |
not directly or indirectly modify objects via their arguments, nor shall
|
| 281 |
+
they rely on the identity of the provided objects.
|
| 282 |
|
| 283 |
### Effect of execution policies on algorithm execution <a id="algorithms.parallel.exec">[[algorithms.parallel.exec]]</a>
|
| 284 |
|
| 285 |
+
Parallel algorithms have template parameters named `ExecutionPolicy`
|
| 286 |
+
[[execpol]] which describe the manner in which the execution of these
|
| 287 |
algorithms may be parallelized and the manner in which they apply the
|
| 288 |
element access functions.
|
| 289 |
|
| 290 |
+
If an object is modified by an element access function, the algorithm
|
| 291 |
+
will perform no other unsynchronized accesses to that object. The
|
| 292 |
+
modifying element access functions are those which are specified as
|
| 293 |
+
modifying the object.
|
| 294 |
+
|
| 295 |
+
[*Note 1*: For example, `swap`, `++`, `--`, `@=`, and assignments
|
| 296 |
+
modify the object. For the assignment and `@=` operators, only the left
|
| 297 |
+
argument is modified. — *end note*]
|
| 298 |
+
|
| 299 |
Unless otherwise stated, implementations may make arbitrary copies of
|
| 300 |
elements (with type `T`) from sequences where
|
| 301 |
`is_trivially_copy_constructible_v<T>` and
|
| 302 |
`is_trivially_destructible_v<T>` are `true`.
|
| 303 |
|
| 304 |
+
[*Note 2*: This implies that user-supplied function objects should not
|
| 305 |
rely on object identity of arguments for such input sequences. Users for
|
| 306 |
whom the object identity of the arguments to these function objects is
|
| 307 |
important should consider using a wrapping iterator that returns a
|
| 308 |
+
non-copied implementation object such as `reference_wrapper<T>`
|
| 309 |
+
[[refwrap]] or some equivalent solution. — *end note*]
|
| 310 |
|
| 311 |
The invocations of element access functions in parallel algorithms
|
| 312 |
invoked with an execution policy object of type
|
| 313 |
`execution::sequenced_policy` all occur in the calling thread of
|
| 314 |
execution.
|
| 315 |
|
| 316 |
+
[*Note 3*: The invocations are not interleaved; see
|
| 317 |
[[intro.execution]]. — *end note*]
|
| 318 |
|
| 319 |
The invocations of element access functions in parallel algorithms
|
| 320 |
invoked with an execution policy object of type
|
| 321 |
+
`execution::unsequenced_policy` are permitted to execute in an unordered
|
| 322 |
+
fashion in the calling thread of execution, unsequenced with respect to
|
| 323 |
+
one another in the calling thread of execution.
|
| 324 |
+
|
| 325 |
+
[*Note 4*: This means that multiple function object invocations may be
|
| 326 |
+
interleaved on a single thread of execution, which overrides the usual
|
| 327 |
+
guarantee from [[intro.execution]] that function executions do not
|
| 328 |
+
overlap with one another. — *end note*]
|
| 329 |
+
|
| 330 |
+
The behavior of a program is undefined if it invokes a
|
| 331 |
+
vectorization-unsafe standard library function from user code called
|
| 332 |
+
from a `execution::unsequenced_policy` algorithm.
|
| 333 |
+
|
| 334 |
+
[*Note 5*: Because `execution::unsequenced_policy` allows the execution
|
| 335 |
+
of element access functions to be interleaved on a single thread of
|
| 336 |
+
execution, blocking synchronization, including the use of mutexes, risks
|
| 337 |
+
deadlock. — *end note*]
|
| 338 |
+
|
| 339 |
+
The invocations of element access functions in parallel algorithms
|
| 340 |
+
invoked with an execution policy object of type
|
| 341 |
+
`execution::parallel_policy` are permitted to execute either in the
|
| 342 |
invoking thread of execution or in a thread of execution implicitly
|
| 343 |
created by the library to support parallel algorithm execution. If the
|
| 344 |
+
threads of execution created by `thread` [[thread.thread.class]] or
|
| 345 |
+
`jthread` [[thread.jthread.class]] provide concurrent forward progress
|
| 346 |
+
guarantees [[intro.progress]], then a thread of execution implicitly
|
| 347 |
+
created by the library will provide parallel forward progress
|
| 348 |
+
guarantees; otherwise, the provided forward progress guarantee is
|
| 349 |
+
*implementation-defined*. Any such invocations executing in the same
|
| 350 |
+
thread of execution are indeterminately sequenced with respect to each
|
| 351 |
+
other.
|
| 352 |
|
| 353 |
+
[*Note 6*: It is the caller’s responsibility to ensure that the
|
| 354 |
invocation does not introduce data races or deadlocks. — *end note*]
|
| 355 |
|
| 356 |
[*Example 1*:
|
| 357 |
|
| 358 |
``` cpp
|
|
|
|
| 372 |
|
| 373 |
``` cpp
|
| 374 |
std::atomic<int> x{0};
|
| 375 |
int a[] = {1,2};
|
| 376 |
std::for_each(std::execution::par, std::begin(a), std::end(a), [&](int) {
|
| 377 |
+
x.fetch_add(1, std::memory_order::relaxed);
|
| 378 |
// spin wait for another iteration to change the value of x
|
| 379 |
+
while (x.load(std::memory_order::relaxed) == 1) { } // incorrect: assumes execution order
|
| 380 |
});
|
| 381 |
```
|
| 382 |
|
| 383 |
The above example depends on the order of execution of the iterations,
|
| 384 |
and will not terminate if both iterations are executed sequentially on
|
|
|
|
| 402 |
incremented correctly.
|
| 403 |
|
| 404 |
— *end example*]
|
| 405 |
|
| 406 |
The invocations of element access functions in parallel algorithms
|
| 407 |
+
invoked with an execution policy object of type
|
| 408 |
`execution::parallel_unsequenced_policy` are permitted to execute in an
|
| 409 |
unordered fashion in unspecified threads of execution, and unsequenced
|
| 410 |
with respect to one another within each thread of execution. These
|
| 411 |
threads of execution are either the invoking thread of execution or
|
| 412 |
threads of execution implicitly created by the library; the latter will
|
| 413 |
provide weakly parallel forward progress guarantees.
|
| 414 |
|
| 415 |
+
[*Note 7*: This means that multiple function object invocations may be
|
| 416 |
interleaved on a single thread of execution, which overrides the usual
|
| 417 |
guarantee from [[intro.execution]] that function executions do not
|
| 418 |
+
overlap with one another. — *end note*]
|
| 419 |
|
| 420 |
+
The behavior of a program is undefined if it invokes a
|
| 421 |
+
vectorization-unsafe standard library function from user code called
|
| 422 |
+
from a `execution::parallel_unsequenced_policy` algorithm.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 423 |
|
| 424 |
+
[*Note 8*: Because `execution::parallel_unsequenced_policy` allows the
|
| 425 |
+
execution of element access functions to be interleaved on a single
|
| 426 |
+
thread of execution, blocking synchronization, including the use of
|
| 427 |
+
mutexes, risks deadlock. — *end note*]
|
| 428 |
|
| 429 |
+
[*Note 9*: The semantics of invocation with
|
| 430 |
+
`execution::unsequenced_policy`, `execution::parallel_policy`, or
|
| 431 |
+
`execution::parallel_unsequenced_policy` allow the implementation to
|
| 432 |
+
fall back to sequential execution if the system cannot parallelize an
|
| 433 |
+
algorithm invocation, e.g., due to lack of resources. — *end note*]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 434 |
|
| 435 |
If an invocation of a parallel algorithm uses threads of execution
|
| 436 |
implicitly created by the library, then the invoking thread of execution
|
| 437 |
will either
|
| 438 |
|
| 439 |
+
- temporarily block with forward progress guarantee delegation
|
| 440 |
+
[[intro.progress]] on the completion of these library-managed threads
|
| 441 |
of execution, or
|
| 442 |
- eventually execute an element access function;
|
| 443 |
|
| 444 |
the thread of execution will continue to do so until the algorithm is
|
| 445 |
finished.
|
| 446 |
|
| 447 |
+
[*Note 10*: In blocking with forward progress guarantee delegation in
|
| 448 |
this context, a thread of execution created by the library is considered
|
| 449 |
to have finished execution as soon as it has finished the execution of
|
| 450 |
the particular element access function that the invoking thread of
|
| 451 |
execution logically depends on. — *end note*]
|
| 452 |
|
|
|
|
| 484 |
number of assignments or swaps, and *expr* is not already expressed with
|
| 485 |
𝑂() notation, the complexity of the algorithm shall be
|
| 486 |
𝑂(\placeholder{expr}).
|
| 487 |
|
| 488 |
Parallel algorithms shall not participate in overload resolution unless
|
| 489 |
+
`is_execution_policy_v<remove_cvref_t<ExecutionPolicy>>` is `true`.
|
| 490 |
+
|
| 491 |
+
## Header `<algorithm>` synopsis <a id="algorithm.syn">[[algorithm.syn]]</a>
|
| 492 |
+
|
| 493 |
+
``` cpp
|
| 494 |
+
#include <initializer_list>
|
| 495 |
+
|
| 496 |
+
namespace std {
|
| 497 |
+
namespace ranges {
|
| 498 |
+
// [algorithms.results], algorithm result types
|
| 499 |
+
template<class I, class F>
|
| 500 |
+
struct in_fun_result;
|
| 501 |
+
|
| 502 |
+
template<class I1, class I2>
|
| 503 |
+
struct in_in_result;
|
| 504 |
+
|
| 505 |
+
template<class I, class O>
|
| 506 |
+
struct in_out_result;
|
| 507 |
+
|
| 508 |
+
template<class I1, class I2, class O>
|
| 509 |
+
struct in_in_out_result;
|
| 510 |
+
|
| 511 |
+
template<class I, class O1, class O2>
|
| 512 |
+
struct in_out_out_result;
|
| 513 |
+
|
| 514 |
+
template<class T>
|
| 515 |
+
struct min_max_result;
|
| 516 |
+
|
| 517 |
+
template<class I>
|
| 518 |
+
struct in_found_result;
|
| 519 |
+
}
|
| 520 |
+
|
| 521 |
+
// [alg.nonmodifying], non-modifying sequence operations
|
| 522 |
+
// [alg.all.of], all of
|
| 523 |
+
template<class InputIterator, class Predicate>
|
| 524 |
+
constexpr bool all_of(InputIterator first, InputIterator last, Predicate pred);
|
| 525 |
+
template<class ExecutionPolicy, class ForwardIterator, class Predicate>
|
| 526 |
+
bool all_of(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 527 |
+
ForwardIterator first, ForwardIterator last, Predicate pred);
|
| 528 |
+
|
| 529 |
+
namespace ranges {
|
| 530 |
+
template<input_iterator I, sentinel_for<I> S, class Proj = identity,
|
| 531 |
+
indirect_unary_predicate<projected<I, Proj>> Pred>
|
| 532 |
+
constexpr bool all_of(I first, S last, Pred pred, Proj proj = {});
|
| 533 |
+
template<input_range R, class Proj = identity,
|
| 534 |
+
indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
|
| 535 |
+
constexpr bool all_of(R&& r, Pred pred, Proj proj = {});
|
| 536 |
+
}
|
| 537 |
+
|
| 538 |
+
// [alg.any.of], any of
|
| 539 |
+
template<class InputIterator, class Predicate>
|
| 540 |
+
constexpr bool any_of(InputIterator first, InputIterator last, Predicate pred);
|
| 541 |
+
template<class ExecutionPolicy, class ForwardIterator, class Predicate>
|
| 542 |
+
bool any_of(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 543 |
+
ForwardIterator first, ForwardIterator last, Predicate pred);
|
| 544 |
+
|
| 545 |
+
namespace ranges {
|
| 546 |
+
template<input_iterator I, sentinel_for<I> S, class Proj = identity,
|
| 547 |
+
indirect_unary_predicate<projected<I, Proj>> Pred>
|
| 548 |
+
constexpr bool any_of(I first, S last, Pred pred, Proj proj = {});
|
| 549 |
+
template<input_range R, class Proj = identity,
|
| 550 |
+
indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
|
| 551 |
+
constexpr bool any_of(R&& r, Pred pred, Proj proj = {});
|
| 552 |
+
}
|
| 553 |
+
|
| 554 |
+
// [alg.none.of], none of
|
| 555 |
+
template<class InputIterator, class Predicate>
|
| 556 |
+
constexpr bool none_of(InputIterator first, InputIterator last, Predicate pred);
|
| 557 |
+
template<class ExecutionPolicy, class ForwardIterator, class Predicate>
|
| 558 |
+
bool none_of(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 559 |
+
ForwardIterator first, ForwardIterator last, Predicate pred);
|
| 560 |
+
|
| 561 |
+
namespace ranges {
|
| 562 |
+
template<input_iterator I, sentinel_for<I> S, class Proj = identity,
|
| 563 |
+
indirect_unary_predicate<projected<I, Proj>> Pred>
|
| 564 |
+
constexpr bool none_of(I first, S last, Pred pred, Proj proj = {});
|
| 565 |
+
template<input_range R, class Proj = identity,
|
| 566 |
+
indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
|
| 567 |
+
constexpr bool none_of(R&& r, Pred pred, Proj proj = {});
|
| 568 |
+
}
|
| 569 |
+
|
| 570 |
+
// [alg.foreach], for each
|
| 571 |
+
template<class InputIterator, class Function>
|
| 572 |
+
constexpr Function for_each(InputIterator first, InputIterator last, Function f);
|
| 573 |
+
template<class ExecutionPolicy, class ForwardIterator, class Function>
|
| 574 |
+
void for_each(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 575 |
+
ForwardIterator first, ForwardIterator last, Function f);
|
| 576 |
+
|
| 577 |
+
namespace ranges {
|
| 578 |
+
template<class I, class F>
|
| 579 |
+
using for_each_result = in_fun_result<I, F>;
|
| 580 |
+
|
| 581 |
+
template<input_iterator I, sentinel_for<I> S, class Proj = identity,
|
| 582 |
+
indirectly_unary_invocable<projected<I, Proj>> Fun>
|
| 583 |
+
constexpr for_each_result<I, Fun>
|
| 584 |
+
for_each(I first, S last, Fun f, Proj proj = {});
|
| 585 |
+
template<input_range R, class Proj = identity,
|
| 586 |
+
indirectly_unary_invocable<projected<iterator_t<R>, Proj>> Fun>
|
| 587 |
+
constexpr for_each_result<borrowed_iterator_t<R>, Fun>
|
| 588 |
+
for_each(R&& r, Fun f, Proj proj = {});
|
| 589 |
+
}
|
| 590 |
+
|
| 591 |
+
template<class InputIterator, class Size, class Function>
|
| 592 |
+
constexpr InputIterator for_each_n(InputIterator first, Size n, Function f);
|
| 593 |
+
template<class ExecutionPolicy, class ForwardIterator, class Size, class Function>
|
| 594 |
+
ForwardIterator for_each_n(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 595 |
+
ForwardIterator first, Size n, Function f);
|
| 596 |
+
|
| 597 |
+
namespace ranges {
|
| 598 |
+
template<class I, class F>
|
| 599 |
+
using for_each_n_result = in_fun_result<I, F>;
|
| 600 |
+
|
| 601 |
+
template<input_iterator I, class Proj = identity,
|
| 602 |
+
indirectly_unary_invocable<projected<I, Proj>> Fun>
|
| 603 |
+
constexpr for_each_n_result<I, Fun>
|
| 604 |
+
for_each_n(I first, iter_difference_t<I> n, Fun f, Proj proj = {});
|
| 605 |
+
}
|
| 606 |
+
|
| 607 |
+
// [alg.find], find
|
| 608 |
+
template<class InputIterator, class T>
|
| 609 |
+
constexpr InputIterator find(InputIterator first, InputIterator last,
|
| 610 |
+
const T& value);
|
| 611 |
+
template<class ExecutionPolicy, class ForwardIterator, class T>
|
| 612 |
+
ForwardIterator find(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 613 |
+
ForwardIterator first, ForwardIterator last,
|
| 614 |
+
const T& value);
|
| 615 |
+
template<class InputIterator, class Predicate>
|
| 616 |
+
constexpr InputIterator find_if(InputIterator first, InputIterator last,
|
| 617 |
+
Predicate pred);
|
| 618 |
+
template<class ExecutionPolicy, class ForwardIterator, class Predicate>
|
| 619 |
+
ForwardIterator find_if(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 620 |
+
ForwardIterator first, ForwardIterator last,
|
| 621 |
+
Predicate pred);
|
| 622 |
+
template<class InputIterator, class Predicate>
|
| 623 |
+
constexpr InputIterator find_if_not(InputIterator first, InputIterator last,
|
| 624 |
+
Predicate pred);
|
| 625 |
+
template<class ExecutionPolicy, class ForwardIterator, class Predicate>
|
| 626 |
+
ForwardIterator find_if_not(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 627 |
+
ForwardIterator first, ForwardIterator last,
|
| 628 |
+
Predicate pred);
|
| 629 |
+
|
| 630 |
+
namespace ranges {
|
| 631 |
+
template<input_iterator I, sentinel_for<I> S, class T, class Proj = identity>
|
| 632 |
+
requires indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T*>
|
| 633 |
+
constexpr I find(I first, S last, const T& value, Proj proj = {});
|
| 634 |
+
template<input_range R, class T, class Proj = identity>
|
| 635 |
+
requires indirect_binary_predicate<ranges::equal_to,
|
| 636 |
+
projected<iterator_t<R>, Proj>, const T*>
|
| 637 |
+
constexpr borrowed_iterator_t<R>
|
| 638 |
+
find(R&& r, const T& value, Proj proj = {});
|
| 639 |
+
template<input_iterator I, sentinel_for<I> S, class Proj = identity,
|
| 640 |
+
indirect_unary_predicate<projected<I, Proj>> Pred>
|
| 641 |
+
constexpr I find_if(I first, S last, Pred pred, Proj proj = {});
|
| 642 |
+
template<input_range R, class Proj = identity,
|
| 643 |
+
indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
|
| 644 |
+
constexpr borrowed_iterator_t<R>
|
| 645 |
+
find_if(R&& r, Pred pred, Proj proj = {});
|
| 646 |
+
template<input_iterator I, sentinel_for<I> S, class Proj = identity,
|
| 647 |
+
indirect_unary_predicate<projected<I, Proj>> Pred>
|
| 648 |
+
constexpr I find_if_not(I first, S last, Pred pred, Proj proj = {});
|
| 649 |
+
template<input_range R, class Proj = identity,
|
| 650 |
+
indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
|
| 651 |
+
constexpr borrowed_iterator_t<R>
|
| 652 |
+
find_if_not(R&& r, Pred pred, Proj proj = {});
|
| 653 |
+
}
|
| 654 |
+
|
| 655 |
+
// [alg.find.end], find end
|
| 656 |
+
template<class ForwardIterator1, class ForwardIterator2>
|
| 657 |
+
constexpr ForwardIterator1
|
| 658 |
+
find_end(ForwardIterator1 first1, ForwardIterator1 last1,
|
| 659 |
+
ForwardIterator2 first2, ForwardIterator2 last2);
|
| 660 |
+
template<class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
|
| 661 |
+
constexpr ForwardIterator1
|
| 662 |
+
find_end(ForwardIterator1 first1, ForwardIterator1 last1,
|
| 663 |
+
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 664 |
+
BinaryPredicate pred);
|
| 665 |
+
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 666 |
+
ForwardIterator1
|
| 667 |
+
find_end(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 668 |
+
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 669 |
+
ForwardIterator2 first2, ForwardIterator2 last2);
|
| 670 |
+
template<class ExecutionPolicy, class ForwardIterator1,
|
| 671 |
+
class ForwardIterator2, class BinaryPredicate>
|
| 672 |
+
ForwardIterator1
|
| 673 |
+
find_end(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 674 |
+
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 675 |
+
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 676 |
+
BinaryPredicate pred);
|
| 677 |
+
|
| 678 |
+
namespace ranges {
|
| 679 |
+
template<forward_iterator I1, sentinel_for<I1> S1, forward_iterator I2, sentinel_for<I2> S2,
|
| 680 |
+
class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
|
| 681 |
+
requires indirectly_comparable<I1, I2, Pred, Proj1, Proj2>
|
| 682 |
+
constexpr subrange<I1>
|
| 683 |
+
find_end(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {},
|
| 684 |
+
Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 685 |
+
template<forward_range R1, forward_range R2,
|
| 686 |
+
class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
|
| 687 |
+
requires indirectly_comparable<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
|
| 688 |
+
constexpr borrowed_subrange_t<R1>
|
| 689 |
+
find_end(R1&& r1, R2&& r2, Pred pred = {},
|
| 690 |
+
Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 691 |
+
}
|
| 692 |
+
|
| 693 |
+
// [alg.find.first.of], find first
|
| 694 |
+
template<class InputIterator, class ForwardIterator>
|
| 695 |
+
constexpr InputIterator
|
| 696 |
+
find_first_of(InputIterator first1, InputIterator last1,
|
| 697 |
+
ForwardIterator first2, ForwardIterator last2);
|
| 698 |
+
template<class InputIterator, class ForwardIterator, class BinaryPredicate>
|
| 699 |
+
constexpr InputIterator
|
| 700 |
+
find_first_of(InputIterator first1, InputIterator last1,
|
| 701 |
+
ForwardIterator first2, ForwardIterator last2,
|
| 702 |
+
BinaryPredicate pred);
|
| 703 |
+
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 704 |
+
ForwardIterator1
|
| 705 |
+
find_first_of(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 706 |
+
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 707 |
+
ForwardIterator2 first2, ForwardIterator2 last2);
|
| 708 |
+
template<class ExecutionPolicy, class ForwardIterator1,
|
| 709 |
+
class ForwardIterator2, class BinaryPredicate>
|
| 710 |
+
ForwardIterator1
|
| 711 |
+
find_first_of(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 712 |
+
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 713 |
+
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 714 |
+
BinaryPredicate pred);
|
| 715 |
+
|
| 716 |
+
namespace ranges {
|
| 717 |
+
template<input_iterator I1, sentinel_for<I1> S1, forward_iterator I2, sentinel_for<I2> S2,
|
| 718 |
+
class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
|
| 719 |
+
requires indirectly_comparable<I1, I2, Pred, Proj1, Proj2>
|
| 720 |
+
constexpr I1 find_first_of(I1 first1, S1 last1, I2 first2, S2 last2,
|
| 721 |
+
Pred pred = {},
|
| 722 |
+
Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 723 |
+
template<input_range R1, forward_range R2,
|
| 724 |
+
class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
|
| 725 |
+
requires indirectly_comparable<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
|
| 726 |
+
constexpr borrowed_iterator_t<R1>
|
| 727 |
+
find_first_of(R1&& r1, R2&& r2,
|
| 728 |
+
Pred pred = {},
|
| 729 |
+
Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 730 |
+
}
|
| 731 |
+
|
| 732 |
+
// [alg.adjacent.find], adjacent find
|
| 733 |
+
template<class ForwardIterator>
|
| 734 |
+
constexpr ForwardIterator
|
| 735 |
+
adjacent_find(ForwardIterator first, ForwardIterator last);
|
| 736 |
+
template<class ForwardIterator, class BinaryPredicate>
|
| 737 |
+
constexpr ForwardIterator
|
| 738 |
+
adjacent_find(ForwardIterator first, ForwardIterator last,
|
| 739 |
+
BinaryPredicate pred);
|
| 740 |
+
template<class ExecutionPolicy, class ForwardIterator>
|
| 741 |
+
ForwardIterator
|
| 742 |
+
adjacent_find(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 743 |
+
ForwardIterator first, ForwardIterator last);
|
| 744 |
+
template<class ExecutionPolicy, class ForwardIterator, class BinaryPredicate>
|
| 745 |
+
ForwardIterator
|
| 746 |
+
adjacent_find(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 747 |
+
ForwardIterator first, ForwardIterator last,
|
| 748 |
+
BinaryPredicate pred);
|
| 749 |
+
|
| 750 |
+
namespace ranges {
|
| 751 |
+
template<forward_iterator I, sentinel_for<I> S, class Proj = identity,
|
| 752 |
+
indirect_binary_predicate<projected<I, Proj>,
|
| 753 |
+
projected<I, Proj>> Pred = ranges::equal_to>
|
| 754 |
+
constexpr I adjacent_find(I first, S last, Pred pred = {},
|
| 755 |
+
Proj proj = {});
|
| 756 |
+
template<forward_range R, class Proj = identity,
|
| 757 |
+
indirect_binary_predicate<projected<iterator_t<R>, Proj>,
|
| 758 |
+
projected<iterator_t<R>, Proj>> Pred = ranges::equal_to>
|
| 759 |
+
constexpr borrowed_iterator_t<R>
|
| 760 |
+
adjacent_find(R&& r, Pred pred = {}, Proj proj = {});
|
| 761 |
+
}
|
| 762 |
+
|
| 763 |
+
// [alg.count], count
|
| 764 |
+
template<class InputIterator, class T>
|
| 765 |
+
constexpr typename iterator_traits<InputIterator>::difference_type
|
| 766 |
+
count(InputIterator first, InputIterator last, const T& value);
|
| 767 |
+
template<class ExecutionPolicy, class ForwardIterator, class T>
|
| 768 |
+
typename iterator_traits<ForwardIterator>::difference_type
|
| 769 |
+
count(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 770 |
+
ForwardIterator first, ForwardIterator last, const T& value);
|
| 771 |
+
template<class InputIterator, class Predicate>
|
| 772 |
+
constexpr typename iterator_traits<InputIterator>::difference_type
|
| 773 |
+
count_if(InputIterator first, InputIterator last, Predicate pred);
|
| 774 |
+
template<class ExecutionPolicy, class ForwardIterator, class Predicate>
|
| 775 |
+
typename iterator_traits<ForwardIterator>::difference_type
|
| 776 |
+
count_if(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 777 |
+
ForwardIterator first, ForwardIterator last, Predicate pred);
|
| 778 |
+
|
| 779 |
+
namespace ranges {
|
| 780 |
+
template<input_iterator I, sentinel_for<I> S, class T, class Proj = identity>
|
| 781 |
+
requires indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T*>
|
| 782 |
+
constexpr iter_difference_t<I>
|
| 783 |
+
count(I first, S last, const T& value, Proj proj = {});
|
| 784 |
+
template<input_range R, class T, class Proj = identity>
|
| 785 |
+
requires indirect_binary_predicate<ranges::equal_to,
|
| 786 |
+
projected<iterator_t<R>, Proj>, const T*>
|
| 787 |
+
constexpr range_difference_t<R>
|
| 788 |
+
count(R&& r, const T& value, Proj proj = {});
|
| 789 |
+
template<input_iterator I, sentinel_for<I> S, class Proj = identity,
|
| 790 |
+
indirect_unary_predicate<projected<I, Proj>> Pred>
|
| 791 |
+
constexpr iter_difference_t<I>
|
| 792 |
+
count_if(I first, S last, Pred pred, Proj proj = {});
|
| 793 |
+
template<input_range R, class Proj = identity,
|
| 794 |
+
indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
|
| 795 |
+
constexpr range_difference_t<R>
|
| 796 |
+
count_if(R&& r, Pred pred, Proj proj = {});
|
| 797 |
+
}
|
| 798 |
+
|
| 799 |
+
// [mismatch], mismatch
|
| 800 |
+
template<class InputIterator1, class InputIterator2>
|
| 801 |
+
constexpr pair<InputIterator1, InputIterator2>
|
| 802 |
+
mismatch(InputIterator1 first1, InputIterator1 last1,
|
| 803 |
+
InputIterator2 first2);
|
| 804 |
+
template<class InputIterator1, class InputIterator2, class BinaryPredicate>
|
| 805 |
+
constexpr pair<InputIterator1, InputIterator2>
|
| 806 |
+
mismatch(InputIterator1 first1, InputIterator1 last1,
|
| 807 |
+
InputIterator2 first2, BinaryPredicate pred);
|
| 808 |
+
template<class InputIterator1, class InputIterator2>
|
| 809 |
+
constexpr pair<InputIterator1, InputIterator2>
|
| 810 |
+
mismatch(InputIterator1 first1, InputIterator1 last1,
|
| 811 |
+
InputIterator2 first2, InputIterator2 last2);
|
| 812 |
+
template<class InputIterator1, class InputIterator2, class BinaryPredicate>
|
| 813 |
+
constexpr pair<InputIterator1, InputIterator2>
|
| 814 |
+
mismatch(InputIterator1 first1, InputIterator1 last1,
|
| 815 |
+
InputIterator2 first2, InputIterator2 last2,
|
| 816 |
+
BinaryPredicate pred);
|
| 817 |
+
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 818 |
+
pair<ForwardIterator1, ForwardIterator2>
|
| 819 |
+
mismatch(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 820 |
+
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 821 |
+
ForwardIterator2 first2);
|
| 822 |
+
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 823 |
+
class BinaryPredicate>
|
| 824 |
+
pair<ForwardIterator1, ForwardIterator2>
|
| 825 |
+
mismatch(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 826 |
+
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 827 |
+
ForwardIterator2 first2, BinaryPredicate pred);
|
| 828 |
+
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 829 |
+
pair<ForwardIterator1, ForwardIterator2>
|
| 830 |
+
mismatch(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 831 |
+
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 832 |
+
ForwardIterator2 first2, ForwardIterator2 last2);
|
| 833 |
+
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 834 |
+
class BinaryPredicate>
|
| 835 |
+
pair<ForwardIterator1, ForwardIterator2>
|
| 836 |
+
mismatch(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 837 |
+
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 838 |
+
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 839 |
+
BinaryPredicate pred);
|
| 840 |
+
|
| 841 |
+
namespace ranges {
|
| 842 |
+
template<class I1, class I2>
|
| 843 |
+
using mismatch_result = in_in_result<I1, I2>;
|
| 844 |
+
|
| 845 |
+
template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2,
|
| 846 |
+
class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
|
| 847 |
+
requires indirectly_comparable<I1, I2, Pred, Proj1, Proj2>
|
| 848 |
+
constexpr mismatch_result<I1, I2>
|
| 849 |
+
mismatch(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {},
|
| 850 |
+
Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 851 |
+
template<input_range R1, input_range R2,
|
| 852 |
+
class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
|
| 853 |
+
requires indirectly_comparable<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
|
| 854 |
+
constexpr mismatch_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>>
|
| 855 |
+
mismatch(R1&& r1, R2&& r2, Pred pred = {},
|
| 856 |
+
Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 857 |
+
}
|
| 858 |
+
|
| 859 |
+
// [alg.equal], equal
|
| 860 |
+
template<class InputIterator1, class InputIterator2>
|
| 861 |
+
constexpr bool equal(InputIterator1 first1, InputIterator1 last1,
|
| 862 |
+
InputIterator2 first2);
|
| 863 |
+
template<class InputIterator1, class InputIterator2, class BinaryPredicate>
|
| 864 |
+
constexpr bool equal(InputIterator1 first1, InputIterator1 last1,
|
| 865 |
+
InputIterator2 first2, BinaryPredicate pred);
|
| 866 |
+
template<class InputIterator1, class InputIterator2>
|
| 867 |
+
constexpr bool equal(InputIterator1 first1, InputIterator1 last1,
|
| 868 |
+
InputIterator2 first2, InputIterator2 last2);
|
| 869 |
+
template<class InputIterator1, class InputIterator2, class BinaryPredicate>
|
| 870 |
+
constexpr bool equal(InputIterator1 first1, InputIterator1 last1,
|
| 871 |
+
InputIterator2 first2, InputIterator2 last2,
|
| 872 |
+
BinaryPredicate pred);
|
| 873 |
+
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 874 |
+
bool equal(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 875 |
+
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 876 |
+
ForwardIterator2 first2);
|
| 877 |
+
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 878 |
+
class BinaryPredicate>
|
| 879 |
+
bool equal(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 880 |
+
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 881 |
+
ForwardIterator2 first2, BinaryPredicate pred);
|
| 882 |
+
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 883 |
+
bool equal(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 884 |
+
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 885 |
+
ForwardIterator2 first2, ForwardIterator2 last2);
|
| 886 |
+
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 887 |
+
class BinaryPredicate>
|
| 888 |
+
bool equal(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 889 |
+
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 890 |
+
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 891 |
+
BinaryPredicate pred);
|
| 892 |
+
|
| 893 |
+
namespace ranges {
|
| 894 |
+
template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2,
|
| 895 |
+
class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
|
| 896 |
+
requires indirectly_comparable<I1, I2, Pred, Proj1, Proj2>
|
| 897 |
+
constexpr bool equal(I1 first1, S1 last1, I2 first2, S2 last2,
|
| 898 |
+
Pred pred = {},
|
| 899 |
+
Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 900 |
+
template<input_range R1, input_range R2, class Pred = ranges::equal_to,
|
| 901 |
+
class Proj1 = identity, class Proj2 = identity>
|
| 902 |
+
requires indirectly_comparable<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
|
| 903 |
+
constexpr bool equal(R1&& r1, R2&& r2, Pred pred = {},
|
| 904 |
+
Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 905 |
+
}
|
| 906 |
+
|
| 907 |
+
// [alg.is.permutation], is permutation
|
| 908 |
+
template<class ForwardIterator1, class ForwardIterator2>
|
| 909 |
+
constexpr bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
|
| 910 |
+
ForwardIterator2 first2);
|
| 911 |
+
template<class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
|
| 912 |
+
constexpr bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
|
| 913 |
+
ForwardIterator2 first2, BinaryPredicate pred);
|
| 914 |
+
template<class ForwardIterator1, class ForwardIterator2>
|
| 915 |
+
constexpr bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
|
| 916 |
+
ForwardIterator2 first2, ForwardIterator2 last2);
|
| 917 |
+
template<class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
|
| 918 |
+
constexpr bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
|
| 919 |
+
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 920 |
+
BinaryPredicate pred);
|
| 921 |
+
|
| 922 |
+
namespace ranges {
|
| 923 |
+
template<forward_iterator I1, sentinel_for<I1> S1, forward_iterator I2,
|
| 924 |
+
sentinel_for<I2> S2, class Proj1 = identity, class Proj2 = identity,
|
| 925 |
+
indirect_equivalence_relation<projected<I1, Proj1>,
|
| 926 |
+
projected<I2, Proj2>> Pred = ranges::equal_to>
|
| 927 |
+
constexpr bool is_permutation(I1 first1, S1 last1, I2 first2, S2 last2,
|
| 928 |
+
Pred pred = {},
|
| 929 |
+
Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 930 |
+
template<forward_range R1, forward_range R2,
|
| 931 |
+
class Proj1 = identity, class Proj2 = identity,
|
| 932 |
+
indirect_equivalence_relation<projected<iterator_t<R1>, Proj1>,
|
| 933 |
+
projected<iterator_t<R2>, Proj2>>
|
| 934 |
+
Pred = ranges::equal_to>
|
| 935 |
+
constexpr bool is_permutation(R1&& r1, R2&& r2, Pred pred = {},
|
| 936 |
+
Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 937 |
+
}
|
| 938 |
+
|
| 939 |
+
// [alg.search], search
|
| 940 |
+
template<class ForwardIterator1, class ForwardIterator2>
|
| 941 |
+
constexpr ForwardIterator1
|
| 942 |
+
search(ForwardIterator1 first1, ForwardIterator1 last1,
|
| 943 |
+
ForwardIterator2 first2, ForwardIterator2 last2);
|
| 944 |
+
template<class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
|
| 945 |
+
constexpr ForwardIterator1
|
| 946 |
+
search(ForwardIterator1 first1, ForwardIterator1 last1,
|
| 947 |
+
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 948 |
+
BinaryPredicate pred);
|
| 949 |
+
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 950 |
+
ForwardIterator1
|
| 951 |
+
search(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 952 |
+
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 953 |
+
ForwardIterator2 first2, ForwardIterator2 last2);
|
| 954 |
+
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 955 |
+
class BinaryPredicate>
|
| 956 |
+
ForwardIterator1
|
| 957 |
+
search(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 958 |
+
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 959 |
+
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 960 |
+
BinaryPredicate pred);
|
| 961 |
+
|
| 962 |
+
namespace ranges {
|
| 963 |
+
template<forward_iterator I1, sentinel_for<I1> S1, forward_iterator I2,
|
| 964 |
+
sentinel_for<I2> S2, class Pred = ranges::equal_to,
|
| 965 |
+
class Proj1 = identity, class Proj2 = identity>
|
| 966 |
+
requires indirectly_comparable<I1, I2, Pred, Proj1, Proj2>
|
| 967 |
+
constexpr subrange<I1>
|
| 968 |
+
search(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {},
|
| 969 |
+
Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 970 |
+
template<forward_range R1, forward_range R2, class Pred = ranges::equal_to,
|
| 971 |
+
class Proj1 = identity, class Proj2 = identity>
|
| 972 |
+
requires indirectly_comparable<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
|
| 973 |
+
constexpr borrowed_subrange_t<R1>
|
| 974 |
+
search(R1&& r1, R2&& r2, Pred pred = {},
|
| 975 |
+
Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 976 |
+
}
|
| 977 |
+
|
| 978 |
+
template<class ForwardIterator, class Size, class T>
|
| 979 |
+
constexpr ForwardIterator
|
| 980 |
+
search_n(ForwardIterator first, ForwardIterator last,
|
| 981 |
+
Size count, const T& value);
|
| 982 |
+
template<class ForwardIterator, class Size, class T, class BinaryPredicate>
|
| 983 |
+
constexpr ForwardIterator
|
| 984 |
+
search_n(ForwardIterator first, ForwardIterator last,
|
| 985 |
+
Size count, const T& value,
|
| 986 |
+
BinaryPredicate pred);
|
| 987 |
+
template<class ExecutionPolicy, class ForwardIterator, class Size, class T>
|
| 988 |
+
ForwardIterator
|
| 989 |
+
search_n(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 990 |
+
ForwardIterator first, ForwardIterator last,
|
| 991 |
+
Size count, const T& value);
|
| 992 |
+
template<class ExecutionPolicy, class ForwardIterator, class Size, class T,
|
| 993 |
+
class BinaryPredicate>
|
| 994 |
+
ForwardIterator
|
| 995 |
+
search_n(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 996 |
+
ForwardIterator first, ForwardIterator last,
|
| 997 |
+
Size count, const T& value,
|
| 998 |
+
BinaryPredicate pred);
|
| 999 |
+
|
| 1000 |
+
namespace ranges {
|
| 1001 |
+
template<forward_iterator I, sentinel_for<I> S, class T,
|
| 1002 |
+
class Pred = ranges::equal_to, class Proj = identity>
|
| 1003 |
+
requires indirectly_comparable<I, const T*, Pred, Proj>
|
| 1004 |
+
constexpr subrange<I>
|
| 1005 |
+
search_n(I first, S last, iter_difference_t<I> count,
|
| 1006 |
+
const T& value, Pred pred = {}, Proj proj = {});
|
| 1007 |
+
template<forward_range R, class T, class Pred = ranges::equal_to,
|
| 1008 |
+
class Proj = identity>
|
| 1009 |
+
requires indirectly_comparable<iterator_t<R>, const T*, Pred, Proj>
|
| 1010 |
+
constexpr borrowed_subrange_t<R>
|
| 1011 |
+
search_n(R&& r, range_difference_t<R> count,
|
| 1012 |
+
const T& value, Pred pred = {}, Proj proj = {});
|
| 1013 |
+
}
|
| 1014 |
+
|
| 1015 |
+
template<class ForwardIterator, class Searcher>
|
| 1016 |
+
constexpr ForwardIterator
|
| 1017 |
+
search(ForwardIterator first, ForwardIterator last, const Searcher& searcher);
|
| 1018 |
+
|
| 1019 |
+
// [alg.modifying.operations], mutating sequence operations
|
| 1020 |
+
// [alg.copy], copy
|
| 1021 |
+
template<class InputIterator, class OutputIterator>
|
| 1022 |
+
constexpr OutputIterator copy(InputIterator first, InputIterator last,
|
| 1023 |
+
OutputIterator result);
|
| 1024 |
+
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 1025 |
+
ForwardIterator2 copy(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 1026 |
+
ForwardIterator1 first, ForwardIterator1 last,
|
| 1027 |
+
ForwardIterator2 result);
|
| 1028 |
+
|
| 1029 |
+
namespace ranges {
|
| 1030 |
+
template<class I, class O>
|
| 1031 |
+
using copy_result = in_out_result<I, O>;
|
| 1032 |
+
|
| 1033 |
+
template<input_iterator I, sentinel_for<I> S, weakly_incrementable O>
|
| 1034 |
+
requires indirectly_copyable<I, O>
|
| 1035 |
+
constexpr copy_result<I, O>
|
| 1036 |
+
copy(I first, S last, O result);
|
| 1037 |
+
template<input_range R, weakly_incrementable O>
|
| 1038 |
+
requires indirectly_copyable<iterator_t<R>, O>
|
| 1039 |
+
constexpr copy_result<borrowed_iterator_t<R>, O>
|
| 1040 |
+
copy(R&& r, O result);
|
| 1041 |
+
}
|
| 1042 |
+
|
| 1043 |
+
template<class InputIterator, class Size, class OutputIterator>
|
| 1044 |
+
constexpr OutputIterator copy_n(InputIterator first, Size n,
|
| 1045 |
+
OutputIterator result);
|
| 1046 |
+
template<class ExecutionPolicy, class ForwardIterator1, class Size,
|
| 1047 |
+
class ForwardIterator2>
|
| 1048 |
+
ForwardIterator2 copy_n(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 1049 |
+
ForwardIterator1 first, Size n,
|
| 1050 |
+
ForwardIterator2 result);
|
| 1051 |
+
|
| 1052 |
+
namespace ranges {
|
| 1053 |
+
template<class I, class O>
|
| 1054 |
+
using copy_n_result = in_out_result<I, O>;
|
| 1055 |
+
|
| 1056 |
+
template<input_iterator I, weakly_incrementable O>
|
| 1057 |
+
requires indirectly_copyable<I, O>
|
| 1058 |
+
constexpr copy_n_result<I, O>
|
| 1059 |
+
copy_n(I first, iter_difference_t<I> n, O result);
|
| 1060 |
+
}
|
| 1061 |
+
|
| 1062 |
+
template<class InputIterator, class OutputIterator, class Predicate>
|
| 1063 |
+
constexpr OutputIterator copy_if(InputIterator first, InputIterator last,
|
| 1064 |
+
OutputIterator result, Predicate pred);
|
| 1065 |
+
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 1066 |
+
class Predicate>
|
| 1067 |
+
ForwardIterator2 copy_if(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 1068 |
+
ForwardIterator1 first, ForwardIterator1 last,
|
| 1069 |
+
ForwardIterator2 result, Predicate pred);
|
| 1070 |
+
|
| 1071 |
+
namespace ranges {
|
| 1072 |
+
template<class I, class O>
|
| 1073 |
+
using copy_if_result = in_out_result<I, O>;
|
| 1074 |
+
|
| 1075 |
+
template<input_iterator I, sentinel_for<I> S, weakly_incrementable O, class Proj = identity,
|
| 1076 |
+
indirect_unary_predicate<projected<I, Proj>> Pred>
|
| 1077 |
+
requires indirectly_copyable<I, O>
|
| 1078 |
+
constexpr copy_if_result<I, O>
|
| 1079 |
+
copy_if(I first, S last, O result, Pred pred, Proj proj = {});
|
| 1080 |
+
template<input_range R, weakly_incrementable O, class Proj = identity,
|
| 1081 |
+
indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
|
| 1082 |
+
requires indirectly_copyable<iterator_t<R>, O>
|
| 1083 |
+
constexpr copy_if_result<borrowed_iterator_t<R>, O>
|
| 1084 |
+
copy_if(R&& r, O result, Pred pred, Proj proj = {});
|
| 1085 |
+
}
|
| 1086 |
+
|
| 1087 |
+
template<class BidirectionalIterator1, class BidirectionalIterator2>
|
| 1088 |
+
constexpr BidirectionalIterator2
|
| 1089 |
+
copy_backward(BidirectionalIterator1 first, BidirectionalIterator1 last,
|
| 1090 |
+
BidirectionalIterator2 result);
|
| 1091 |
+
|
| 1092 |
+
namespace ranges {
|
| 1093 |
+
template<class I1, class I2>
|
| 1094 |
+
using copy_backward_result = in_out_result<I1, I2>;
|
| 1095 |
+
|
| 1096 |
+
template<bidirectional_iterator I1, sentinel_for<I1> S1, bidirectional_iterator I2>
|
| 1097 |
+
requires indirectly_copyable<I1, I2>
|
| 1098 |
+
constexpr copy_backward_result<I1, I2>
|
| 1099 |
+
copy_backward(I1 first, S1 last, I2 result);
|
| 1100 |
+
template<bidirectional_range R, bidirectional_iterator I>
|
| 1101 |
+
requires indirectly_copyable<iterator_t<R>, I>
|
| 1102 |
+
constexpr copy_backward_result<borrowed_iterator_t<R>, I>
|
| 1103 |
+
copy_backward(R&& r, I result);
|
| 1104 |
+
}
|
| 1105 |
+
|
| 1106 |
+
// [alg.move], move
|
| 1107 |
+
template<class InputIterator, class OutputIterator>
|
| 1108 |
+
constexpr OutputIterator move(InputIterator first, InputIterator last,
|
| 1109 |
+
OutputIterator result);
|
| 1110 |
+
template<class ExecutionPolicy, class ForwardIterator1,
|
| 1111 |
+
class ForwardIterator2>
|
| 1112 |
+
ForwardIterator2 move(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 1113 |
+
ForwardIterator1 first, ForwardIterator1 last,
|
| 1114 |
+
ForwardIterator2 result);
|
| 1115 |
+
|
| 1116 |
+
namespace ranges {
|
| 1117 |
+
template<class I, class O>
|
| 1118 |
+
using move_result = in_out_result<I, O>;
|
| 1119 |
+
|
| 1120 |
+
template<input_iterator I, sentinel_for<I> S, weakly_incrementable O>
|
| 1121 |
+
requires indirectly_movable<I, O>
|
| 1122 |
+
constexpr move_result<I, O>
|
| 1123 |
+
move(I first, S last, O result);
|
| 1124 |
+
template<input_range R, weakly_incrementable O>
|
| 1125 |
+
requires indirectly_movable<iterator_t<R>, O>
|
| 1126 |
+
constexpr move_result<borrowed_iterator_t<R>, O>
|
| 1127 |
+
move(R&& r, O result);
|
| 1128 |
+
}
|
| 1129 |
+
|
| 1130 |
+
template<class BidirectionalIterator1, class BidirectionalIterator2>
|
| 1131 |
+
constexpr BidirectionalIterator2
|
| 1132 |
+
move_backward(BidirectionalIterator1 first, BidirectionalIterator1 last,
|
| 1133 |
+
BidirectionalIterator2 result);
|
| 1134 |
+
|
| 1135 |
+
namespace ranges {
|
| 1136 |
+
template<class I1, class I2>
|
| 1137 |
+
using move_backward_result = in_out_result<I1, I2>;
|
| 1138 |
+
|
| 1139 |
+
template<bidirectional_iterator I1, sentinel_for<I1> S1, bidirectional_iterator I2>
|
| 1140 |
+
requires indirectly_movable<I1, I2>
|
| 1141 |
+
constexpr move_backward_result<I1, I2>
|
| 1142 |
+
move_backward(I1 first, S1 last, I2 result);
|
| 1143 |
+
template<bidirectional_range R, bidirectional_iterator I>
|
| 1144 |
+
requires indirectly_movable<iterator_t<R>, I>
|
| 1145 |
+
constexpr move_backward_result<borrowed_iterator_t<R>, I>
|
| 1146 |
+
move_backward(R&& r, I result);
|
| 1147 |
+
}
|
| 1148 |
+
|
| 1149 |
+
// [alg.swap], swap
|
| 1150 |
+
template<class ForwardIterator1, class ForwardIterator2>
|
| 1151 |
+
constexpr ForwardIterator2 swap_ranges(ForwardIterator1 first1, ForwardIterator1 last1,
|
| 1152 |
+
ForwardIterator2 first2);
|
| 1153 |
+
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 1154 |
+
ForwardIterator2 swap_ranges(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 1155 |
+
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 1156 |
+
ForwardIterator2 first2);
|
| 1157 |
+
|
| 1158 |
+
namespace ranges {
|
| 1159 |
+
template<class I1, class I2>
|
| 1160 |
+
using swap_ranges_result = in_in_result<I1, I2>;
|
| 1161 |
+
|
| 1162 |
+
template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2>
|
| 1163 |
+
requires indirectly_swappable<I1, I2>
|
| 1164 |
+
constexpr swap_ranges_result<I1, I2>
|
| 1165 |
+
swap_ranges(I1 first1, S1 last1, I2 first2, S2 last2);
|
| 1166 |
+
template<input_range R1, input_range R2>
|
| 1167 |
+
requires indirectly_swappable<iterator_t<R1>, iterator_t<R2>>
|
| 1168 |
+
constexpr swap_ranges_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>>
|
| 1169 |
+
swap_ranges(R1&& r1, R2&& r2);
|
| 1170 |
+
}
|
| 1171 |
+
|
| 1172 |
+
template<class ForwardIterator1, class ForwardIterator2>
|
| 1173 |
+
constexpr void iter_swap(ForwardIterator1 a, ForwardIterator2 b);
|
| 1174 |
+
|
| 1175 |
+
// [alg.transform], transform
|
| 1176 |
+
template<class InputIterator, class OutputIterator, class UnaryOperation>
|
| 1177 |
+
constexpr OutputIterator
|
| 1178 |
+
transform(InputIterator first1, InputIterator last1,
|
| 1179 |
+
OutputIterator result, UnaryOperation op);
|
| 1180 |
+
template<class InputIterator1, class InputIterator2, class OutputIterator,
|
| 1181 |
+
class BinaryOperation>
|
| 1182 |
+
constexpr OutputIterator
|
| 1183 |
+
transform(InputIterator1 first1, InputIterator1 last1,
|
| 1184 |
+
InputIterator2 first2, OutputIterator result,
|
| 1185 |
+
BinaryOperation binary_op);
|
| 1186 |
+
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 1187 |
+
class UnaryOperation>
|
| 1188 |
+
ForwardIterator2
|
| 1189 |
+
transform(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 1190 |
+
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 1191 |
+
ForwardIterator2 result, UnaryOperation op);
|
| 1192 |
+
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 1193 |
+
class ForwardIterator, class BinaryOperation>
|
| 1194 |
+
ForwardIterator
|
| 1195 |
+
transform(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 1196 |
+
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 1197 |
+
ForwardIterator2 first2, ForwardIterator result,
|
| 1198 |
+
BinaryOperation binary_op);
|
| 1199 |
+
|
| 1200 |
+
namespace ranges {
|
| 1201 |
+
template<class I, class O>
|
| 1202 |
+
using unary_transform_result = in_out_result<I, O>;
|
| 1203 |
+
|
| 1204 |
+
template<input_iterator I, sentinel_for<I> S, weakly_incrementable O,
|
| 1205 |
+
copy_constructible F, class Proj = identity>
|
| 1206 |
+
requires indirectly_writable<O, indirect_result_t<F&, projected<I, Proj>>>
|
| 1207 |
+
constexpr unary_transform_result<I, O>
|
| 1208 |
+
transform(I first1, S last1, O result, F op, Proj proj = {});
|
| 1209 |
+
template<input_range R, weakly_incrementable O, copy_constructible F,
|
| 1210 |
+
class Proj = identity>
|
| 1211 |
+
requires indirectly_writable<O, indirect_result_t<F&, projected<iterator_t<R>, Proj>>>
|
| 1212 |
+
constexpr unary_transform_result<borrowed_iterator_t<R>, O>
|
| 1213 |
+
transform(R&& r, O result, F op, Proj proj = {});
|
| 1214 |
+
|
| 1215 |
+
template<class I1, class I2, class O>
|
| 1216 |
+
using binary_transform_result = in_in_out_result<I1, I2, O>;
|
| 1217 |
+
|
| 1218 |
+
template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2,
|
| 1219 |
+
weakly_incrementable O, copy_constructible F, class Proj1 = identity,
|
| 1220 |
+
class Proj2 = identity>
|
| 1221 |
+
requires indirectly_writable<O, indirect_result_t<F&, projected<I1, Proj1>,
|
| 1222 |
+
projected<I2, Proj2>>>
|
| 1223 |
+
constexpr binary_transform_result<I1, I2, O>
|
| 1224 |
+
transform(I1 first1, S1 last1, I2 first2, S2 last2, O result,
|
| 1225 |
+
F binary_op, Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 1226 |
+
template<input_range R1, input_range R2, weakly_incrementable O,
|
| 1227 |
+
copy_constructible F, class Proj1 = identity, class Proj2 = identity>
|
| 1228 |
+
requires indirectly_writable<O, indirect_result_t<F&, projected<iterator_t<R1>, Proj1>,
|
| 1229 |
+
projected<iterator_t<R2>, Proj2>>>
|
| 1230 |
+
constexpr binary_transform_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>, O>
|
| 1231 |
+
transform(R1&& r1, R2&& r2, O result,
|
| 1232 |
+
F binary_op, Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 1233 |
+
}
|
| 1234 |
+
|
| 1235 |
+
// [alg.replace], replace
|
| 1236 |
+
template<class ForwardIterator, class T>
|
| 1237 |
+
constexpr void replace(ForwardIterator first, ForwardIterator last,
|
| 1238 |
+
const T& old_value, const T& new_value);
|
| 1239 |
+
template<class ExecutionPolicy, class ForwardIterator, class T>
|
| 1240 |
+
void replace(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 1241 |
+
ForwardIterator first, ForwardIterator last,
|
| 1242 |
+
const T& old_value, const T& new_value);
|
| 1243 |
+
template<class ForwardIterator, class Predicate, class T>
|
| 1244 |
+
constexpr void replace_if(ForwardIterator first, ForwardIterator last,
|
| 1245 |
+
Predicate pred, const T& new_value);
|
| 1246 |
+
template<class ExecutionPolicy, class ForwardIterator, class Predicate, class T>
|
| 1247 |
+
void replace_if(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 1248 |
+
ForwardIterator first, ForwardIterator last,
|
| 1249 |
+
Predicate pred, const T& new_value);
|
| 1250 |
+
|
| 1251 |
+
namespace ranges {
|
| 1252 |
+
template<input_iterator I, sentinel_for<I> S, class T1, class T2, class Proj = identity>
|
| 1253 |
+
requires indirectly_writable<I, const T2&> &&
|
| 1254 |
+
indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T1*>
|
| 1255 |
+
constexpr I
|
| 1256 |
+
replace(I first, S last, const T1& old_value, const T2& new_value, Proj proj = {});
|
| 1257 |
+
template<input_range R, class T1, class T2, class Proj = identity>
|
| 1258 |
+
requires indirectly_writable<iterator_t<R>, const T2&> &&
|
| 1259 |
+
indirect_binary_predicate<ranges::equal_to,
|
| 1260 |
+
projected<iterator_t<R>, Proj>, const T1*>
|
| 1261 |
+
constexpr borrowed_iterator_t<R>
|
| 1262 |
+
replace(R&& r, const T1& old_value, const T2& new_value, Proj proj = {});
|
| 1263 |
+
template<input_iterator I, sentinel_for<I> S, class T, class Proj = identity,
|
| 1264 |
+
indirect_unary_predicate<projected<I, Proj>> Pred>
|
| 1265 |
+
requires indirectly_writable<I, const T&>
|
| 1266 |
+
constexpr I replace_if(I first, S last, Pred pred, const T& new_value, Proj proj = {});
|
| 1267 |
+
template<input_range R, class T, class Proj = identity,
|
| 1268 |
+
indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
|
| 1269 |
+
requires indirectly_writable<iterator_t<R>, const T&>
|
| 1270 |
+
constexpr borrowed_iterator_t<R>
|
| 1271 |
+
replace_if(R&& r, Pred pred, const T& new_value, Proj proj = {});
|
| 1272 |
+
}
|
| 1273 |
+
|
| 1274 |
+
template<class InputIterator, class OutputIterator, class T>
|
| 1275 |
+
constexpr OutputIterator replace_copy(InputIterator first, InputIterator last,
|
| 1276 |
+
OutputIterator result,
|
| 1277 |
+
const T& old_value, const T& new_value);
|
| 1278 |
+
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class T>
|
| 1279 |
+
ForwardIterator2 replace_copy(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 1280 |
+
ForwardIterator1 first, ForwardIterator1 last,
|
| 1281 |
+
ForwardIterator2 result,
|
| 1282 |
+
const T& old_value, const T& new_value);
|
| 1283 |
+
template<class InputIterator, class OutputIterator, class Predicate, class T>
|
| 1284 |
+
constexpr OutputIterator replace_copy_if(InputIterator first, InputIterator last,
|
| 1285 |
+
OutputIterator result,
|
| 1286 |
+
Predicate pred, const T& new_value);
|
| 1287 |
+
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 1288 |
+
class Predicate, class T>
|
| 1289 |
+
ForwardIterator2 replace_copy_if(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 1290 |
+
ForwardIterator1 first, ForwardIterator1 last,
|
| 1291 |
+
ForwardIterator2 result,
|
| 1292 |
+
Predicate pred, const T& new_value);
|
| 1293 |
+
|
| 1294 |
+
namespace ranges {
|
| 1295 |
+
template<class I, class O>
|
| 1296 |
+
using replace_copy_result = in_out_result<I, O>;
|
| 1297 |
+
|
| 1298 |
+
template<input_iterator I, sentinel_for<I> S, class T1, class T2,
|
| 1299 |
+
output_iterator<const T2&> O, class Proj = identity>
|
| 1300 |
+
requires indirectly_copyable<I, O> &&
|
| 1301 |
+
indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T1*>
|
| 1302 |
+
constexpr replace_copy_result<I, O>
|
| 1303 |
+
replace_copy(I first, S last, O result, const T1& old_value, const T2& new_value,
|
| 1304 |
+
Proj proj = {});
|
| 1305 |
+
template<input_range R, class T1, class T2, output_iterator<const T2&> O,
|
| 1306 |
+
class Proj = identity>
|
| 1307 |
+
requires indirectly_copyable<iterator_t<R>, O> &&
|
| 1308 |
+
indirect_binary_predicate<ranges::equal_to,
|
| 1309 |
+
projected<iterator_t<R>, Proj>, const T1*>
|
| 1310 |
+
constexpr replace_copy_result<borrowed_iterator_t<R>, O>
|
| 1311 |
+
replace_copy(R&& r, O result, const T1& old_value, const T2& new_value,
|
| 1312 |
+
Proj proj = {});
|
| 1313 |
+
|
| 1314 |
+
template<class I, class O>
|
| 1315 |
+
using replace_copy_if_result = in_out_result<I, O>;
|
| 1316 |
+
|
| 1317 |
+
template<input_iterator I, sentinel_for<I> S, class T, output_iterator<const T&> O,
|
| 1318 |
+
class Proj = identity, indirect_unary_predicate<projected<I, Proj>> Pred>
|
| 1319 |
+
requires indirectly_copyable<I, O>
|
| 1320 |
+
constexpr replace_copy_if_result<I, O>
|
| 1321 |
+
replace_copy_if(I first, S last, O result, Pred pred, const T& new_value,
|
| 1322 |
+
Proj proj = {});
|
| 1323 |
+
template<input_range R, class T, output_iterator<const T&> O, class Proj = identity,
|
| 1324 |
+
indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
|
| 1325 |
+
requires indirectly_copyable<iterator_t<R>, O>
|
| 1326 |
+
constexpr replace_copy_if_result<borrowed_iterator_t<R>, O>
|
| 1327 |
+
replace_copy_if(R&& r, O result, Pred pred, const T& new_value,
|
| 1328 |
+
Proj proj = {});
|
| 1329 |
+
}
|
| 1330 |
+
|
| 1331 |
+
// [alg.fill], fill
|
| 1332 |
+
template<class ForwardIterator, class T>
|
| 1333 |
+
constexpr void fill(ForwardIterator first, ForwardIterator last, const T& value);
|
| 1334 |
+
template<class ExecutionPolicy, class ForwardIterator, class T>
|
| 1335 |
+
void fill(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 1336 |
+
ForwardIterator first, ForwardIterator last, const T& value);
|
| 1337 |
+
template<class OutputIterator, class Size, class T>
|
| 1338 |
+
constexpr OutputIterator fill_n(OutputIterator first, Size n, const T& value);
|
| 1339 |
+
template<class ExecutionPolicy, class ForwardIterator,
|
| 1340 |
+
class Size, class T>
|
| 1341 |
+
ForwardIterator fill_n(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 1342 |
+
ForwardIterator first, Size n, const T& value);
|
| 1343 |
+
|
| 1344 |
+
namespace ranges {
|
| 1345 |
+
template<class T, output_iterator<const T&> O, sentinel_for<O> S>
|
| 1346 |
+
constexpr O fill(O first, S last, const T& value);
|
| 1347 |
+
template<class T, output_range<const T&> R>
|
| 1348 |
+
constexpr borrowed_iterator_t<R> fill(R&& r, const T& value);
|
| 1349 |
+
template<class T, output_iterator<const T&> O>
|
| 1350 |
+
constexpr O fill_n(O first, iter_difference_t<O> n, const T& value);
|
| 1351 |
+
}
|
| 1352 |
+
|
| 1353 |
+
// [alg.generate], generate
|
| 1354 |
+
template<class ForwardIterator, class Generator>
|
| 1355 |
+
constexpr void generate(ForwardIterator first, ForwardIterator last,
|
| 1356 |
+
Generator gen);
|
| 1357 |
+
template<class ExecutionPolicy, class ForwardIterator, class Generator>
|
| 1358 |
+
void generate(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 1359 |
+
ForwardIterator first, ForwardIterator last,
|
| 1360 |
+
Generator gen);
|
| 1361 |
+
template<class OutputIterator, class Size, class Generator>
|
| 1362 |
+
constexpr OutputIterator generate_n(OutputIterator first, Size n, Generator gen);
|
| 1363 |
+
template<class ExecutionPolicy, class ForwardIterator, class Size, class Generator>
|
| 1364 |
+
ForwardIterator generate_n(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 1365 |
+
ForwardIterator first, Size n, Generator gen);
|
| 1366 |
+
|
| 1367 |
+
namespace ranges {
|
| 1368 |
+
template<input_or_output_iterator O, sentinel_for<O> S, copy_constructible F>
|
| 1369 |
+
requires invocable<F&> && indirectly_writable<O, invoke_result_t<F&>>
|
| 1370 |
+
constexpr O generate(O first, S last, F gen);
|
| 1371 |
+
template<class R, copy_constructible F>
|
| 1372 |
+
requires invocable<F&> && output_range<R, invoke_result_t<F&>>
|
| 1373 |
+
constexpr borrowed_iterator_t<R> generate(R&& r, F gen);
|
| 1374 |
+
template<input_or_output_iterator O, copy_constructible F>
|
| 1375 |
+
requires invocable<F&> && indirectly_writable<O, invoke_result_t<F&>>
|
| 1376 |
+
constexpr O generate_n(O first, iter_difference_t<O> n, F gen);
|
| 1377 |
+
}
|
| 1378 |
+
|
| 1379 |
+
// [alg.remove], remove
|
| 1380 |
+
template<class ForwardIterator, class T>
|
| 1381 |
+
constexpr ForwardIterator remove(ForwardIterator first, ForwardIterator last,
|
| 1382 |
+
const T& value);
|
| 1383 |
+
template<class ExecutionPolicy, class ForwardIterator, class T>
|
| 1384 |
+
ForwardIterator remove(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 1385 |
+
ForwardIterator first, ForwardIterator last,
|
| 1386 |
+
const T& value);
|
| 1387 |
+
template<class ForwardIterator, class Predicate>
|
| 1388 |
+
constexpr ForwardIterator remove_if(ForwardIterator first, ForwardIterator last,
|
| 1389 |
+
Predicate pred);
|
| 1390 |
+
template<class ExecutionPolicy, class ForwardIterator, class Predicate>
|
| 1391 |
+
ForwardIterator remove_if(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 1392 |
+
ForwardIterator first, ForwardIterator last,
|
| 1393 |
+
Predicate pred);
|
| 1394 |
+
|
| 1395 |
+
namespace ranges {
|
| 1396 |
+
template<permutable I, sentinel_for<I> S, class T, class Proj = identity>
|
| 1397 |
+
requires indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T*>
|
| 1398 |
+
constexpr subrange<I> remove(I first, S last, const T& value, Proj proj = {});
|
| 1399 |
+
template<forward_range R, class T, class Proj = identity>
|
| 1400 |
+
requires permutable<iterator_t<R>> &&
|
| 1401 |
+
indirect_binary_predicate<ranges::equal_to,
|
| 1402 |
+
projected<iterator_t<R>, Proj>, const T*>
|
| 1403 |
+
constexpr borrowed_subrange_t<R>
|
| 1404 |
+
remove(R&& r, const T& value, Proj proj = {});
|
| 1405 |
+
template<permutable I, sentinel_for<I> S, class Proj = identity,
|
| 1406 |
+
indirect_unary_predicate<projected<I, Proj>> Pred>
|
| 1407 |
+
constexpr subrange<I> remove_if(I first, S last, Pred pred, Proj proj = {});
|
| 1408 |
+
template<forward_range R, class Proj = identity,
|
| 1409 |
+
indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
|
| 1410 |
+
requires permutable<iterator_t<R>>
|
| 1411 |
+
constexpr borrowed_subrange_t<R>
|
| 1412 |
+
remove_if(R&& r, Pred pred, Proj proj = {});
|
| 1413 |
+
}
|
| 1414 |
+
|
| 1415 |
+
template<class InputIterator, class OutputIterator, class T>
|
| 1416 |
+
constexpr OutputIterator
|
| 1417 |
+
remove_copy(InputIterator first, InputIterator last,
|
| 1418 |
+
OutputIterator result, const T& value);
|
| 1419 |
+
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 1420 |
+
class T>
|
| 1421 |
+
ForwardIterator2
|
| 1422 |
+
remove_copy(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 1423 |
+
ForwardIterator1 first, ForwardIterator1 last,
|
| 1424 |
+
ForwardIterator2 result, const T& value);
|
| 1425 |
+
template<class InputIterator, class OutputIterator, class Predicate>
|
| 1426 |
+
constexpr OutputIterator
|
| 1427 |
+
remove_copy_if(InputIterator first, InputIterator last,
|
| 1428 |
+
OutputIterator result, Predicate pred);
|
| 1429 |
+
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 1430 |
+
class Predicate>
|
| 1431 |
+
ForwardIterator2
|
| 1432 |
+
remove_copy_if(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 1433 |
+
ForwardIterator1 first, ForwardIterator1 last,
|
| 1434 |
+
ForwardIterator2 result, Predicate pred);
|
| 1435 |
+
|
| 1436 |
+
namespace ranges {
|
| 1437 |
+
template<class I, class O>
|
| 1438 |
+
using remove_copy_result = in_out_result<I, O>;
|
| 1439 |
+
|
| 1440 |
+
template<input_iterator I, sentinel_for<I> S, weakly_incrementable O, class T,
|
| 1441 |
+
class Proj = identity>
|
| 1442 |
+
requires indirectly_copyable<I, O> &&
|
| 1443 |
+
indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T*>
|
| 1444 |
+
constexpr remove_copy_result<I, O>
|
| 1445 |
+
remove_copy(I first, S last, O result, const T& value, Proj proj = {});
|
| 1446 |
+
template<input_range R, weakly_incrementable O, class T, class Proj = identity>
|
| 1447 |
+
requires indirectly_copyable<iterator_t<R>, O> &&
|
| 1448 |
+
indirect_binary_predicate<ranges::equal_to,
|
| 1449 |
+
projected<iterator_t<R>, Proj>, const T*>
|
| 1450 |
+
constexpr remove_copy_result<borrowed_iterator_t<R>, O>
|
| 1451 |
+
remove_copy(R&& r, O result, const T& value, Proj proj = {});
|
| 1452 |
+
|
| 1453 |
+
template<class I, class O>
|
| 1454 |
+
using remove_copy_if_result = in_out_result<I, O>;
|
| 1455 |
+
|
| 1456 |
+
template<input_iterator I, sentinel_for<I> S, weakly_incrementable O,
|
| 1457 |
+
class Proj = identity, indirect_unary_predicate<projected<I, Proj>> Pred>
|
| 1458 |
+
requires indirectly_copyable<I, O>
|
| 1459 |
+
constexpr remove_copy_if_result<I, O>
|
| 1460 |
+
remove_copy_if(I first, S last, O result, Pred pred, Proj proj = {});
|
| 1461 |
+
template<input_range R, weakly_incrementable O, class Proj = identity,
|
| 1462 |
+
indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
|
| 1463 |
+
requires indirectly_copyable<iterator_t<R>, O>
|
| 1464 |
+
constexpr remove_copy_if_result<borrowed_iterator_t<R>, O>
|
| 1465 |
+
remove_copy_if(R&& r, O result, Pred pred, Proj proj = {});
|
| 1466 |
+
}
|
| 1467 |
+
|
| 1468 |
+
// [alg.unique], unique
|
| 1469 |
+
template<class ForwardIterator>
|
| 1470 |
+
constexpr ForwardIterator unique(ForwardIterator first, ForwardIterator last);
|
| 1471 |
+
template<class ForwardIterator, class BinaryPredicate>
|
| 1472 |
+
constexpr ForwardIterator unique(ForwardIterator first, ForwardIterator last,
|
| 1473 |
+
BinaryPredicate pred);
|
| 1474 |
+
template<class ExecutionPolicy, class ForwardIterator>
|
| 1475 |
+
ForwardIterator unique(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 1476 |
+
ForwardIterator first, ForwardIterator last);
|
| 1477 |
+
template<class ExecutionPolicy, class ForwardIterator, class BinaryPredicate>
|
| 1478 |
+
ForwardIterator unique(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 1479 |
+
ForwardIterator first, ForwardIterator last,
|
| 1480 |
+
BinaryPredicate pred);
|
| 1481 |
+
|
| 1482 |
+
namespace ranges {
|
| 1483 |
+
template<permutable I, sentinel_for<I> S, class Proj = identity,
|
| 1484 |
+
indirect_equivalence_relation<projected<I, Proj>> C = ranges::equal_to>
|
| 1485 |
+
constexpr subrange<I> unique(I first, S last, C comp = {}, Proj proj = {});
|
| 1486 |
+
template<forward_range R, class Proj = identity,
|
| 1487 |
+
indirect_equivalence_relation<projected<iterator_t<R>, Proj>> C = ranges::equal_to>
|
| 1488 |
+
requires permutable<iterator_t<R>>
|
| 1489 |
+
constexpr borrowed_subrange_t<R>
|
| 1490 |
+
unique(R&& r, C comp = {}, Proj proj = {});
|
| 1491 |
+
}
|
| 1492 |
+
|
| 1493 |
+
template<class InputIterator, class OutputIterator>
|
| 1494 |
+
constexpr OutputIterator
|
| 1495 |
+
unique_copy(InputIterator first, InputIterator last,
|
| 1496 |
+
OutputIterator result);
|
| 1497 |
+
template<class InputIterator, class OutputIterator, class BinaryPredicate>
|
| 1498 |
+
constexpr OutputIterator
|
| 1499 |
+
unique_copy(InputIterator first, InputIterator last,
|
| 1500 |
+
OutputIterator result, BinaryPredicate pred);
|
| 1501 |
+
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 1502 |
+
ForwardIterator2
|
| 1503 |
+
unique_copy(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 1504 |
+
ForwardIterator1 first, ForwardIterator1 last,
|
| 1505 |
+
ForwardIterator2 result);
|
| 1506 |
+
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 1507 |
+
class BinaryPredicate>
|
| 1508 |
+
ForwardIterator2
|
| 1509 |
+
unique_copy(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 1510 |
+
ForwardIterator1 first, ForwardIterator1 last,
|
| 1511 |
+
ForwardIterator2 result, BinaryPredicate pred);
|
| 1512 |
+
|
| 1513 |
+
namespace ranges {
|
| 1514 |
+
template<class I, class O>
|
| 1515 |
+
using unique_copy_result = in_out_result<I, O>;
|
| 1516 |
+
|
| 1517 |
+
template<input_iterator I, sentinel_for<I> S, weakly_incrementable O, class Proj = identity,
|
| 1518 |
+
indirect_equivalence_relation<projected<I, Proj>> C = ranges::equal_to>
|
| 1519 |
+
requires indirectly_copyable<I, O> &&
|
| 1520 |
+
(forward_iterator<I> ||
|
| 1521 |
+
(input_iterator<O> && same_as<iter_value_t<I>, iter_value_t<O>>) ||
|
| 1522 |
+
indirectly_copyable_storable<I, O>)
|
| 1523 |
+
constexpr unique_copy_result<I, O>
|
| 1524 |
+
unique_copy(I first, S last, O result, C comp = {}, Proj proj = {});
|
| 1525 |
+
template<input_range R, weakly_incrementable O, class Proj = identity,
|
| 1526 |
+
indirect_equivalence_relation<projected<iterator_t<R>, Proj>> C = ranges::equal_to>
|
| 1527 |
+
requires indirectly_copyable<iterator_t<R>, O> &&
|
| 1528 |
+
(forward_iterator<iterator_t<R>> ||
|
| 1529 |
+
(input_iterator<O> && same_as<range_value_t<R>, iter_value_t<O>>) ||
|
| 1530 |
+
indirectly_copyable_storable<iterator_t<R>, O>)
|
| 1531 |
+
constexpr unique_copy_result<borrowed_iterator_t<R>, O>
|
| 1532 |
+
unique_copy(R&& r, O result, C comp = {}, Proj proj = {});
|
| 1533 |
+
}
|
| 1534 |
+
|
| 1535 |
+
// [alg.reverse], reverse
|
| 1536 |
+
template<class BidirectionalIterator>
|
| 1537 |
+
constexpr void reverse(BidirectionalIterator first, BidirectionalIterator last);
|
| 1538 |
+
template<class ExecutionPolicy, class BidirectionalIterator>
|
| 1539 |
+
void reverse(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 1540 |
+
BidirectionalIterator first, BidirectionalIterator last);
|
| 1541 |
+
|
| 1542 |
+
namespace ranges {
|
| 1543 |
+
template<bidirectional_iterator I, sentinel_for<I> S>
|
| 1544 |
+
requires permutable<I>
|
| 1545 |
+
constexpr I reverse(I first, S last);
|
| 1546 |
+
template<bidirectional_range R>
|
| 1547 |
+
requires permutable<iterator_t<R>>
|
| 1548 |
+
constexpr borrowed_iterator_t<R> reverse(R&& r);
|
| 1549 |
+
}
|
| 1550 |
+
|
| 1551 |
+
template<class BidirectionalIterator, class OutputIterator>
|
| 1552 |
+
constexpr OutputIterator
|
| 1553 |
+
reverse_copy(BidirectionalIterator first, BidirectionalIterator last,
|
| 1554 |
+
OutputIterator result);
|
| 1555 |
+
template<class ExecutionPolicy, class BidirectionalIterator, class ForwardIterator>
|
| 1556 |
+
ForwardIterator
|
| 1557 |
+
reverse_copy(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 1558 |
+
BidirectionalIterator first, BidirectionalIterator last,
|
| 1559 |
+
ForwardIterator result);
|
| 1560 |
+
|
| 1561 |
+
namespace ranges {
|
| 1562 |
+
template<class I, class O>
|
| 1563 |
+
using reverse_copy_result = in_out_result<I, O>;
|
| 1564 |
+
|
| 1565 |
+
template<bidirectional_iterator I, sentinel_for<I> S, weakly_incrementable O>
|
| 1566 |
+
requires indirectly_copyable<I, O>
|
| 1567 |
+
constexpr reverse_copy_result<I, O>
|
| 1568 |
+
reverse_copy(I first, S last, O result);
|
| 1569 |
+
template<bidirectional_range R, weakly_incrementable O>
|
| 1570 |
+
requires indirectly_copyable<iterator_t<R>, O>
|
| 1571 |
+
constexpr reverse_copy_result<borrowed_iterator_t<R>, O>
|
| 1572 |
+
reverse_copy(R&& r, O result);
|
| 1573 |
+
}
|
| 1574 |
+
|
| 1575 |
+
// [alg.rotate], rotate
|
| 1576 |
+
template<class ForwardIterator>
|
| 1577 |
+
constexpr ForwardIterator rotate(ForwardIterator first,
|
| 1578 |
+
ForwardIterator middle,
|
| 1579 |
+
ForwardIterator last);
|
| 1580 |
+
template<class ExecutionPolicy, class ForwardIterator>
|
| 1581 |
+
ForwardIterator rotate(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 1582 |
+
ForwardIterator first,
|
| 1583 |
+
ForwardIterator middle,
|
| 1584 |
+
ForwardIterator last);
|
| 1585 |
+
|
| 1586 |
+
namespace ranges {
|
| 1587 |
+
template<permutable I, sentinel_for<I> S>
|
| 1588 |
+
constexpr subrange<I> rotate(I first, I middle, S last);
|
| 1589 |
+
template<forward_range R>
|
| 1590 |
+
requires permutable<iterator_t<R>>
|
| 1591 |
+
constexpr borrowed_subrange_t<R> rotate(R&& r, iterator_t<R> middle);
|
| 1592 |
+
}
|
| 1593 |
+
|
| 1594 |
+
template<class ForwardIterator, class OutputIterator>
|
| 1595 |
+
constexpr OutputIterator
|
| 1596 |
+
rotate_copy(ForwardIterator first, ForwardIterator middle,
|
| 1597 |
+
ForwardIterator last, OutputIterator result);
|
| 1598 |
+
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 1599 |
+
ForwardIterator2
|
| 1600 |
+
rotate_copy(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 1601 |
+
ForwardIterator1 first, ForwardIterator1 middle,
|
| 1602 |
+
ForwardIterator1 last, ForwardIterator2 result);
|
| 1603 |
+
|
| 1604 |
+
namespace ranges {
|
| 1605 |
+
template<class I, class O>
|
| 1606 |
+
using rotate_copy_result = in_out_result<I, O>;
|
| 1607 |
+
|
| 1608 |
+
template<forward_iterator I, sentinel_for<I> S, weakly_incrementable O>
|
| 1609 |
+
requires indirectly_copyable<I, O>
|
| 1610 |
+
constexpr rotate_copy_result<I, O>
|
| 1611 |
+
rotate_copy(I first, I middle, S last, O result);
|
| 1612 |
+
template<forward_range R, weakly_incrementable O>
|
| 1613 |
+
requires indirectly_copyable<iterator_t<R>, O>
|
| 1614 |
+
constexpr rotate_copy_result<borrowed_iterator_t<R>, O>
|
| 1615 |
+
rotate_copy(R&& r, iterator_t<R> middle, O result);
|
| 1616 |
+
}
|
| 1617 |
+
|
| 1618 |
+
// [alg.random.sample], sample
|
| 1619 |
+
template<class PopulationIterator, class SampleIterator,
|
| 1620 |
+
class Distance, class UniformRandomBitGenerator>
|
| 1621 |
+
SampleIterator sample(PopulationIterator first, PopulationIterator last,
|
| 1622 |
+
SampleIterator out, Distance n,
|
| 1623 |
+
UniformRandomBitGenerator&& g);
|
| 1624 |
+
|
| 1625 |
+
namespace ranges {
|
| 1626 |
+
template<input_iterator I, sentinel_for<I> S,
|
| 1627 |
+
weakly_incrementable O, class Gen>
|
| 1628 |
+
requires (forward_iterator<I> || random_access_iterator<O>) &&
|
| 1629 |
+
indirectly_copyable<I, O> &&
|
| 1630 |
+
uniform_random_bit_generator<remove_reference_t<Gen>>
|
| 1631 |
+
O sample(I first, S last, O out, iter_difference_t<I> n, Gen&& g);
|
| 1632 |
+
template<input_range R, weakly_incrementable O, class Gen>
|
| 1633 |
+
requires (forward_range<R> || random_access_iterator<O>) &&
|
| 1634 |
+
indirectly_copyable<iterator_t<R>, O> &&
|
| 1635 |
+
uniform_random_bit_generator<remove_reference_t<Gen>>
|
| 1636 |
+
O sample(R&& r, O out, range_difference_t<R> n, Gen&& g);
|
| 1637 |
+
}
|
| 1638 |
+
|
| 1639 |
+
// [alg.random.shuffle], shuffle
|
| 1640 |
+
template<class RandomAccessIterator, class UniformRandomBitGenerator>
|
| 1641 |
+
void shuffle(RandomAccessIterator first,
|
| 1642 |
+
RandomAccessIterator last,
|
| 1643 |
+
UniformRandomBitGenerator&& g);
|
| 1644 |
+
|
| 1645 |
+
namespace ranges {
|
| 1646 |
+
template<random_access_iterator I, sentinel_for<I> S, class Gen>
|
| 1647 |
+
requires permutable<I> &&
|
| 1648 |
+
uniform_random_bit_generator<remove_reference_t<Gen>>
|
| 1649 |
+
I shuffle(I first, S last, Gen&& g);
|
| 1650 |
+
template<random_access_range R, class Gen>
|
| 1651 |
+
requires permutable<iterator_t<R>> &&
|
| 1652 |
+
uniform_random_bit_generator<remove_reference_t<Gen>>
|
| 1653 |
+
borrowed_iterator_t<R> shuffle(R&& r, Gen&& g);
|
| 1654 |
+
}
|
| 1655 |
+
|
| 1656 |
+
// [alg.shift], shift
|
| 1657 |
+
template<class ForwardIterator>
|
| 1658 |
+
constexpr ForwardIterator
|
| 1659 |
+
shift_left(ForwardIterator first, ForwardIterator last,
|
| 1660 |
+
typename iterator_traits<ForwardIterator>::difference_type n);
|
| 1661 |
+
template<class ExecutionPolicy, class ForwardIterator>
|
| 1662 |
+
ForwardIterator
|
| 1663 |
+
shift_left(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 1664 |
+
ForwardIterator first, ForwardIterator last,
|
| 1665 |
+
typename iterator_traits<ForwardIterator>::difference_type n);
|
| 1666 |
+
template<class ForwardIterator>
|
| 1667 |
+
constexpr ForwardIterator
|
| 1668 |
+
shift_right(ForwardIterator first, ForwardIterator last,
|
| 1669 |
+
typename iterator_traits<ForwardIterator>::difference_type n);
|
| 1670 |
+
template<class ExecutionPolicy, class ForwardIterator>
|
| 1671 |
+
ForwardIterator
|
| 1672 |
+
shift_right(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 1673 |
+
ForwardIterator first, ForwardIterator last,
|
| 1674 |
+
typename iterator_traits<ForwardIterator>::difference_type n);
|
| 1675 |
+
|
| 1676 |
+
// [alg.sorting], sorting and related operations
|
| 1677 |
+
// [alg.sort], sorting
|
| 1678 |
+
template<class RandomAccessIterator>
|
| 1679 |
+
constexpr void sort(RandomAccessIterator first, RandomAccessIterator last);
|
| 1680 |
+
template<class RandomAccessIterator, class Compare>
|
| 1681 |
+
constexpr void sort(RandomAccessIterator first, RandomAccessIterator last,
|
| 1682 |
+
Compare comp);
|
| 1683 |
+
template<class ExecutionPolicy, class RandomAccessIterator>
|
| 1684 |
+
void sort(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 1685 |
+
RandomAccessIterator first, RandomAccessIterator last);
|
| 1686 |
+
template<class ExecutionPolicy, class RandomAccessIterator, class Compare>
|
| 1687 |
+
void sort(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 1688 |
+
RandomAccessIterator first, RandomAccessIterator last,
|
| 1689 |
+
Compare comp);
|
| 1690 |
+
|
| 1691 |
+
namespace ranges {
|
| 1692 |
+
template<random_access_iterator I, sentinel_for<I> S, class Comp = ranges::less,
|
| 1693 |
+
class Proj = identity>
|
| 1694 |
+
requires sortable<I, Comp, Proj>
|
| 1695 |
+
constexpr I
|
| 1696 |
+
sort(I first, S last, Comp comp = {}, Proj proj = {});
|
| 1697 |
+
template<random_access_range R, class Comp = ranges::less, class Proj = identity>
|
| 1698 |
+
requires sortable<iterator_t<R>, Comp, Proj>
|
| 1699 |
+
constexpr borrowed_iterator_t<R>
|
| 1700 |
+
sort(R&& r, Comp comp = {}, Proj proj = {});
|
| 1701 |
+
}
|
| 1702 |
+
|
| 1703 |
+
template<class RandomAccessIterator>
|
| 1704 |
+
void stable_sort(RandomAccessIterator first, RandomAccessIterator last);
|
| 1705 |
+
template<class RandomAccessIterator, class Compare>
|
| 1706 |
+
void stable_sort(RandomAccessIterator first, RandomAccessIterator last,
|
| 1707 |
+
Compare comp);
|
| 1708 |
+
template<class ExecutionPolicy, class RandomAccessIterator>
|
| 1709 |
+
void stable_sort(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 1710 |
+
RandomAccessIterator first, RandomAccessIterator last);
|
| 1711 |
+
template<class ExecutionPolicy, class RandomAccessIterator, class Compare>
|
| 1712 |
+
void stable_sort(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 1713 |
+
RandomAccessIterator first, RandomAccessIterator last,
|
| 1714 |
+
Compare comp);
|
| 1715 |
+
|
| 1716 |
+
namespace ranges {
|
| 1717 |
+
template<random_access_iterator I, sentinel_for<I> S, class Comp = ranges::less,
|
| 1718 |
+
class Proj = identity>
|
| 1719 |
+
requires sortable<I, Comp, Proj>
|
| 1720 |
+
I stable_sort(I first, S last, Comp comp = {}, Proj proj = {});
|
| 1721 |
+
template<random_access_range R, class Comp = ranges::less, class Proj = identity>
|
| 1722 |
+
requires sortable<iterator_t<R>, Comp, Proj>
|
| 1723 |
+
borrowed_iterator_t<R>
|
| 1724 |
+
stable_sort(R&& r, Comp comp = {}, Proj proj = {});
|
| 1725 |
+
}
|
| 1726 |
+
|
| 1727 |
+
template<class RandomAccessIterator>
|
| 1728 |
+
constexpr void partial_sort(RandomAccessIterator first,
|
| 1729 |
+
RandomAccessIterator middle,
|
| 1730 |
+
RandomAccessIterator last);
|
| 1731 |
+
template<class RandomAccessIterator, class Compare>
|
| 1732 |
+
constexpr void partial_sort(RandomAccessIterator first,
|
| 1733 |
+
RandomAccessIterator middle,
|
| 1734 |
+
RandomAccessIterator last, Compare comp);
|
| 1735 |
+
template<class ExecutionPolicy, class RandomAccessIterator>
|
| 1736 |
+
void partial_sort(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 1737 |
+
RandomAccessIterator first,
|
| 1738 |
+
RandomAccessIterator middle,
|
| 1739 |
+
RandomAccessIterator last);
|
| 1740 |
+
template<class ExecutionPolicy, class RandomAccessIterator, class Compare>
|
| 1741 |
+
void partial_sort(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 1742 |
+
RandomAccessIterator first,
|
| 1743 |
+
RandomAccessIterator middle,
|
| 1744 |
+
RandomAccessIterator last, Compare comp);
|
| 1745 |
+
|
| 1746 |
+
namespace ranges {
|
| 1747 |
+
template<random_access_iterator I, sentinel_for<I> S, class Comp = ranges::less,
|
| 1748 |
+
class Proj = identity>
|
| 1749 |
+
requires sortable<I, Comp, Proj>
|
| 1750 |
+
constexpr I
|
| 1751 |
+
partial_sort(I first, I middle, S last, Comp comp = {}, Proj proj = {});
|
| 1752 |
+
template<random_access_range R, class Comp = ranges::less, class Proj = identity>
|
| 1753 |
+
requires sortable<iterator_t<R>, Comp, Proj>
|
| 1754 |
+
constexpr borrowed_iterator_t<R>
|
| 1755 |
+
partial_sort(R&& r, iterator_t<R> middle, Comp comp = {},
|
| 1756 |
+
Proj proj = {});
|
| 1757 |
+
}
|
| 1758 |
+
|
| 1759 |
+
template<class InputIterator, class RandomAccessIterator>
|
| 1760 |
+
constexpr RandomAccessIterator
|
| 1761 |
+
partial_sort_copy(InputIterator first, InputIterator last,
|
| 1762 |
+
RandomAccessIterator result_first,
|
| 1763 |
+
RandomAccessIterator result_last);
|
| 1764 |
+
template<class InputIterator, class RandomAccessIterator, class Compare>
|
| 1765 |
+
constexpr RandomAccessIterator
|
| 1766 |
+
partial_sort_copy(InputIterator first, InputIterator last,
|
| 1767 |
+
RandomAccessIterator result_first,
|
| 1768 |
+
RandomAccessIterator result_last,
|
| 1769 |
+
Compare comp);
|
| 1770 |
+
template<class ExecutionPolicy, class ForwardIterator, class RandomAccessIterator>
|
| 1771 |
+
RandomAccessIterator
|
| 1772 |
+
partial_sort_copy(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 1773 |
+
ForwardIterator first, ForwardIterator last,
|
| 1774 |
+
RandomAccessIterator result_first,
|
| 1775 |
+
RandomAccessIterator result_last);
|
| 1776 |
+
template<class ExecutionPolicy, class ForwardIterator, class RandomAccessIterator,
|
| 1777 |
+
class Compare>
|
| 1778 |
+
RandomAccessIterator
|
| 1779 |
+
partial_sort_copy(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 1780 |
+
ForwardIterator first, ForwardIterator last,
|
| 1781 |
+
RandomAccessIterator result_first,
|
| 1782 |
+
RandomAccessIterator result_last,
|
| 1783 |
+
Compare comp);
|
| 1784 |
+
|
| 1785 |
+
namespace ranges {
|
| 1786 |
+
template<class I, class O>
|
| 1787 |
+
using partial_sort_copy_result = in_out_result<I, O>;
|
| 1788 |
+
|
| 1789 |
+
template<input_iterator I1, sentinel_for<I1> S1,
|
| 1790 |
+
random_access_iterator I2, sentinel_for<I2> S2,
|
| 1791 |
+
class Comp = ranges::less, class Proj1 = identity, class Proj2 = identity>
|
| 1792 |
+
requires indirectly_copyable<I1, I2> && sortable<I2, Comp, Proj2> &&
|
| 1793 |
+
indirect_strict_weak_order<Comp, projected<I1, Proj1>, projected<I2, Proj2>>
|
| 1794 |
+
constexpr partial_sort_copy_result<I1, I2>
|
| 1795 |
+
partial_sort_copy(I1 first, S1 last, I2 result_first, S2 result_last,
|
| 1796 |
+
Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 1797 |
+
template<input_range R1, random_access_range R2, class Comp = ranges::less,
|
| 1798 |
+
class Proj1 = identity, class Proj2 = identity>
|
| 1799 |
+
requires indirectly_copyable<iterator_t<R1>, iterator_t<R2>> &&
|
| 1800 |
+
sortable<iterator_t<R2>, Comp, Proj2> &&
|
| 1801 |
+
indirect_strict_weak_order<Comp, projected<iterator_t<R1>, Proj1>,
|
| 1802 |
+
projected<iterator_t<R2>, Proj2>>
|
| 1803 |
+
constexpr partial_sort_copy_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>>
|
| 1804 |
+
partial_sort_copy(R1&& r, R2&& result_r, Comp comp = {},
|
| 1805 |
+
Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 1806 |
+
}
|
| 1807 |
+
|
| 1808 |
+
template<class ForwardIterator>
|
| 1809 |
+
constexpr bool is_sorted(ForwardIterator first, ForwardIterator last);
|
| 1810 |
+
template<class ForwardIterator, class Compare>
|
| 1811 |
+
constexpr bool is_sorted(ForwardIterator first, ForwardIterator last,
|
| 1812 |
+
Compare comp);
|
| 1813 |
+
template<class ExecutionPolicy, class ForwardIterator>
|
| 1814 |
+
bool is_sorted(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 1815 |
+
ForwardIterator first, ForwardIterator last);
|
| 1816 |
+
template<class ExecutionPolicy, class ForwardIterator, class Compare>
|
| 1817 |
+
bool is_sorted(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 1818 |
+
ForwardIterator first, ForwardIterator last,
|
| 1819 |
+
Compare comp);
|
| 1820 |
+
|
| 1821 |
+
namespace ranges {
|
| 1822 |
+
template<forward_iterator I, sentinel_for<I> S, class Proj = identity,
|
| 1823 |
+
indirect_strict_weak_order<projected<I, Proj>> Comp = ranges::less>
|
| 1824 |
+
constexpr bool is_sorted(I first, S last, Comp comp = {}, Proj proj = {});
|
| 1825 |
+
template<forward_range R, class Proj = identity,
|
| 1826 |
+
indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less>
|
| 1827 |
+
constexpr bool is_sorted(R&& r, Comp comp = {}, Proj proj = {});
|
| 1828 |
+
}
|
| 1829 |
+
|
| 1830 |
+
template<class ForwardIterator>
|
| 1831 |
+
constexpr ForwardIterator
|
| 1832 |
+
is_sorted_until(ForwardIterator first, ForwardIterator last);
|
| 1833 |
+
template<class ForwardIterator, class Compare>
|
| 1834 |
+
constexpr ForwardIterator
|
| 1835 |
+
is_sorted_until(ForwardIterator first, ForwardIterator last,
|
| 1836 |
+
Compare comp);
|
| 1837 |
+
template<class ExecutionPolicy, class ForwardIterator>
|
| 1838 |
+
ForwardIterator
|
| 1839 |
+
is_sorted_until(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 1840 |
+
ForwardIterator first, ForwardIterator last);
|
| 1841 |
+
template<class ExecutionPolicy, class ForwardIterator, class Compare>
|
| 1842 |
+
ForwardIterator
|
| 1843 |
+
is_sorted_until(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 1844 |
+
ForwardIterator first, ForwardIterator last,
|
| 1845 |
+
Compare comp);
|
| 1846 |
+
|
| 1847 |
+
namespace ranges {
|
| 1848 |
+
template<forward_iterator I, sentinel_for<I> S, class Proj = identity,
|
| 1849 |
+
indirect_strict_weak_order<projected<I, Proj>> Comp = ranges::less>
|
| 1850 |
+
constexpr I is_sorted_until(I first, S last, Comp comp = {}, Proj proj = {});
|
| 1851 |
+
template<forward_range R, class Proj = identity,
|
| 1852 |
+
indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less>
|
| 1853 |
+
constexpr borrowed_iterator_t<R>
|
| 1854 |
+
is_sorted_until(R&& r, Comp comp = {}, Proj proj = {});
|
| 1855 |
+
}
|
| 1856 |
+
|
| 1857 |
+
// [alg.nth.element], Nth element
|
| 1858 |
+
template<class RandomAccessIterator>
|
| 1859 |
+
constexpr void nth_element(RandomAccessIterator first, RandomAccessIterator nth,
|
| 1860 |
+
RandomAccessIterator last);
|
| 1861 |
+
template<class RandomAccessIterator, class Compare>
|
| 1862 |
+
constexpr void nth_element(RandomAccessIterator first, RandomAccessIterator nth,
|
| 1863 |
+
RandomAccessIterator last, Compare comp);
|
| 1864 |
+
template<class ExecutionPolicy, class RandomAccessIterator>
|
| 1865 |
+
void nth_element(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 1866 |
+
RandomAccessIterator first, RandomAccessIterator nth,
|
| 1867 |
+
RandomAccessIterator last);
|
| 1868 |
+
template<class ExecutionPolicy, class RandomAccessIterator, class Compare>
|
| 1869 |
+
void nth_element(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 1870 |
+
RandomAccessIterator first, RandomAccessIterator nth,
|
| 1871 |
+
RandomAccessIterator last, Compare comp);
|
| 1872 |
+
|
| 1873 |
+
namespace ranges {
|
| 1874 |
+
template<random_access_iterator I, sentinel_for<I> S, class Comp = ranges::less,
|
| 1875 |
+
class Proj = identity>
|
| 1876 |
+
requires sortable<I, Comp, Proj>
|
| 1877 |
+
constexpr I
|
| 1878 |
+
nth_element(I first, I nth, S last, Comp comp = {}, Proj proj = {});
|
| 1879 |
+
template<random_access_range R, class Comp = ranges::less, class Proj = identity>
|
| 1880 |
+
requires sortable<iterator_t<R>, Comp, Proj>
|
| 1881 |
+
constexpr borrowed_iterator_t<R>
|
| 1882 |
+
nth_element(R&& r, iterator_t<R> nth, Comp comp = {}, Proj proj = {});
|
| 1883 |
+
}
|
| 1884 |
+
|
| 1885 |
+
// [alg.binary.search], binary search
|
| 1886 |
+
template<class ForwardIterator, class T>
|
| 1887 |
+
constexpr ForwardIterator
|
| 1888 |
+
lower_bound(ForwardIterator first, ForwardIterator last,
|
| 1889 |
+
const T& value);
|
| 1890 |
+
template<class ForwardIterator, class T, class Compare>
|
| 1891 |
+
constexpr ForwardIterator
|
| 1892 |
+
lower_bound(ForwardIterator first, ForwardIterator last,
|
| 1893 |
+
const T& value, Compare comp);
|
| 1894 |
+
|
| 1895 |
+
namespace ranges {
|
| 1896 |
+
template<forward_iterator I, sentinel_for<I> S, class T, class Proj = identity,
|
| 1897 |
+
indirect_strict_weak_order<const T*, projected<I, Proj>> Comp = ranges::less>
|
| 1898 |
+
constexpr I lower_bound(I first, S last, const T& value, Comp comp = {},
|
| 1899 |
+
Proj proj = {});
|
| 1900 |
+
template<forward_range R, class T, class Proj = identity,
|
| 1901 |
+
indirect_strict_weak_order<const T*, projected<iterator_t<R>, Proj>> Comp =
|
| 1902 |
+
ranges::less>
|
| 1903 |
+
constexpr borrowed_iterator_t<R>
|
| 1904 |
+
lower_bound(R&& r, const T& value, Comp comp = {}, Proj proj = {});
|
| 1905 |
+
}
|
| 1906 |
+
|
| 1907 |
+
template<class ForwardIterator, class T>
|
| 1908 |
+
constexpr ForwardIterator
|
| 1909 |
+
upper_bound(ForwardIterator first, ForwardIterator last,
|
| 1910 |
+
const T& value);
|
| 1911 |
+
template<class ForwardIterator, class T, class Compare>
|
| 1912 |
+
constexpr ForwardIterator
|
| 1913 |
+
upper_bound(ForwardIterator first, ForwardIterator last,
|
| 1914 |
+
const T& value, Compare comp);
|
| 1915 |
+
|
| 1916 |
+
namespace ranges {
|
| 1917 |
+
template<forward_iterator I, sentinel_for<I> S, class T, class Proj = identity,
|
| 1918 |
+
indirect_strict_weak_order<const T*, projected<I, Proj>> Comp = ranges::less>
|
| 1919 |
+
constexpr I upper_bound(I first, S last, const T& value, Comp comp = {}, Proj proj = {});
|
| 1920 |
+
template<forward_range R, class T, class Proj = identity,
|
| 1921 |
+
indirect_strict_weak_order<const T*, projected<iterator_t<R>, Proj>> Comp =
|
| 1922 |
+
ranges::less>
|
| 1923 |
+
constexpr borrowed_iterator_t<R>
|
| 1924 |
+
upper_bound(R&& r, const T& value, Comp comp = {}, Proj proj = {});
|
| 1925 |
+
}
|
| 1926 |
+
|
| 1927 |
+
template<class ForwardIterator, class T>
|
| 1928 |
+
constexpr pair<ForwardIterator, ForwardIterator>
|
| 1929 |
+
equal_range(ForwardIterator first, ForwardIterator last,
|
| 1930 |
+
const T& value);
|
| 1931 |
+
template<class ForwardIterator, class T, class Compare>
|
| 1932 |
+
constexpr pair<ForwardIterator, ForwardIterator>
|
| 1933 |
+
equal_range(ForwardIterator first, ForwardIterator last,
|
| 1934 |
+
const T& value, Compare comp);
|
| 1935 |
+
|
| 1936 |
+
namespace ranges {
|
| 1937 |
+
template<forward_iterator I, sentinel_for<I> S, class T, class Proj = identity,
|
| 1938 |
+
indirect_strict_weak_order<const T*, projected<I, Proj>> Comp = ranges::less>
|
| 1939 |
+
constexpr subrange<I>
|
| 1940 |
+
equal_range(I first, S last, const T& value, Comp comp = {}, Proj proj = {});
|
| 1941 |
+
template<forward_range R, class T, class Proj = identity,
|
| 1942 |
+
indirect_strict_weak_order<const T*, projected<iterator_t<R>, Proj>> Comp =
|
| 1943 |
+
ranges::less>
|
| 1944 |
+
constexpr borrowed_subrange_t<R>
|
| 1945 |
+
equal_range(R&& r, const T& value, Comp comp = {}, Proj proj = {});
|
| 1946 |
+
}
|
| 1947 |
+
|
| 1948 |
+
template<class ForwardIterator, class T>
|
| 1949 |
+
constexpr bool
|
| 1950 |
+
binary_search(ForwardIterator first, ForwardIterator last,
|
| 1951 |
+
const T& value);
|
| 1952 |
+
template<class ForwardIterator, class T, class Compare>
|
| 1953 |
+
constexpr bool
|
| 1954 |
+
binary_search(ForwardIterator first, ForwardIterator last,
|
| 1955 |
+
const T& value, Compare comp);
|
| 1956 |
+
|
| 1957 |
+
namespace ranges {
|
| 1958 |
+
template<forward_iterator I, sentinel_for<I> S, class T, class Proj = identity,
|
| 1959 |
+
indirect_strict_weak_order<const T*, projected<I, Proj>> Comp = ranges::less>
|
| 1960 |
+
constexpr bool binary_search(I first, S last, const T& value, Comp comp = {},
|
| 1961 |
+
Proj proj = {});
|
| 1962 |
+
template<forward_range R, class T, class Proj = identity,
|
| 1963 |
+
indirect_strict_weak_order<const T*, projected<iterator_t<R>, Proj>> Comp =
|
| 1964 |
+
ranges::less>
|
| 1965 |
+
constexpr bool binary_search(R&& r, const T& value, Comp comp = {},
|
| 1966 |
+
Proj proj = {});
|
| 1967 |
+
}
|
| 1968 |
+
|
| 1969 |
+
// [alg.partitions], partitions
|
| 1970 |
+
template<class InputIterator, class Predicate>
|
| 1971 |
+
constexpr bool is_partitioned(InputIterator first, InputIterator last, Predicate pred);
|
| 1972 |
+
template<class ExecutionPolicy, class ForwardIterator, class Predicate>
|
| 1973 |
+
bool is_partitioned(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 1974 |
+
ForwardIterator first, ForwardIterator last, Predicate pred);
|
| 1975 |
+
|
| 1976 |
+
namespace ranges {
|
| 1977 |
+
template<input_iterator I, sentinel_for<I> S, class Proj = identity,
|
| 1978 |
+
indirect_unary_predicate<projected<I, Proj>> Pred>
|
| 1979 |
+
constexpr bool is_partitioned(I first, S last, Pred pred, Proj proj = {});
|
| 1980 |
+
template<input_range R, class Proj = identity,
|
| 1981 |
+
indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
|
| 1982 |
+
constexpr bool is_partitioned(R&& r, Pred pred, Proj proj = {});
|
| 1983 |
+
}
|
| 1984 |
+
|
| 1985 |
+
template<class ForwardIterator, class Predicate>
|
| 1986 |
+
constexpr ForwardIterator partition(ForwardIterator first,
|
| 1987 |
+
ForwardIterator last,
|
| 1988 |
+
Predicate pred);
|
| 1989 |
+
template<class ExecutionPolicy, class ForwardIterator, class Predicate>
|
| 1990 |
+
ForwardIterator partition(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 1991 |
+
ForwardIterator first,
|
| 1992 |
+
ForwardIterator last,
|
| 1993 |
+
Predicate pred);
|
| 1994 |
+
|
| 1995 |
+
namespace ranges {
|
| 1996 |
+
template<permutable I, sentinel_for<I> S, class Proj = identity,
|
| 1997 |
+
indirect_unary_predicate<projected<I, Proj>> Pred>
|
| 1998 |
+
constexpr subrange<I>
|
| 1999 |
+
partition(I first, S last, Pred pred, Proj proj = {});
|
| 2000 |
+
template<forward_range R, class Proj = identity,
|
| 2001 |
+
indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
|
| 2002 |
+
requires permutable<iterator_t<R>>
|
| 2003 |
+
constexpr borrowed_subrange_t<R>
|
| 2004 |
+
partition(R&& r, Pred pred, Proj proj = {});
|
| 2005 |
+
}
|
| 2006 |
+
|
| 2007 |
+
template<class BidirectionalIterator, class Predicate>
|
| 2008 |
+
BidirectionalIterator stable_partition(BidirectionalIterator first,
|
| 2009 |
+
BidirectionalIterator last,
|
| 2010 |
+
Predicate pred);
|
| 2011 |
+
template<class ExecutionPolicy, class BidirectionalIterator, class Predicate>
|
| 2012 |
+
BidirectionalIterator stable_partition(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 2013 |
+
BidirectionalIterator first,
|
| 2014 |
+
BidirectionalIterator last,
|
| 2015 |
+
Predicate pred);
|
| 2016 |
+
|
| 2017 |
+
namespace ranges {
|
| 2018 |
+
template<bidirectional_iterator I, sentinel_for<I> S, class Proj = identity,
|
| 2019 |
+
indirect_unary_predicate<projected<I, Proj>> Pred>
|
| 2020 |
+
requires permutable<I>
|
| 2021 |
+
subrange<I> stable_partition(I first, S last, Pred pred, Proj proj = {});
|
| 2022 |
+
template<bidirectional_range R, class Proj = identity,
|
| 2023 |
+
indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
|
| 2024 |
+
requires permutable<iterator_t<R>>
|
| 2025 |
+
borrowed_subrange_t<R> stable_partition(R&& r, Pred pred, Proj proj = {});
|
| 2026 |
+
}
|
| 2027 |
+
|
| 2028 |
+
template<class InputIterator, class OutputIterator1,
|
| 2029 |
+
class OutputIterator2, class Predicate>
|
| 2030 |
+
constexpr pair<OutputIterator1, OutputIterator2>
|
| 2031 |
+
partition_copy(InputIterator first, InputIterator last,
|
| 2032 |
+
OutputIterator1 out_true, OutputIterator2 out_false,
|
| 2033 |
+
Predicate pred);
|
| 2034 |
+
template<class ExecutionPolicy, class ForwardIterator, class ForwardIterator1,
|
| 2035 |
+
class ForwardIterator2, class Predicate>
|
| 2036 |
+
pair<ForwardIterator1, ForwardIterator2>
|
| 2037 |
+
partition_copy(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 2038 |
+
ForwardIterator first, ForwardIterator last,
|
| 2039 |
+
ForwardIterator1 out_true, ForwardIterator2 out_false,
|
| 2040 |
+
Predicate pred);
|
| 2041 |
+
|
| 2042 |
+
namespace ranges {
|
| 2043 |
+
template<class I, class O1, class O2>
|
| 2044 |
+
using partition_copy_result = in_out_out_result<I, O1, O2>;
|
| 2045 |
+
|
| 2046 |
+
template<input_iterator I, sentinel_for<I> S,
|
| 2047 |
+
weakly_incrementable O1, weakly_incrementable O2,
|
| 2048 |
+
class Proj = identity, indirect_unary_predicate<projected<I, Proj>> Pred>
|
| 2049 |
+
requires indirectly_copyable<I, O1> && indirectly_copyable<I, O2>
|
| 2050 |
+
constexpr partition_copy_result<I, O1, O2>
|
| 2051 |
+
partition_copy(I first, S last, O1 out_true, O2 out_false, Pred pred,
|
| 2052 |
+
Proj proj = {});
|
| 2053 |
+
template<input_range R, weakly_incrementable O1, weakly_incrementable O2,
|
| 2054 |
+
class Proj = identity,
|
| 2055 |
+
indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
|
| 2056 |
+
requires indirectly_copyable<iterator_t<R>, O1> &&
|
| 2057 |
+
indirectly_copyable<iterator_t<R>, O2>
|
| 2058 |
+
constexpr partition_copy_result<borrowed_iterator_t<R>, O1, O2>
|
| 2059 |
+
partition_copy(R&& r, O1 out_true, O2 out_false, Pred pred, Proj proj = {});
|
| 2060 |
+
}
|
| 2061 |
+
|
| 2062 |
+
template<class ForwardIterator, class Predicate>
|
| 2063 |
+
constexpr ForwardIterator
|
| 2064 |
+
partition_point(ForwardIterator first, ForwardIterator last,
|
| 2065 |
+
Predicate pred);
|
| 2066 |
+
|
| 2067 |
+
namespace ranges {
|
| 2068 |
+
template<forward_iterator I, sentinel_for<I> S, class Proj = identity,
|
| 2069 |
+
indirect_unary_predicate<projected<I, Proj>> Pred>
|
| 2070 |
+
constexpr I partition_point(I first, S last, Pred pred, Proj proj = {});
|
| 2071 |
+
template<forward_range R, class Proj = identity,
|
| 2072 |
+
indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
|
| 2073 |
+
constexpr borrowed_iterator_t<R>
|
| 2074 |
+
partition_point(R&& r, Pred pred, Proj proj = {});
|
| 2075 |
+
}
|
| 2076 |
+
|
| 2077 |
+
// [alg.merge], merge
|
| 2078 |
+
template<class InputIterator1, class InputIterator2, class OutputIterator>
|
| 2079 |
+
constexpr OutputIterator
|
| 2080 |
+
merge(InputIterator1 first1, InputIterator1 last1,
|
| 2081 |
+
InputIterator2 first2, InputIterator2 last2,
|
| 2082 |
+
OutputIterator result);
|
| 2083 |
+
template<class InputIterator1, class InputIterator2, class OutputIterator,
|
| 2084 |
+
class Compare>
|
| 2085 |
+
constexpr OutputIterator
|
| 2086 |
+
merge(InputIterator1 first1, InputIterator1 last1,
|
| 2087 |
+
InputIterator2 first2, InputIterator2 last2,
|
| 2088 |
+
OutputIterator result, Compare comp);
|
| 2089 |
+
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 2090 |
+
class ForwardIterator>
|
| 2091 |
+
ForwardIterator
|
| 2092 |
+
merge(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 2093 |
+
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 2094 |
+
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 2095 |
+
ForwardIterator result);
|
| 2096 |
+
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 2097 |
+
class ForwardIterator, class Compare>
|
| 2098 |
+
ForwardIterator
|
| 2099 |
+
merge(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 2100 |
+
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 2101 |
+
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 2102 |
+
ForwardIterator result, Compare comp);
|
| 2103 |
+
|
| 2104 |
+
namespace ranges {
|
| 2105 |
+
template<class I1, class I2, class O>
|
| 2106 |
+
using merge_result = in_in_out_result<I1, I2, O>;
|
| 2107 |
+
|
| 2108 |
+
template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2,
|
| 2109 |
+
weakly_incrementable O, class Comp = ranges::less, class Proj1 = identity,
|
| 2110 |
+
class Proj2 = identity>
|
| 2111 |
+
requires mergeable<I1, I2, O, Comp, Proj1, Proj2>
|
| 2112 |
+
constexpr merge_result<I1, I2, O>
|
| 2113 |
+
merge(I1 first1, S1 last1, I2 first2, S2 last2, O result,
|
| 2114 |
+
Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 2115 |
+
template<input_range R1, input_range R2, weakly_incrementable O, class Comp = ranges::less,
|
| 2116 |
+
class Proj1 = identity, class Proj2 = identity>
|
| 2117 |
+
requires mergeable<iterator_t<R1>, iterator_t<R2>, O, Comp, Proj1, Proj2>
|
| 2118 |
+
constexpr merge_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>, O>
|
| 2119 |
+
merge(R1&& r1, R2&& r2, O result,
|
| 2120 |
+
Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 2121 |
+
}
|
| 2122 |
+
|
| 2123 |
+
template<class BidirectionalIterator>
|
| 2124 |
+
void inplace_merge(BidirectionalIterator first,
|
| 2125 |
+
BidirectionalIterator middle,
|
| 2126 |
+
BidirectionalIterator last);
|
| 2127 |
+
template<class BidirectionalIterator, class Compare>
|
| 2128 |
+
void inplace_merge(BidirectionalIterator first,
|
| 2129 |
+
BidirectionalIterator middle,
|
| 2130 |
+
BidirectionalIterator last, Compare comp);
|
| 2131 |
+
template<class ExecutionPolicy, class BidirectionalIterator>
|
| 2132 |
+
void inplace_merge(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 2133 |
+
BidirectionalIterator first,
|
| 2134 |
+
BidirectionalIterator middle,
|
| 2135 |
+
BidirectionalIterator last);
|
| 2136 |
+
template<class ExecutionPolicy, class BidirectionalIterator, class Compare>
|
| 2137 |
+
void inplace_merge(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 2138 |
+
BidirectionalIterator first,
|
| 2139 |
+
BidirectionalIterator middle,
|
| 2140 |
+
BidirectionalIterator last, Compare comp);
|
| 2141 |
+
|
| 2142 |
+
namespace ranges {
|
| 2143 |
+
template<bidirectional_iterator I, sentinel_for<I> S, class Comp = ranges::less,
|
| 2144 |
+
class Proj = identity>
|
| 2145 |
+
requires sortable<I, Comp, Proj>
|
| 2146 |
+
I inplace_merge(I first, I middle, S last, Comp comp = {}, Proj proj = {});
|
| 2147 |
+
template<bidirectional_range R, class Comp = ranges::less, class Proj = identity>
|
| 2148 |
+
requires sortable<iterator_t<R>, Comp, Proj>
|
| 2149 |
+
borrowed_iterator_t<R>
|
| 2150 |
+
inplace_merge(R&& r, iterator_t<R> middle, Comp comp = {},
|
| 2151 |
+
Proj proj = {});
|
| 2152 |
+
}
|
| 2153 |
+
|
| 2154 |
+
// [alg.set.operations], set operations
|
| 2155 |
+
template<class InputIterator1, class InputIterator2>
|
| 2156 |
+
constexpr bool includes(InputIterator1 first1, InputIterator1 last1,
|
| 2157 |
+
InputIterator2 first2, InputIterator2 last2);
|
| 2158 |
+
template<class InputIterator1, class InputIterator2, class Compare>
|
| 2159 |
+
constexpr bool includes(InputIterator1 first1, InputIterator1 last1,
|
| 2160 |
+
InputIterator2 first2, InputIterator2 last2,
|
| 2161 |
+
Compare comp);
|
| 2162 |
+
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 2163 |
+
bool includes(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 2164 |
+
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 2165 |
+
ForwardIterator2 first2, ForwardIterator2 last2);
|
| 2166 |
+
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 2167 |
+
class Compare>
|
| 2168 |
+
bool includes(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 2169 |
+
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 2170 |
+
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 2171 |
+
Compare comp);
|
| 2172 |
+
|
| 2173 |
+
namespace ranges {
|
| 2174 |
+
template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2,
|
| 2175 |
+
class Proj1 = identity, class Proj2 = identity,
|
| 2176 |
+
indirect_strict_weak_order<projected<I1, Proj1>, projected<I2, Proj2>> Comp =
|
| 2177 |
+
ranges::less>
|
| 2178 |
+
constexpr bool includes(I1 first1, S1 last1, I2 first2, S2 last2, Comp comp = {},
|
| 2179 |
+
Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 2180 |
+
template<input_range R1, input_range R2, class Proj1 = identity,
|
| 2181 |
+
class Proj2 = identity,
|
| 2182 |
+
indirect_strict_weak_order<projected<iterator_t<R1>, Proj1>,
|
| 2183 |
+
projected<iterator_t<R2>, Proj2>> Comp = ranges::less>
|
| 2184 |
+
constexpr bool includes(R1&& r1, R2&& r2, Comp comp = {},
|
| 2185 |
+
Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 2186 |
+
}
|
| 2187 |
+
|
| 2188 |
+
template<class InputIterator1, class InputIterator2, class OutputIterator>
|
| 2189 |
+
constexpr OutputIterator
|
| 2190 |
+
set_union(InputIterator1 first1, InputIterator1 last1,
|
| 2191 |
+
InputIterator2 first2, InputIterator2 last2,
|
| 2192 |
+
OutputIterator result);
|
| 2193 |
+
template<class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
|
| 2194 |
+
constexpr OutputIterator
|
| 2195 |
+
set_union(InputIterator1 first1, InputIterator1 last1,
|
| 2196 |
+
InputIterator2 first2, InputIterator2 last2,
|
| 2197 |
+
OutputIterator result, Compare comp);
|
| 2198 |
+
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 2199 |
+
class ForwardIterator>
|
| 2200 |
+
ForwardIterator
|
| 2201 |
+
set_union(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 2202 |
+
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 2203 |
+
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 2204 |
+
ForwardIterator result);
|
| 2205 |
+
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 2206 |
+
class ForwardIterator, class Compare>
|
| 2207 |
+
ForwardIterator
|
| 2208 |
+
set_union(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 2209 |
+
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 2210 |
+
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 2211 |
+
ForwardIterator result, Compare comp);
|
| 2212 |
+
|
| 2213 |
+
namespace ranges {
|
| 2214 |
+
template<class I1, class I2, class O>
|
| 2215 |
+
using set_union_result = in_in_out_result<I1, I2, O>;
|
| 2216 |
+
|
| 2217 |
+
template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2,
|
| 2218 |
+
weakly_incrementable O, class Comp = ranges::less,
|
| 2219 |
+
class Proj1 = identity, class Proj2 = identity>
|
| 2220 |
+
requires mergeable<I1, I2, O, Comp, Proj1, Proj2>
|
| 2221 |
+
constexpr set_union_result<I1, I2, O>
|
| 2222 |
+
set_union(I1 first1, S1 last1, I2 first2, S2 last2, O result, Comp comp = {},
|
| 2223 |
+
Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 2224 |
+
template<input_range R1, input_range R2, weakly_incrementable O,
|
| 2225 |
+
class Comp = ranges::less, class Proj1 = identity, class Proj2 = identity>
|
| 2226 |
+
requires mergeable<iterator_t<R1>, iterator_t<R2>, O, Comp, Proj1, Proj2>
|
| 2227 |
+
constexpr set_union_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>, O>
|
| 2228 |
+
set_union(R1&& r1, R2&& r2, O result, Comp comp = {},
|
| 2229 |
+
Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 2230 |
+
}
|
| 2231 |
+
|
| 2232 |
+
template<class InputIterator1, class InputIterator2, class OutputIterator>
|
| 2233 |
+
constexpr OutputIterator
|
| 2234 |
+
set_intersection(InputIterator1 first1, InputIterator1 last1,
|
| 2235 |
+
InputIterator2 first2, InputIterator2 last2,
|
| 2236 |
+
OutputIterator result);
|
| 2237 |
+
template<class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
|
| 2238 |
+
constexpr OutputIterator
|
| 2239 |
+
set_intersection(InputIterator1 first1, InputIterator1 last1,
|
| 2240 |
+
InputIterator2 first2, InputIterator2 last2,
|
| 2241 |
+
OutputIterator result, Compare comp);
|
| 2242 |
+
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 2243 |
+
class ForwardIterator>
|
| 2244 |
+
ForwardIterator
|
| 2245 |
+
set_intersection(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 2246 |
+
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 2247 |
+
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 2248 |
+
ForwardIterator result);
|
| 2249 |
+
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 2250 |
+
class ForwardIterator, class Compare>
|
| 2251 |
+
ForwardIterator
|
| 2252 |
+
set_intersection(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 2253 |
+
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 2254 |
+
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 2255 |
+
ForwardIterator result, Compare comp);
|
| 2256 |
+
|
| 2257 |
+
namespace ranges {
|
| 2258 |
+
template<class I1, class I2, class O>
|
| 2259 |
+
using set_intersection_result = in_in_out_result<I1, I2, O>;
|
| 2260 |
+
|
| 2261 |
+
template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2,
|
| 2262 |
+
weakly_incrementable O, class Comp = ranges::less,
|
| 2263 |
+
class Proj1 = identity, class Proj2 = identity>
|
| 2264 |
+
requires mergeable<I1, I2, O, Comp, Proj1, Proj2>
|
| 2265 |
+
constexpr set_intersection_result<I1, I2, O>
|
| 2266 |
+
set_intersection(I1 first1, S1 last1, I2 first2, S2 last2, O result,
|
| 2267 |
+
Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 2268 |
+
template<input_range R1, input_range R2, weakly_incrementable O,
|
| 2269 |
+
class Comp = ranges::less, class Proj1 = identity, class Proj2 = identity>
|
| 2270 |
+
requires mergeable<iterator_t<R1>, iterator_t<R2>, O, Comp, Proj1, Proj2>
|
| 2271 |
+
constexpr set_intersection_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>, O>
|
| 2272 |
+
set_intersection(R1&& r1, R2&& r2, O result,
|
| 2273 |
+
Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 2274 |
+
}
|
| 2275 |
+
|
| 2276 |
+
template<class InputIterator1, class InputIterator2, class OutputIterator>
|
| 2277 |
+
constexpr OutputIterator
|
| 2278 |
+
set_difference(InputIterator1 first1, InputIterator1 last1,
|
| 2279 |
+
InputIterator2 first2, InputIterator2 last2,
|
| 2280 |
+
OutputIterator result);
|
| 2281 |
+
template<class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
|
| 2282 |
+
constexpr OutputIterator
|
| 2283 |
+
set_difference(InputIterator1 first1, InputIterator1 last1,
|
| 2284 |
+
InputIterator2 first2, InputIterator2 last2,
|
| 2285 |
+
OutputIterator result, Compare comp);
|
| 2286 |
+
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 2287 |
+
class ForwardIterator>
|
| 2288 |
+
ForwardIterator
|
| 2289 |
+
set_difference(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 2290 |
+
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 2291 |
+
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 2292 |
+
ForwardIterator result);
|
| 2293 |
+
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 2294 |
+
class ForwardIterator, class Compare>
|
| 2295 |
+
ForwardIterator
|
| 2296 |
+
set_difference(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 2297 |
+
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 2298 |
+
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 2299 |
+
ForwardIterator result, Compare comp);
|
| 2300 |
+
|
| 2301 |
+
namespace ranges {
|
| 2302 |
+
template<class I, class O>
|
| 2303 |
+
using set_difference_result = in_out_result<I, O>;
|
| 2304 |
+
|
| 2305 |
+
template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2,
|
| 2306 |
+
weakly_incrementable O, class Comp = ranges::less,
|
| 2307 |
+
class Proj1 = identity, class Proj2 = identity>
|
| 2308 |
+
requires mergeable<I1, I2, O, Comp, Proj1, Proj2>
|
| 2309 |
+
constexpr set_difference_result<I1, O>
|
| 2310 |
+
set_difference(I1 first1, S1 last1, I2 first2, S2 last2, O result,
|
| 2311 |
+
Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 2312 |
+
template<input_range R1, input_range R2, weakly_incrementable O,
|
| 2313 |
+
class Comp = ranges::less, class Proj1 = identity, class Proj2 = identity>
|
| 2314 |
+
requires mergeable<iterator_t<R1>, iterator_t<R2>, O, Comp, Proj1, Proj2>
|
| 2315 |
+
constexpr set_difference_result<borrowed_iterator_t<R1>, O>
|
| 2316 |
+
set_difference(R1&& r1, R2&& r2, O result,
|
| 2317 |
+
Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 2318 |
+
}
|
| 2319 |
+
|
| 2320 |
+
template<class InputIterator1, class InputIterator2, class OutputIterator>
|
| 2321 |
+
constexpr OutputIterator
|
| 2322 |
+
set_symmetric_difference(InputIterator1 first1, InputIterator1 last1,
|
| 2323 |
+
InputIterator2 first2, InputIterator2 last2,
|
| 2324 |
+
OutputIterator result);
|
| 2325 |
+
template<class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
|
| 2326 |
+
constexpr OutputIterator
|
| 2327 |
+
set_symmetric_difference(InputIterator1 first1, InputIterator1 last1,
|
| 2328 |
+
InputIterator2 first2, InputIterator2 last2,
|
| 2329 |
+
OutputIterator result, Compare comp);
|
| 2330 |
+
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 2331 |
+
class ForwardIterator>
|
| 2332 |
+
ForwardIterator
|
| 2333 |
+
set_symmetric_difference(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 2334 |
+
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 2335 |
+
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 2336 |
+
ForwardIterator result);
|
| 2337 |
+
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 2338 |
+
class ForwardIterator, class Compare>
|
| 2339 |
+
ForwardIterator
|
| 2340 |
+
set_symmetric_difference(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 2341 |
+
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 2342 |
+
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 2343 |
+
ForwardIterator result, Compare comp);
|
| 2344 |
+
|
| 2345 |
+
namespace ranges {
|
| 2346 |
+
template<class I1, class I2, class O>
|
| 2347 |
+
using set_symmetric_difference_result = in_in_out_result<I1, I2, O>;
|
| 2348 |
+
|
| 2349 |
+
template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2,
|
| 2350 |
+
weakly_incrementable O, class Comp = ranges::less,
|
| 2351 |
+
class Proj1 = identity, class Proj2 = identity>
|
| 2352 |
+
requires mergeable<I1, I2, O, Comp, Proj1, Proj2>
|
| 2353 |
+
constexpr set_symmetric_difference_result<I1, I2, O>
|
| 2354 |
+
set_symmetric_difference(I1 first1, S1 last1, I2 first2, S2 last2, O result,
|
| 2355 |
+
Comp comp = {}, Proj1 proj1 = {},
|
| 2356 |
+
Proj2 proj2 = {});
|
| 2357 |
+
template<input_range R1, input_range R2, weakly_incrementable O,
|
| 2358 |
+
class Comp = ranges::less, class Proj1 = identity, class Proj2 = identity>
|
| 2359 |
+
requires mergeable<iterator_t<R1>, iterator_t<R2>, O, Comp, Proj1, Proj2>
|
| 2360 |
+
constexpr set_symmetric_difference_result<borrowed_iterator_t<R1>,
|
| 2361 |
+
borrowed_iterator_t<R2>, O>
|
| 2362 |
+
set_symmetric_difference(R1&& r1, R2&& r2, O result, Comp comp = {},
|
| 2363 |
+
Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 2364 |
+
}
|
| 2365 |
+
|
| 2366 |
+
// [alg.heap.operations], heap operations
|
| 2367 |
+
template<class RandomAccessIterator>
|
| 2368 |
+
constexpr void push_heap(RandomAccessIterator first, RandomAccessIterator last);
|
| 2369 |
+
template<class RandomAccessIterator, class Compare>
|
| 2370 |
+
constexpr void push_heap(RandomAccessIterator first, RandomAccessIterator last,
|
| 2371 |
+
Compare comp);
|
| 2372 |
+
|
| 2373 |
+
namespace ranges {
|
| 2374 |
+
template<random_access_iterator I, sentinel_for<I> S, class Comp = ranges::less,
|
| 2375 |
+
class Proj = identity>
|
| 2376 |
+
requires sortable<I, Comp, Proj>
|
| 2377 |
+
constexpr I
|
| 2378 |
+
push_heap(I first, S last, Comp comp = {}, Proj proj = {});
|
| 2379 |
+
template<random_access_range R, class Comp = ranges::less, class Proj = identity>
|
| 2380 |
+
requires sortable<iterator_t<R>, Comp, Proj>
|
| 2381 |
+
constexpr borrowed_iterator_t<R>
|
| 2382 |
+
push_heap(R&& r, Comp comp = {}, Proj proj = {});
|
| 2383 |
+
}
|
| 2384 |
+
|
| 2385 |
+
template<class RandomAccessIterator>
|
| 2386 |
+
constexpr void pop_heap(RandomAccessIterator first, RandomAccessIterator last);
|
| 2387 |
+
template<class RandomAccessIterator, class Compare>
|
| 2388 |
+
constexpr void pop_heap(RandomAccessIterator first, RandomAccessIterator last,
|
| 2389 |
+
Compare comp);
|
| 2390 |
+
|
| 2391 |
+
namespace ranges {
|
| 2392 |
+
template<random_access_iterator I, sentinel_for<I> S, class Comp = ranges::less,
|
| 2393 |
+
class Proj = identity>
|
| 2394 |
+
requires sortable<I, Comp, Proj>
|
| 2395 |
+
constexpr I
|
| 2396 |
+
pop_heap(I first, S last, Comp comp = {}, Proj proj = {});
|
| 2397 |
+
template<random_access_range R, class Comp = ranges::less, class Proj = identity>
|
| 2398 |
+
requires sortable<iterator_t<R>, Comp, Proj>
|
| 2399 |
+
constexpr borrowed_iterator_t<R>
|
| 2400 |
+
pop_heap(R&& r, Comp comp = {}, Proj proj = {});
|
| 2401 |
+
}
|
| 2402 |
+
|
| 2403 |
+
template<class RandomAccessIterator>
|
| 2404 |
+
constexpr void make_heap(RandomAccessIterator first, RandomAccessIterator last);
|
| 2405 |
+
template<class RandomAccessIterator, class Compare>
|
| 2406 |
+
constexpr void make_heap(RandomAccessIterator first, RandomAccessIterator last,
|
| 2407 |
+
Compare comp);
|
| 2408 |
+
|
| 2409 |
+
namespace ranges {
|
| 2410 |
+
template<random_access_iterator I, sentinel_for<I> S, class Comp = ranges::less,
|
| 2411 |
+
class Proj = identity>
|
| 2412 |
+
requires sortable<I, Comp, Proj>
|
| 2413 |
+
constexpr I
|
| 2414 |
+
make_heap(I first, S last, Comp comp = {}, Proj proj = {});
|
| 2415 |
+
template<random_access_range R, class Comp = ranges::less, class Proj = identity>
|
| 2416 |
+
requires sortable<iterator_t<R>, Comp, Proj>
|
| 2417 |
+
constexpr borrowed_iterator_t<R>
|
| 2418 |
+
make_heap(R&& r, Comp comp = {}, Proj proj = {});
|
| 2419 |
+
}
|
| 2420 |
+
|
| 2421 |
+
template<class RandomAccessIterator>
|
| 2422 |
+
constexpr void sort_heap(RandomAccessIterator first, RandomAccessIterator last);
|
| 2423 |
+
template<class RandomAccessIterator, class Compare>
|
| 2424 |
+
constexpr void sort_heap(RandomAccessIterator first, RandomAccessIterator last,
|
| 2425 |
+
Compare comp);
|
| 2426 |
+
|
| 2427 |
+
namespace ranges {
|
| 2428 |
+
template<random_access_iterator I, sentinel_for<I> S, class Comp = ranges::less,
|
| 2429 |
+
class Proj = identity>
|
| 2430 |
+
requires sortable<I, Comp, Proj>
|
| 2431 |
+
constexpr I
|
| 2432 |
+
sort_heap(I first, S last, Comp comp = {}, Proj proj = {});
|
| 2433 |
+
template<random_access_range R, class Comp = ranges::less, class Proj = identity>
|
| 2434 |
+
requires sortable<iterator_t<R>, Comp, Proj>
|
| 2435 |
+
constexpr borrowed_iterator_t<R>
|
| 2436 |
+
sort_heap(R&& r, Comp comp = {}, Proj proj = {});
|
| 2437 |
+
}
|
| 2438 |
+
|
| 2439 |
+
template<class RandomAccessIterator>
|
| 2440 |
+
constexpr bool is_heap(RandomAccessIterator first, RandomAccessIterator last);
|
| 2441 |
+
template<class RandomAccessIterator, class Compare>
|
| 2442 |
+
constexpr bool is_heap(RandomAccessIterator first, RandomAccessIterator last,
|
| 2443 |
+
Compare comp);
|
| 2444 |
+
template<class ExecutionPolicy, class RandomAccessIterator>
|
| 2445 |
+
bool is_heap(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 2446 |
+
RandomAccessIterator first, RandomAccessIterator last);
|
| 2447 |
+
template<class ExecutionPolicy, class RandomAccessIterator, class Compare>
|
| 2448 |
+
bool is_heap(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 2449 |
+
RandomAccessIterator first, RandomAccessIterator last,
|
| 2450 |
+
Compare comp);
|
| 2451 |
+
|
| 2452 |
+
namespace ranges {
|
| 2453 |
+
template<random_access_iterator I, sentinel_for<I> S, class Proj = identity,
|
| 2454 |
+
indirect_strict_weak_order<projected<I, Proj>> Comp = ranges::less>
|
| 2455 |
+
constexpr bool is_heap(I first, S last, Comp comp = {}, Proj proj = {});
|
| 2456 |
+
template<random_access_range R, class Proj = identity,
|
| 2457 |
+
indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less>
|
| 2458 |
+
constexpr bool is_heap(R&& r, Comp comp = {}, Proj proj = {});
|
| 2459 |
+
}
|
| 2460 |
+
|
| 2461 |
+
template<class RandomAccessIterator>
|
| 2462 |
+
constexpr RandomAccessIterator
|
| 2463 |
+
is_heap_until(RandomAccessIterator first, RandomAccessIterator last);
|
| 2464 |
+
template<class RandomAccessIterator, class Compare>
|
| 2465 |
+
constexpr RandomAccessIterator
|
| 2466 |
+
is_heap_until(RandomAccessIterator first, RandomAccessIterator last,
|
| 2467 |
+
Compare comp);
|
| 2468 |
+
template<class ExecutionPolicy, class RandomAccessIterator>
|
| 2469 |
+
RandomAccessIterator
|
| 2470 |
+
is_heap_until(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 2471 |
+
RandomAccessIterator first, RandomAccessIterator last);
|
| 2472 |
+
template<class ExecutionPolicy, class RandomAccessIterator, class Compare>
|
| 2473 |
+
RandomAccessIterator
|
| 2474 |
+
is_heap_until(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 2475 |
+
RandomAccessIterator first, RandomAccessIterator last,
|
| 2476 |
+
Compare comp);
|
| 2477 |
+
|
| 2478 |
+
namespace ranges {
|
| 2479 |
+
template<random_access_iterator I, sentinel_for<I> S, class Proj = identity,
|
| 2480 |
+
indirect_strict_weak_order<projected<I, Proj>> Comp = ranges::less>
|
| 2481 |
+
constexpr I is_heap_until(I first, S last, Comp comp = {}, Proj proj = {});
|
| 2482 |
+
template<random_access_range R, class Proj = identity,
|
| 2483 |
+
indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less>
|
| 2484 |
+
constexpr borrowed_iterator_t<R>
|
| 2485 |
+
is_heap_until(R&& r, Comp comp = {}, Proj proj = {});
|
| 2486 |
+
}
|
| 2487 |
+
|
| 2488 |
+
// [alg.min.max], minimum and maximum
|
| 2489 |
+
template<class T> constexpr const T& min(const T& a, const T& b);
|
| 2490 |
+
template<class T, class Compare>
|
| 2491 |
+
constexpr const T& min(const T& a, const T& b, Compare comp);
|
| 2492 |
+
template<class T>
|
| 2493 |
+
constexpr T min(initializer_list<T> t);
|
| 2494 |
+
template<class T, class Compare>
|
| 2495 |
+
constexpr T min(initializer_list<T> t, Compare comp);
|
| 2496 |
+
|
| 2497 |
+
namespace ranges {
|
| 2498 |
+
template<class T, class Proj = identity,
|
| 2499 |
+
indirect_strict_weak_order<projected<const T*, Proj>> Comp = ranges::less>
|
| 2500 |
+
constexpr const T& min(const T& a, const T& b, Comp comp = {}, Proj proj = {});
|
| 2501 |
+
template<copyable T, class Proj = identity,
|
| 2502 |
+
indirect_strict_weak_order<projected<const T*, Proj>> Comp = ranges::less>
|
| 2503 |
+
constexpr T min(initializer_list<T> r, Comp comp = {}, Proj proj = {});
|
| 2504 |
+
template<input_range R, class Proj = identity,
|
| 2505 |
+
indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less>
|
| 2506 |
+
requires indirectly_copyable_storable<iterator_t<R>, range_value_t<R>*>
|
| 2507 |
+
constexpr range_value_t<R>
|
| 2508 |
+
min(R&& r, Comp comp = {}, Proj proj = {});
|
| 2509 |
+
}
|
| 2510 |
+
|
| 2511 |
+
template<class T> constexpr const T& max(const T& a, const T& b);
|
| 2512 |
+
template<class T, class Compare>
|
| 2513 |
+
constexpr const T& max(const T& a, const T& b, Compare comp);
|
| 2514 |
+
template<class T>
|
| 2515 |
+
constexpr T max(initializer_list<T> t);
|
| 2516 |
+
template<class T, class Compare>
|
| 2517 |
+
constexpr T max(initializer_list<T> t, Compare comp);
|
| 2518 |
+
|
| 2519 |
+
namespace ranges {
|
| 2520 |
+
template<class T, class Proj = identity,
|
| 2521 |
+
indirect_strict_weak_order<projected<const T*, Proj>> Comp = ranges::less>
|
| 2522 |
+
constexpr const T& max(const T& a, const T& b, Comp comp = {}, Proj proj = {});
|
| 2523 |
+
template<copyable T, class Proj = identity,
|
| 2524 |
+
indirect_strict_weak_order<projected<const T*, Proj>> Comp = ranges::less>
|
| 2525 |
+
constexpr T max(initializer_list<T> r, Comp comp = {}, Proj proj = {});
|
| 2526 |
+
template<input_range R, class Proj = identity,
|
| 2527 |
+
indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less>
|
| 2528 |
+
requires indirectly_copyable_storable<iterator_t<R>, range_value_t<R>*>
|
| 2529 |
+
constexpr range_value_t<R>
|
| 2530 |
+
max(R&& r, Comp comp = {}, Proj proj = {});
|
| 2531 |
+
}
|
| 2532 |
+
|
| 2533 |
+
template<class T> constexpr pair<const T&, const T&> minmax(const T& a, const T& b);
|
| 2534 |
+
template<class T, class Compare>
|
| 2535 |
+
constexpr pair<const T&, const T&> minmax(const T& a, const T& b, Compare comp);
|
| 2536 |
+
template<class T>
|
| 2537 |
+
constexpr pair<T, T> minmax(initializer_list<T> t);
|
| 2538 |
+
template<class T, class Compare>
|
| 2539 |
+
constexpr pair<T, T> minmax(initializer_list<T> t, Compare comp);
|
| 2540 |
+
|
| 2541 |
+
namespace ranges {
|
| 2542 |
+
template<class T>
|
| 2543 |
+
using minmax_result = min_max_result<T>;
|
| 2544 |
+
|
| 2545 |
+
template<class T, class Proj = identity,
|
| 2546 |
+
indirect_strict_weak_order<projected<const T*, Proj>> Comp = ranges::less>
|
| 2547 |
+
constexpr minmax_result<const T&>
|
| 2548 |
+
minmax(const T& a, const T& b, Comp comp = {}, Proj proj = {});
|
| 2549 |
+
template<copyable T, class Proj = identity,
|
| 2550 |
+
indirect_strict_weak_order<projected<const T*, Proj>> Comp = ranges::less>
|
| 2551 |
+
constexpr minmax_result<T>
|
| 2552 |
+
minmax(initializer_list<T> r, Comp comp = {}, Proj proj = {});
|
| 2553 |
+
template<input_range R, class Proj = identity,
|
| 2554 |
+
indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less>
|
| 2555 |
+
requires indirectly_copyable_storable<iterator_t<R>, range_value_t<R>*>
|
| 2556 |
+
constexpr minmax_result<range_value_t<R>>
|
| 2557 |
+
minmax(R&& r, Comp comp = {}, Proj proj = {});
|
| 2558 |
+
}
|
| 2559 |
+
|
| 2560 |
+
template<class ForwardIterator>
|
| 2561 |
+
constexpr ForwardIterator min_element(ForwardIterator first, ForwardIterator last);
|
| 2562 |
+
template<class ForwardIterator, class Compare>
|
| 2563 |
+
constexpr ForwardIterator min_element(ForwardIterator first, ForwardIterator last,
|
| 2564 |
+
Compare comp);
|
| 2565 |
+
template<class ExecutionPolicy, class ForwardIterator>
|
| 2566 |
+
ForwardIterator min_element(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 2567 |
+
ForwardIterator first, ForwardIterator last);
|
| 2568 |
+
template<class ExecutionPolicy, class ForwardIterator, class Compare>
|
| 2569 |
+
ForwardIterator min_element(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 2570 |
+
ForwardIterator first, ForwardIterator last,
|
| 2571 |
+
Compare comp);
|
| 2572 |
+
|
| 2573 |
+
namespace ranges {
|
| 2574 |
+
template<forward_iterator I, sentinel_for<I> S, class Proj = identity,
|
| 2575 |
+
indirect_strict_weak_order<projected<I, Proj>> Comp = ranges::less>
|
| 2576 |
+
constexpr I min_element(I first, S last, Comp comp = {}, Proj proj = {});
|
| 2577 |
+
template<forward_range R, class Proj = identity,
|
| 2578 |
+
indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less>
|
| 2579 |
+
constexpr borrowed_iterator_t<R>
|
| 2580 |
+
min_element(R&& r, Comp comp = {}, Proj proj = {});
|
| 2581 |
+
}
|
| 2582 |
+
|
| 2583 |
+
template<class ForwardIterator>
|
| 2584 |
+
constexpr ForwardIterator max_element(ForwardIterator first, ForwardIterator last);
|
| 2585 |
+
template<class ForwardIterator, class Compare>
|
| 2586 |
+
constexpr ForwardIterator max_element(ForwardIterator first, ForwardIterator last,
|
| 2587 |
+
Compare comp);
|
| 2588 |
+
template<class ExecutionPolicy, class ForwardIterator>
|
| 2589 |
+
ForwardIterator max_element(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 2590 |
+
ForwardIterator first, ForwardIterator last);
|
| 2591 |
+
template<class ExecutionPolicy, class ForwardIterator, class Compare>
|
| 2592 |
+
ForwardIterator max_element(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 2593 |
+
ForwardIterator first, ForwardIterator last,
|
| 2594 |
+
Compare comp);
|
| 2595 |
+
|
| 2596 |
+
namespace ranges {
|
| 2597 |
+
template<forward_iterator I, sentinel_for<I> S, class Proj = identity,
|
| 2598 |
+
indirect_strict_weak_order<projected<I, Proj>> Comp = ranges::less>
|
| 2599 |
+
constexpr I max_element(I first, S last, Comp comp = {}, Proj proj = {});
|
| 2600 |
+
template<forward_range R, class Proj = identity,
|
| 2601 |
+
indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less>
|
| 2602 |
+
constexpr borrowed_iterator_t<R>
|
| 2603 |
+
max_element(R&& r, Comp comp = {}, Proj proj = {});
|
| 2604 |
+
}
|
| 2605 |
+
|
| 2606 |
+
template<class ForwardIterator>
|
| 2607 |
+
constexpr pair<ForwardIterator, ForwardIterator>
|
| 2608 |
+
minmax_element(ForwardIterator first, ForwardIterator last);
|
| 2609 |
+
template<class ForwardIterator, class Compare>
|
| 2610 |
+
constexpr pair<ForwardIterator, ForwardIterator>
|
| 2611 |
+
minmax_element(ForwardIterator first, ForwardIterator last, Compare comp);
|
| 2612 |
+
template<class ExecutionPolicy, class ForwardIterator>
|
| 2613 |
+
pair<ForwardIterator, ForwardIterator>
|
| 2614 |
+
minmax_element(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 2615 |
+
ForwardIterator first, ForwardIterator last);
|
| 2616 |
+
template<class ExecutionPolicy, class ForwardIterator, class Compare>
|
| 2617 |
+
pair<ForwardIterator, ForwardIterator>
|
| 2618 |
+
minmax_element(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 2619 |
+
ForwardIterator first, ForwardIterator last, Compare comp);
|
| 2620 |
+
|
| 2621 |
+
namespace ranges {
|
| 2622 |
+
template<class I>
|
| 2623 |
+
using minmax_element_result = min_max_result<I>;
|
| 2624 |
+
|
| 2625 |
+
template<forward_iterator I, sentinel_for<I> S, class Proj = identity,
|
| 2626 |
+
indirect_strict_weak_order<projected<I, Proj>> Comp = ranges::less>
|
| 2627 |
+
constexpr minmax_element_result<I>
|
| 2628 |
+
minmax_element(I first, S last, Comp comp = {}, Proj proj = {});
|
| 2629 |
+
template<forward_range R, class Proj = identity,
|
| 2630 |
+
indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less>
|
| 2631 |
+
constexpr minmax_element_result<borrowed_iterator_t<R>>
|
| 2632 |
+
minmax_element(R&& r, Comp comp = {}, Proj proj = {});
|
| 2633 |
+
}
|
| 2634 |
+
|
| 2635 |
+
// [alg.clamp], bounded value
|
| 2636 |
+
template<class T>
|
| 2637 |
+
constexpr const T& clamp(const T& v, const T& lo, const T& hi);
|
| 2638 |
+
template<class T, class Compare>
|
| 2639 |
+
constexpr const T& clamp(const T& v, const T& lo, const T& hi, Compare comp);
|
| 2640 |
+
|
| 2641 |
+
namespace ranges {
|
| 2642 |
+
template<class T, class Proj = identity,
|
| 2643 |
+
indirect_strict_weak_order<projected<const T*, Proj>> Comp = ranges::less>
|
| 2644 |
+
constexpr const T&
|
| 2645 |
+
clamp(const T& v, const T& lo, const T& hi, Comp comp = {}, Proj proj = {});
|
| 2646 |
+
}
|
| 2647 |
+
|
| 2648 |
+
// [alg.lex.comparison], lexicographical comparison
|
| 2649 |
+
template<class InputIterator1, class InputIterator2>
|
| 2650 |
+
constexpr bool
|
| 2651 |
+
lexicographical_compare(InputIterator1 first1, InputIterator1 last1,
|
| 2652 |
+
InputIterator2 first2, InputIterator2 last2);
|
| 2653 |
+
template<class InputIterator1, class InputIterator2, class Compare>
|
| 2654 |
+
constexpr bool
|
| 2655 |
+
lexicographical_compare(InputIterator1 first1, InputIterator1 last1,
|
| 2656 |
+
InputIterator2 first2, InputIterator2 last2,
|
| 2657 |
+
Compare comp);
|
| 2658 |
+
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 2659 |
+
bool
|
| 2660 |
+
lexicographical_compare(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 2661 |
+
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 2662 |
+
ForwardIterator2 first2, ForwardIterator2 last2);
|
| 2663 |
+
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 2664 |
+
class Compare>
|
| 2665 |
+
bool
|
| 2666 |
+
lexicographical_compare(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 2667 |
+
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 2668 |
+
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 2669 |
+
Compare comp);
|
| 2670 |
+
|
| 2671 |
+
namespace ranges {
|
| 2672 |
+
template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2,
|
| 2673 |
+
class Proj1 = identity, class Proj2 = identity,
|
| 2674 |
+
indirect_strict_weak_order<projected<I1, Proj1>, projected<I2, Proj2>> Comp =
|
| 2675 |
+
ranges::less>
|
| 2676 |
+
constexpr bool
|
| 2677 |
+
lexicographical_compare(I1 first1, S1 last1, I2 first2, S2 last2,
|
| 2678 |
+
Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 2679 |
+
template<input_range R1, input_range R2, class Proj1 = identity,
|
| 2680 |
+
class Proj2 = identity,
|
| 2681 |
+
indirect_strict_weak_order<projected<iterator_t<R1>, Proj1>,
|
| 2682 |
+
projected<iterator_t<R2>, Proj2>> Comp = ranges::less>
|
| 2683 |
+
constexpr bool
|
| 2684 |
+
lexicographical_compare(R1&& r1, R2&& r2, Comp comp = {},
|
| 2685 |
+
Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 2686 |
+
}
|
| 2687 |
+
|
| 2688 |
+
// [alg.three.way], three-way comparison algorithms
|
| 2689 |
+
template<class InputIterator1, class InputIterator2, class Cmp>
|
| 2690 |
+
constexpr auto
|
| 2691 |
+
lexicographical_compare_three_way(InputIterator1 b1, InputIterator1 e1,
|
| 2692 |
+
InputIterator2 b2, InputIterator2 e2,
|
| 2693 |
+
Cmp comp)
|
| 2694 |
+
-> decltype(comp(*b1, *b2));
|
| 2695 |
+
template<class InputIterator1, class InputIterator2>
|
| 2696 |
+
constexpr auto
|
| 2697 |
+
lexicographical_compare_three_way(InputIterator1 b1, InputIterator1 e1,
|
| 2698 |
+
InputIterator2 b2, InputIterator2 e2);
|
| 2699 |
+
|
| 2700 |
+
// [alg.permutation.generators], permutations
|
| 2701 |
+
template<class BidirectionalIterator>
|
| 2702 |
+
constexpr bool next_permutation(BidirectionalIterator first,
|
| 2703 |
+
BidirectionalIterator last);
|
| 2704 |
+
template<class BidirectionalIterator, class Compare>
|
| 2705 |
+
constexpr bool next_permutation(BidirectionalIterator first,
|
| 2706 |
+
BidirectionalIterator last, Compare comp);
|
| 2707 |
+
|
| 2708 |
+
namespace ranges {
|
| 2709 |
+
template<class I>
|
| 2710 |
+
using next_permutation_result = in_found_result<I>;
|
| 2711 |
+
|
| 2712 |
+
template<bidirectional_iterator I, sentinel_for<I> S, class Comp = ranges::less,
|
| 2713 |
+
class Proj = identity>
|
| 2714 |
+
requires sortable<I, Comp, Proj>
|
| 2715 |
+
constexpr next_permutation_result<I>
|
| 2716 |
+
next_permutation(I first, S last, Comp comp = {}, Proj proj = {});
|
| 2717 |
+
template<bidirectional_range R, class Comp = ranges::less,
|
| 2718 |
+
class Proj = identity>
|
| 2719 |
+
requires sortable<iterator_t<R>, Comp, Proj>
|
| 2720 |
+
constexpr next_permutation_result<borrowed_iterator_t<R>>
|
| 2721 |
+
next_permutation(R&& r, Comp comp = {}, Proj proj = {});
|
| 2722 |
+
}
|
| 2723 |
+
|
| 2724 |
+
template<class BidirectionalIterator>
|
| 2725 |
+
constexpr bool prev_permutation(BidirectionalIterator first,
|
| 2726 |
+
BidirectionalIterator last);
|
| 2727 |
+
template<class BidirectionalIterator, class Compare>
|
| 2728 |
+
constexpr bool prev_permutation(BidirectionalIterator first,
|
| 2729 |
+
BidirectionalIterator last, Compare comp);
|
| 2730 |
+
|
| 2731 |
+
namespace ranges {
|
| 2732 |
+
template<class I>
|
| 2733 |
+
using prev_permutation_result = in_found_result<I>;
|
| 2734 |
+
|
| 2735 |
+
template<bidirectional_iterator I, sentinel_for<I> S, class Comp = ranges::less,
|
| 2736 |
+
class Proj = identity>
|
| 2737 |
+
requires sortable<I, Comp, Proj>
|
| 2738 |
+
constexpr prev_permutation_result<I>
|
| 2739 |
+
prev_permutation(I first, S last, Comp comp = {}, Proj proj = {});
|
| 2740 |
+
template<bidirectional_range R, class Comp = ranges::less,
|
| 2741 |
+
class Proj = identity>
|
| 2742 |
+
requires sortable<iterator_t<R>, Comp, Proj>
|
| 2743 |
+
constexpr prev_permutation_result<borrowed_iterator_t<R>>
|
| 2744 |
+
prev_permutation(R&& r, Comp comp = {}, Proj proj = {});
|
| 2745 |
+
}
|
| 2746 |
+
}
|
| 2747 |
+
```
|
| 2748 |
+
|
| 2749 |
+
## Algorithm result types <a id="algorithms.results">[[algorithms.results]]</a>
|
| 2750 |
+
|
| 2751 |
+
Each of the class templates specified in this subclause has the template
|
| 2752 |
+
parameters, data members, and special members specified below, and has
|
| 2753 |
+
no base classes or members other than those specified.
|
| 2754 |
+
|
| 2755 |
+
``` cpp
|
| 2756 |
+
namespace std::ranges {
|
| 2757 |
+
template<class I, class F>
|
| 2758 |
+
struct in_fun_result {
|
| 2759 |
+
[[no_unique_address]] I in;
|
| 2760 |
+
[[no_unique_address]] F fun;
|
| 2761 |
+
|
| 2762 |
+
template<class I2, class F2>
|
| 2763 |
+
requires convertible_to<const I&, I2> && convertible_to<const F&, F2>
|
| 2764 |
+
constexpr operator in_fun_result<I2, F2>() const & {
|
| 2765 |
+
return {in, fun};
|
| 2766 |
+
}
|
| 2767 |
+
|
| 2768 |
+
template<class I2, class F2>
|
| 2769 |
+
requires convertible_to<I, I2> && convertible_to<F, F2>
|
| 2770 |
+
constexpr operator in_fun_result<I2, F2>() && {
|
| 2771 |
+
return {std::move(in), std::move(fun)};
|
| 2772 |
+
}
|
| 2773 |
+
};
|
| 2774 |
+
|
| 2775 |
+
template<class I1, class I2>
|
| 2776 |
+
struct in_in_result {
|
| 2777 |
+
[[no_unique_address]] I1 in1;
|
| 2778 |
+
[[no_unique_address]] I2 in2;
|
| 2779 |
+
|
| 2780 |
+
template<class II1, class II2>
|
| 2781 |
+
requires convertible_to<const I1&, II1> && convertible_to<const I2&, II2>
|
| 2782 |
+
constexpr operator in_in_result<II1, II2>() const & {
|
| 2783 |
+
return {in1, in2};
|
| 2784 |
+
}
|
| 2785 |
+
|
| 2786 |
+
template<class II1, class II2>
|
| 2787 |
+
requires convertible_to<I1, II1> && convertible_to<I2, II2>
|
| 2788 |
+
constexpr operator in_in_result<II1, II2>() && {
|
| 2789 |
+
return {std::move(in1), std::move(in2)};
|
| 2790 |
+
}
|
| 2791 |
+
};
|
| 2792 |
+
|
| 2793 |
+
template<class I, class O>
|
| 2794 |
+
struct in_out_result {
|
| 2795 |
+
[[no_unique_address]] I in;
|
| 2796 |
+
[[no_unique_address]] O out;
|
| 2797 |
+
|
| 2798 |
+
template<class I2, class O2>
|
| 2799 |
+
requires convertible_to<const I&, I2> && convertible_to<const O&, O2>
|
| 2800 |
+
constexpr operator in_out_result<I2, O2>() const & {
|
| 2801 |
+
return {in, out};
|
| 2802 |
+
}
|
| 2803 |
+
|
| 2804 |
+
template<class I2, class O2>
|
| 2805 |
+
requires convertible_to<I, I2> && convertible_to<O, O2>
|
| 2806 |
+
constexpr operator in_out_result<I2, O2>() && {
|
| 2807 |
+
return {std::move(in), std::move(out)};
|
| 2808 |
+
}
|
| 2809 |
+
};
|
| 2810 |
+
|
| 2811 |
+
template<class I1, class I2, class O>
|
| 2812 |
+
struct in_in_out_result {
|
| 2813 |
+
[[no_unique_address]] I1 in1;
|
| 2814 |
+
[[no_unique_address]] I2 in2;
|
| 2815 |
+
[[no_unique_address]] O out;
|
| 2816 |
+
|
| 2817 |
+
template<class II1, class II2, class OO>
|
| 2818 |
+
requires convertible_to<const I1&, II1> &&
|
| 2819 |
+
convertible_to<const I2&, II2> &&
|
| 2820 |
+
convertible_to<const O&, OO>
|
| 2821 |
+
constexpr operator in_in_out_result<II1, II2, OO>() const & {
|
| 2822 |
+
return {in1, in2, out};
|
| 2823 |
+
}
|
| 2824 |
+
|
| 2825 |
+
template<class II1, class II2, class OO>
|
| 2826 |
+
requires convertible_to<I1, II1> &&
|
| 2827 |
+
convertible_to<I2, II2> &&
|
| 2828 |
+
convertible_to<O, OO>
|
| 2829 |
+
constexpr operator in_in_out_result<II1, II2, OO>() && {
|
| 2830 |
+
return {std::move(in1), std::move(in2), std::move(out)};
|
| 2831 |
+
}
|
| 2832 |
+
};
|
| 2833 |
+
|
| 2834 |
+
template<class I, class O1, class O2>
|
| 2835 |
+
struct in_out_out_result {
|
| 2836 |
+
[[no_unique_address]] I in;
|
| 2837 |
+
[[no_unique_address]] O1 out1;
|
| 2838 |
+
[[no_unique_address]] O2 out2;
|
| 2839 |
+
|
| 2840 |
+
template<class II, class OO1, class OO2>
|
| 2841 |
+
requires convertible_to<const I&, II> &&
|
| 2842 |
+
convertible_to<const O1&, OO1> &&
|
| 2843 |
+
convertible_to<const O2&, OO2>
|
| 2844 |
+
constexpr operator in_out_out_result<II, OO1, OO2>() const & {
|
| 2845 |
+
return {in, out1, out2};
|
| 2846 |
+
}
|
| 2847 |
+
|
| 2848 |
+
template<class II, class OO1, class OO2>
|
| 2849 |
+
requires convertible_to<I, II> &&
|
| 2850 |
+
convertible_to<O1, OO1> &&
|
| 2851 |
+
convertible_to<O2, OO2>
|
| 2852 |
+
constexpr operator in_out_out_result<II, OO1, OO2>() && {
|
| 2853 |
+
return {std::move(in), std::move(out1), std::move(out2)};
|
| 2854 |
+
}
|
| 2855 |
+
};
|
| 2856 |
+
|
| 2857 |
+
template<class T>
|
| 2858 |
+
struct min_max_result {
|
| 2859 |
+
[[no_unique_address]] T min;
|
| 2860 |
+
[[no_unique_address]] T max;
|
| 2861 |
+
|
| 2862 |
+
template<class T2>
|
| 2863 |
+
requires convertible_to<const T&, T2>
|
| 2864 |
+
constexpr operator min_max_result<T2>() const & {
|
| 2865 |
+
return {min, max};
|
| 2866 |
+
}
|
| 2867 |
+
|
| 2868 |
+
template<class T2>
|
| 2869 |
+
requires convertible_to<T, T2>
|
| 2870 |
+
constexpr operator min_max_result<T2>() && {
|
| 2871 |
+
return {std::move(min), std::move(max)};
|
| 2872 |
+
}
|
| 2873 |
+
};
|
| 2874 |
+
|
| 2875 |
+
template<class I>
|
| 2876 |
+
struct in_found_result {
|
| 2877 |
+
[[no_unique_address]] I in;
|
| 2878 |
+
bool found;
|
| 2879 |
+
|
| 2880 |
+
template<class I2>
|
| 2881 |
+
requires convertible_to<const I&, I2>
|
| 2882 |
+
constexpr operator in_found_result<I2>() const & {
|
| 2883 |
+
return {in, found};
|
| 2884 |
+
}
|
| 2885 |
+
template<class I2>
|
| 2886 |
+
requires convertible_to<I, I2>
|
| 2887 |
+
constexpr operator in_found_result<I2>() && {
|
| 2888 |
+
return {std::move(in), found};
|
| 2889 |
+
}
|
| 2890 |
+
};
|
| 2891 |
+
}
|
| 2892 |
+
```
|
| 2893 |
|
| 2894 |
## Non-modifying sequence operations <a id="alg.nonmodifying">[[alg.nonmodifying]]</a>
|
| 2895 |
|
| 2896 |
+
### All of <a id="alg.all.of">[[alg.all.of]]</a>
|
| 2897 |
|
| 2898 |
``` cpp
|
| 2899 |
template<class InputIterator, class Predicate>
|
| 2900 |
+
constexpr bool all_of(InputIterator first, InputIterator last, Predicate pred);
|
| 2901 |
template<class ExecutionPolicy, class ForwardIterator, class Predicate>
|
| 2902 |
bool all_of(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last,
|
| 2903 |
Predicate pred);
|
| 2904 |
+
|
| 2905 |
+
template<input_iterator I, sentinel_for<I> S, class Proj = identity,
|
| 2906 |
+
indirect_unary_predicate<projected<I, Proj>> Pred>
|
| 2907 |
+
constexpr bool ranges::all_of(I first, S last, Pred pred, Proj proj = {});
|
| 2908 |
+
template<input_range R, class Proj = identity,
|
| 2909 |
+
indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
|
| 2910 |
+
constexpr bool ranges::all_of(R&& r, Pred pred, Proj proj = {});
|
| 2911 |
```
|
| 2912 |
|
| 2913 |
+
Let E be:
|
|
|
|
|
|
|
| 2914 |
|
| 2915 |
+
- `pred(*i)` for the overloads in namespace `std`;
|
| 2916 |
+
- `invoke(pred, invoke(proj, *i))` for the overloads in namespace
|
| 2917 |
+
`ranges`.
|
| 2918 |
|
| 2919 |
+
*Returns:* `false` if E is `false` for some iterator `i` in the range
|
| 2920 |
+
\[`first`, `last`), and `true` otherwise.
|
| 2921 |
+
|
| 2922 |
+
*Complexity:* At most `last - first` applications of the predicate and
|
| 2923 |
+
any projection.
|
| 2924 |
+
|
| 2925 |
+
### Any of <a id="alg.any.of">[[alg.any.of]]</a>
|
| 2926 |
|
| 2927 |
``` cpp
|
| 2928 |
template<class InputIterator, class Predicate>
|
| 2929 |
+
constexpr bool any_of(InputIterator first, InputIterator last, Predicate pred);
|
| 2930 |
template<class ExecutionPolicy, class ForwardIterator, class Predicate>
|
| 2931 |
bool any_of(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last,
|
| 2932 |
Predicate pred);
|
| 2933 |
+
|
| 2934 |
+
template<input_iterator I, sentinel_for<I> S, class Proj = identity,
|
| 2935 |
+
indirect_unary_predicate<projected<I, Proj>> Pred>
|
| 2936 |
+
constexpr bool ranges::any_of(I first, S last, Pred pred, Proj proj = {});
|
| 2937 |
+
template<input_range R, class Proj = identity,
|
| 2938 |
+
indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
|
| 2939 |
+
constexpr bool ranges::any_of(R&& r, Pred pred, Proj proj = {});
|
| 2940 |
```
|
| 2941 |
|
| 2942 |
+
Let E be:
|
|
|
|
|
|
|
| 2943 |
|
| 2944 |
+
- `pred(*i)` for the overloads in namespace `std`;
|
| 2945 |
+
- `invoke(pred, invoke(proj, *i))` for the overloads in namespace
|
| 2946 |
+
`ranges`.
|
| 2947 |
|
| 2948 |
+
*Returns:* `true` if E is `true` for some iterator `i` in the range
|
| 2949 |
+
\[`first`, `last`), and `false` otherwise.
|
| 2950 |
+
|
| 2951 |
+
*Complexity:* At most `last - first` applications of the predicate and
|
| 2952 |
+
any projection.
|
| 2953 |
+
|
| 2954 |
+
### None of <a id="alg.none.of">[[alg.none.of]]</a>
|
| 2955 |
|
| 2956 |
``` cpp
|
| 2957 |
template<class InputIterator, class Predicate>
|
| 2958 |
+
constexpr bool none_of(InputIterator first, InputIterator last, Predicate pred);
|
| 2959 |
template<class ExecutionPolicy, class ForwardIterator, class Predicate>
|
| 2960 |
bool none_of(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last,
|
| 2961 |
Predicate pred);
|
| 2962 |
+
|
| 2963 |
+
template<input_iterator I, sentinel_for<I> S, class Proj = identity,
|
| 2964 |
+
indirect_unary_predicate<projected<I, Proj>> Pred>
|
| 2965 |
+
constexpr bool ranges::none_of(I first, S last, Pred pred, Proj proj = {});
|
| 2966 |
+
template<input_range R, class Proj = identity,
|
| 2967 |
+
indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
|
| 2968 |
+
constexpr bool ranges::none_of(R&& r, Pred pred, Proj proj = {});
|
| 2969 |
```
|
| 2970 |
|
| 2971 |
+
Let E be:
|
|
|
|
|
|
|
| 2972 |
|
| 2973 |
+
- `pred(*i)` for the overloads in namespace `std`;
|
| 2974 |
+
- `invoke(pred, invoke(proj, *i))` for the overloads in namespace
|
| 2975 |
+
`ranges`.
|
| 2976 |
+
|
| 2977 |
+
*Returns:* `false` if E is `true` for some iterator `i` in the range
|
| 2978 |
+
\[`first`, `last`), and `true` otherwise.
|
| 2979 |
+
|
| 2980 |
+
*Complexity:* At most `last - first` applications of the predicate and
|
| 2981 |
+
any projection.
|
| 2982 |
|
| 2983 |
### For each <a id="alg.foreach">[[alg.foreach]]</a>
|
| 2984 |
|
| 2985 |
``` cpp
|
| 2986 |
template<class InputIterator, class Function>
|
| 2987 |
+
constexpr Function for_each(InputIterator first, InputIterator last, Function f);
|
| 2988 |
```
|
| 2989 |
|
| 2990 |
+
*Preconditions:* `Function` meets the *Cpp17MoveConstructible*
|
| 2991 |
+
requirements ([[cpp17.moveconstructible]]).
|
| 2992 |
|
| 2993 |
[*Note 1*: `Function` need not meet the requirements of
|
| 2994 |
+
*Cpp17CopyConstructible* ([[cpp17.copyconstructible]]). — *end note*]
|
| 2995 |
|
| 2996 |
*Effects:* Applies `f` to the result of dereferencing every iterator in
|
| 2997 |
the range \[`first`, `last`), starting from `first` and proceeding to
|
| 2998 |
`last - 1`.
|
| 2999 |
|
| 3000 |
+
[*Note 2*: If the type of `first` meets the requirements of a mutable
|
| 3001 |
+
iterator, `f` may apply non-constant functions through the dereferenced
|
| 3002 |
+
iterator. — *end note*]
|
| 3003 |
|
| 3004 |
*Returns:* `f`.
|
| 3005 |
|
| 3006 |
*Complexity:* Applies `f` exactly `last - first` times.
|
| 3007 |
|
|
|
|
| 3012 |
void for_each(ExecutionPolicy&& exec,
|
| 3013 |
ForwardIterator first, ForwardIterator last,
|
| 3014 |
Function f);
|
| 3015 |
```
|
| 3016 |
|
| 3017 |
+
*Preconditions:* `Function` meets the *Cpp17CopyConstructible*
|
| 3018 |
+
requirements.
|
| 3019 |
|
| 3020 |
*Effects:* Applies `f` to the result of dereferencing every iterator in
|
| 3021 |
the range \[`first`, `last`).
|
| 3022 |
|
| 3023 |
+
[*Note 3*: If the type of `first` meets the requirements of a mutable
|
| 3024 |
+
iterator, `f` may apply non-constant functions through the dereferenced
|
| 3025 |
+
iterator. — *end note*]
|
| 3026 |
|
| 3027 |
*Complexity:* Applies `f` exactly `last - first` times.
|
| 3028 |
|
| 3029 |
*Remarks:* If `f` returns a result, the result is ignored.
|
| 3030 |
Implementations do not have the freedom granted under
|
|
|
|
| 3033 |
|
| 3034 |
[*Note 4*: Does not return a copy of its `Function` parameter, since
|
| 3035 |
parallelization may not permit efficient state
|
| 3036 |
accumulation. — *end note*]
|
| 3037 |
|
| 3038 |
+
``` cpp
|
| 3039 |
+
template<input_iterator I, sentinel_for<I> S, class Proj = identity,
|
| 3040 |
+
indirectly_unary_invocable<projected<I, Proj>> Fun>
|
| 3041 |
+
constexpr ranges::for_each_result<I, Fun>
|
| 3042 |
+
ranges::for_each(I first, S last, Fun f, Proj proj = {});
|
| 3043 |
+
template<input_range R, class Proj = identity,
|
| 3044 |
+
indirectly_unary_invocable<projected<iterator_t<R>, Proj>> Fun>
|
| 3045 |
+
constexpr ranges::for_each_result<borrowed_iterator_t<R>, Fun>
|
| 3046 |
+
ranges::for_each(R&& r, Fun f, Proj proj = {});
|
| 3047 |
+
```
|
| 3048 |
+
|
| 3049 |
+
*Effects:* Calls `invoke(f, invoke(proj, *i))` for every iterator `i` in
|
| 3050 |
+
the range \[`first`, `last`), starting from `first` and proceeding to
|
| 3051 |
+
`last - 1`.
|
| 3052 |
+
|
| 3053 |
+
[*Note 5*: If the result of `invoke(proj, *i)` is a mutable reference,
|
| 3054 |
+
`f` may apply non-constant functions. — *end note*]
|
| 3055 |
+
|
| 3056 |
+
*Returns:* `{last, std::move(f)}`.
|
| 3057 |
+
|
| 3058 |
+
*Complexity:* Applies `f` and `proj` exactly `last - first` times.
|
| 3059 |
+
|
| 3060 |
+
*Remarks:* If `f` returns a result, the result is ignored.
|
| 3061 |
+
|
| 3062 |
+
[*Note 6*: The overloads in namespace `ranges` require `Fun` to model
|
| 3063 |
+
`copy_constructible`. — *end note*]
|
| 3064 |
+
|
| 3065 |
``` cpp
|
| 3066 |
template<class InputIterator, class Size, class Function>
|
| 3067 |
+
constexpr InputIterator for_each_n(InputIterator first, Size n, Function f);
|
| 3068 |
```
|
| 3069 |
|
| 3070 |
+
*Mandates:* The type `Size` is convertible to an integral
|
| 3071 |
+
type ([[conv.integral]], [[class.conv]]).
|
| 3072 |
|
| 3073 |
+
*Preconditions:* `Function` meets the *Cpp17MoveConstructible*
|
| 3074 |
+
requirements.
|
| 3075 |
|
| 3076 |
+
[*Note 7*: `Function` need not meet the requirements of
|
| 3077 |
+
*Cpp17CopyConstructible*. — *end note*]
|
| 3078 |
+
|
| 3079 |
+
*Preconditions:* `n >= 0` is `true`.
|
| 3080 |
|
| 3081 |
*Effects:* Applies `f` to the result of dereferencing every iterator in
|
| 3082 |
the range \[`first`, `first + n`) in order.
|
| 3083 |
|
| 3084 |
+
[*Note 8*: If the type of `first` meets the requirements of a mutable
|
| 3085 |
+
iterator, `f` may apply non-constant functions through the dereferenced
|
| 3086 |
+
iterator. — *end note*]
|
| 3087 |
|
| 3088 |
*Returns:* `first + n`.
|
| 3089 |
|
| 3090 |
*Remarks:* If `f` returns a result, the result is ignored.
|
| 3091 |
|
|
|
|
| 3093 |
template<class ExecutionPolicy, class ForwardIterator, class Size, class Function>
|
| 3094 |
ForwardIterator for_each_n(ExecutionPolicy&& exec, ForwardIterator first, Size n,
|
| 3095 |
Function f);
|
| 3096 |
```
|
| 3097 |
|
| 3098 |
+
*Mandates:* The type `Size` is convertible to an integral
|
| 3099 |
+
type ([[conv.integral]], [[class.conv]]).
|
| 3100 |
|
| 3101 |
+
*Preconditions:* `Function` meets the *Cpp17CopyConstructible*
|
| 3102 |
+
requirements.
|
| 3103 |
+
|
| 3104 |
+
*Preconditions:* `n >= 0` is `true`.
|
| 3105 |
|
| 3106 |
*Effects:* Applies `f` to the result of dereferencing every iterator in
|
| 3107 |
the range \[`first`, `first + n`).
|
| 3108 |
|
| 3109 |
+
[*Note 9*: If the type of `first` meets the requirements of a mutable
|
| 3110 |
+
iterator, `f` may apply non-constant functions through the dereferenced
|
| 3111 |
+
iterator. — *end note*]
|
| 3112 |
|
| 3113 |
*Returns:* `first + n`.
|
| 3114 |
|
| 3115 |
*Remarks:* If `f` returns a result, the result is ignored.
|
| 3116 |
Implementations do not have the freedom granted under
|
| 3117 |
[[algorithms.parallel.exec]] to make arbitrary copies of elements from
|
| 3118 |
the input sequence.
|
| 3119 |
|
| 3120 |
+
``` cpp
|
| 3121 |
+
template<input_iterator I, class Proj = identity,
|
| 3122 |
+
indirectly_unary_invocable<projected<I, Proj>> Fun>
|
| 3123 |
+
constexpr ranges::for_each_n_result<I, Fun>
|
| 3124 |
+
ranges::for_each_n(I first, iter_difference_t<I> n, Fun f, Proj proj = {});
|
| 3125 |
+
```
|
| 3126 |
+
|
| 3127 |
+
*Preconditions:* `n >= 0` is `true`.
|
| 3128 |
+
|
| 3129 |
+
*Effects:* Calls `invoke(f, invoke(proj, *i))` for every iterator `i` in
|
| 3130 |
+
the range \[`first`, `first + n`) in order.
|
| 3131 |
+
|
| 3132 |
+
[*Note 10*: If the result of `invoke(proj, *i)` is a mutable reference,
|
| 3133 |
+
`f` may apply non-constant functions. — *end note*]
|
| 3134 |
+
|
| 3135 |
+
*Returns:* `{first + n, std::move(f)}`.
|
| 3136 |
+
|
| 3137 |
+
*Remarks:* If `f` returns a result, the result is ignored.
|
| 3138 |
+
|
| 3139 |
+
[*Note 11*: The overload in namespace `ranges` requires `Fun` to model
|
| 3140 |
+
`copy_constructible`. — *end note*]
|
| 3141 |
+
|
| 3142 |
### Find <a id="alg.find">[[alg.find]]</a>
|
| 3143 |
|
| 3144 |
``` cpp
|
| 3145 |
template<class InputIterator, class T>
|
| 3146 |
+
constexpr InputIterator find(InputIterator first, InputIterator last,
|
| 3147 |
const T& value);
|
| 3148 |
template<class ExecutionPolicy, class ForwardIterator, class T>
|
| 3149 |
ForwardIterator find(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last,
|
| 3150 |
const T& value);
|
| 3151 |
|
| 3152 |
template<class InputIterator, class Predicate>
|
| 3153 |
+
constexpr InputIterator find_if(InputIterator first, InputIterator last,
|
| 3154 |
Predicate pred);
|
| 3155 |
template<class ExecutionPolicy, class ForwardIterator, class Predicate>
|
| 3156 |
ForwardIterator find_if(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last,
|
| 3157 |
Predicate pred);
|
| 3158 |
|
| 3159 |
template<class InputIterator, class Predicate>
|
| 3160 |
+
constexpr InputIterator find_if_not(InputIterator first, InputIterator last,
|
| 3161 |
Predicate pred);
|
| 3162 |
template<class ExecutionPolicy, class ForwardIterator, class Predicate>
|
| 3163 |
+
ForwardIterator find_if_not(ExecutionPolicy&& exec,
|
| 3164 |
+
ForwardIterator first, ForwardIterator last,
|
| 3165 |
Predicate pred);
|
| 3166 |
+
|
| 3167 |
+
template<input_iterator I, sentinel_for<I> S, class T, class Proj = identity>
|
| 3168 |
+
requires indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T*>
|
| 3169 |
+
constexpr I ranges::find(I first, S last, const T& value, Proj proj = {});
|
| 3170 |
+
template<input_range R, class T, class Proj = identity>
|
| 3171 |
+
requires indirect_binary_predicate<ranges::equal_to, projected<iterator_t<R>, Proj>, const T*>
|
| 3172 |
+
constexpr borrowed_iterator_t<R>
|
| 3173 |
+
ranges::find(R&& r, const T& value, Proj proj = {});
|
| 3174 |
+
template<input_iterator I, sentinel_for<I> S, class Proj = identity,
|
| 3175 |
+
indirect_unary_predicate<projected<I, Proj>> Pred>
|
| 3176 |
+
constexpr I ranges::find_if(I first, S last, Pred pred, Proj proj = {});
|
| 3177 |
+
template<input_range R, class Proj = identity,
|
| 3178 |
+
indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
|
| 3179 |
+
constexpr borrowed_iterator_t<R>
|
| 3180 |
+
ranges::find_if(R&& r, Pred pred, Proj proj = {});
|
| 3181 |
+
template<input_iterator I, sentinel_for<I> S, class Proj = identity,
|
| 3182 |
+
indirect_unary_predicate<projected<I, Proj>> Pred>
|
| 3183 |
+
constexpr I ranges::find_if_not(I first, S last, Pred pred, Proj proj = {});
|
| 3184 |
+
template<input_range R, class Proj = identity,
|
| 3185 |
+
indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
|
| 3186 |
+
constexpr borrowed_iterator_t<R>
|
| 3187 |
+
ranges::find_if_not(R&& r, Pred pred, Proj proj = {});
|
| 3188 |
```
|
| 3189 |
|
| 3190 |
+
Let E be:
|
| 3191 |
+
|
| 3192 |
+
- `*i == value` for `find`;
|
| 3193 |
+
- `pred(*i) != false` for `find_if`;
|
| 3194 |
+
- `pred(*i) == false` for `find_if_not`;
|
| 3195 |
+
- `bool(invoke(proj, *i) == value)` for `ranges::find`;
|
| 3196 |
+
- `bool(invoke(pred, invoke(proj, *i)))` for `ranges::find_if`;
|
| 3197 |
+
- `bool(!invoke(pred, invoke(proj, *i)))` for `ranges::find_if_not`.
|
| 3198 |
+
|
| 3199 |
*Returns:* The first iterator `i` in the range \[`first`, `last`) for
|
| 3200 |
+
which E is `true`. Returns `last` if no such iterator is found.
|
|
|
|
|
|
|
| 3201 |
|
| 3202 |
*Complexity:* At most `last - first` applications of the corresponding
|
| 3203 |
+
predicate and any projection.
|
| 3204 |
|
| 3205 |
### Find end <a id="alg.find.end">[[alg.find.end]]</a>
|
| 3206 |
|
| 3207 |
``` cpp
|
| 3208 |
template<class ForwardIterator1, class ForwardIterator2>
|
| 3209 |
+
constexpr ForwardIterator1
|
| 3210 |
find_end(ForwardIterator1 first1, ForwardIterator1 last1,
|
| 3211 |
ForwardIterator2 first2, ForwardIterator2 last2);
|
| 3212 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 3213 |
ForwardIterator1
|
| 3214 |
find_end(ExecutionPolicy&& exec,
|
| 3215 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 3216 |
ForwardIterator2 first2, ForwardIterator2 last2);
|
| 3217 |
|
| 3218 |
template<class ForwardIterator1, class ForwardIterator2,
|
| 3219 |
class BinaryPredicate>
|
| 3220 |
+
constexpr ForwardIterator1
|
| 3221 |
find_end(ForwardIterator1 first1, ForwardIterator1 last1,
|
| 3222 |
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 3223 |
BinaryPredicate pred);
|
| 3224 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 3225 |
class BinaryPredicate>
|
| 3226 |
ForwardIterator1
|
| 3227 |
find_end(ExecutionPolicy&& exec,
|
| 3228 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 3229 |
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 3230 |
BinaryPredicate pred);
|
| 3231 |
+
|
| 3232 |
+
template<forward_iterator I1, sentinel_for<I1> S1, forward_iterator I2, sentinel_for<I2> S2,
|
| 3233 |
+
class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
|
| 3234 |
+
requires indirectly_comparable<I1, I2, Pred, Proj1, Proj2>
|
| 3235 |
+
constexpr subrange<I1>
|
| 3236 |
+
ranges::find_end(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {},
|
| 3237 |
+
Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 3238 |
+
template<forward_range R1, forward_range R2,
|
| 3239 |
+
class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
|
| 3240 |
+
requires indirectly_comparable<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
|
| 3241 |
+
constexpr borrowed_subrange_t<R1>
|
| 3242 |
+
ranges::find_end(R1&& r1, R2&& r2, Pred pred = {},
|
| 3243 |
+
Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 3244 |
```
|
| 3245 |
|
| 3246 |
+
Let:
|
| 3247 |
|
| 3248 |
+
- `pred` be `equal_to{}` for the overloads with no parameter `pred`;
|
| 3249 |
+
- E be:
|
| 3250 |
+
- `pred(*(i + n), *(first2 + n))` for the overloads in namespace
|
| 3251 |
+
`std`;
|
| 3252 |
+
- `invoke(pred, invoke(proj1, *(i + n)), invoke(proj2, *(first2 + n)))`
|
| 3253 |
+
for the overloads in namespace `ranges`;
|
| 3254 |
+
- `i` be `last1` if \[`first2`, `last2`) is empty, or if
|
| 3255 |
+
`(last2 - first2) > (last1 - first1)` is `true`, or if there is no
|
| 3256 |
+
iterator in the range \[`first1`, `last1 - (last2 - first2)`) such
|
| 3257 |
+
that for every non-negative integer `n < (last2 - first2)`, E is
|
| 3258 |
+
`true`. Otherwise `i` is the last such iterator in \[`first1`,
|
| 3259 |
+
`last1 - (last2 - first2)`).
|
| 3260 |
+
|
| 3261 |
+
*Returns:*
|
| 3262 |
+
|
| 3263 |
+
- `i` for the overloads in namespace `std`.
|
| 3264 |
+
- `{i, i + (i == last1 ? 0 : last2 - first2)}` for the overloads in
|
| 3265 |
+
namespace `ranges`.
|
| 3266 |
|
| 3267 |
*Complexity:* At most
|
| 3268 |
`(last2 - first2) * (last1 - first1 - (last2 - first2) + 1)`
|
| 3269 |
+
applications of the corresponding predicate and any projections.
|
| 3270 |
|
| 3271 |
### Find first <a id="alg.find.first.of">[[alg.find.first.of]]</a>
|
| 3272 |
|
| 3273 |
``` cpp
|
| 3274 |
template<class InputIterator, class ForwardIterator>
|
| 3275 |
+
constexpr InputIterator
|
| 3276 |
find_first_of(InputIterator first1, InputIterator last1,
|
| 3277 |
ForwardIterator first2, ForwardIterator last2);
|
| 3278 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 3279 |
ForwardIterator1
|
| 3280 |
find_first_of(ExecutionPolicy&& exec,
|
| 3281 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 3282 |
ForwardIterator2 first2, ForwardIterator2 last2);
|
| 3283 |
|
| 3284 |
template<class InputIterator, class ForwardIterator,
|
| 3285 |
class BinaryPredicate>
|
| 3286 |
+
constexpr InputIterator
|
| 3287 |
find_first_of(InputIterator first1, InputIterator last1,
|
| 3288 |
ForwardIterator first2, ForwardIterator last2,
|
| 3289 |
BinaryPredicate pred);
|
| 3290 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 3291 |
class BinaryPredicate>
|
| 3292 |
ForwardIterator1
|
| 3293 |
find_first_of(ExecutionPolicy&& exec,
|
| 3294 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 3295 |
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 3296 |
BinaryPredicate pred);
|
| 3297 |
+
|
| 3298 |
+
template<input_iterator I1, sentinel_for<I1> S1, forward_iterator I2, sentinel_for<I2> S2,
|
| 3299 |
+
class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
|
| 3300 |
+
requires indirectly_comparable<I1, I2, Pred, Proj1, Proj2>
|
| 3301 |
+
constexpr I1 ranges::find_first_of(I1 first1, S1 last1, I2 first2, S2 last2,
|
| 3302 |
+
Pred pred = {},
|
| 3303 |
+
Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 3304 |
+
template<input_range R1, forward_range R2,
|
| 3305 |
+
class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
|
| 3306 |
+
requires indirectly_comparable<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
|
| 3307 |
+
constexpr borrowed_iterator_t<R1>
|
| 3308 |
+
ranges::find_first_of(R1&& r1, R2&& r2,
|
| 3309 |
+
Pred pred = {},
|
| 3310 |
+
Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 3311 |
```
|
| 3312 |
|
| 3313 |
+
Let E be:
|
| 3314 |
+
|
| 3315 |
+
- `*i == *j` for the overloads with no parameter `pred`;
|
| 3316 |
+
- `pred(*i, *j) != false` for the overloads with a parameter `pred` and
|
| 3317 |
+
no parameter `proj1`;
|
| 3318 |
+
- `bool(invoke(pred, invoke(proj1, *i), invoke(proj2, *j)))` for the
|
| 3319 |
+
overloads with parameters `pred` and `proj1`.
|
| 3320 |
+
|
| 3321 |
*Effects:* Finds an element that matches one of a set of values.
|
| 3322 |
|
| 3323 |
*Returns:* The first iterator `i` in the range \[`first1`, `last1`) such
|
| 3324 |
+
that for some iterator `j` in the range \[`first2`, `last2`) E holds.
|
| 3325 |
+
Returns `last1` if \[`first2`, `last2`) is empty or if no such iterator
|
| 3326 |
+
is found.
|
|
|
|
| 3327 |
|
| 3328 |
*Complexity:* At most `(last1-first1) * (last2-first2)` applications of
|
| 3329 |
+
the corresponding predicate and any projections.
|
| 3330 |
|
| 3331 |
### Adjacent find <a id="alg.adjacent.find">[[alg.adjacent.find]]</a>
|
| 3332 |
|
| 3333 |
``` cpp
|
| 3334 |
template<class ForwardIterator>
|
| 3335 |
+
constexpr ForwardIterator
|
| 3336 |
+
adjacent_find(ForwardIterator first, ForwardIterator last);
|
| 3337 |
template<class ExecutionPolicy, class ForwardIterator>
|
| 3338 |
+
ForwardIterator
|
| 3339 |
+
adjacent_find(ExecutionPolicy&& exec,
|
| 3340 |
ForwardIterator first, ForwardIterator last);
|
| 3341 |
|
| 3342 |
template<class ForwardIterator, class BinaryPredicate>
|
| 3343 |
+
constexpr ForwardIterator
|
| 3344 |
+
adjacent_find(ForwardIterator first, ForwardIterator last,
|
| 3345 |
BinaryPredicate pred);
|
| 3346 |
template<class ExecutionPolicy, class ForwardIterator, class BinaryPredicate>
|
| 3347 |
+
ForwardIterator
|
| 3348 |
+
adjacent_find(ExecutionPolicy&& exec,
|
| 3349 |
ForwardIterator first, ForwardIterator last,
|
| 3350 |
BinaryPredicate pred);
|
| 3351 |
+
|
| 3352 |
+
template<forward_iterator I, sentinel_for<I> S, class Proj = identity,
|
| 3353 |
+
indirect_binary_predicate<projected<I, Proj>,
|
| 3354 |
+
projected<I, Proj>> Pred = ranges::equal_to>
|
| 3355 |
+
constexpr I ranges::adjacent_find(I first, S last, Pred pred = {}, Proj proj = {});
|
| 3356 |
+
template<forward_range R, class Proj = identity,
|
| 3357 |
+
indirect_binary_predicate<projected<iterator_t<R>, Proj>,
|
| 3358 |
+
projected<iterator_t<R>, Proj>> Pred = ranges::equal_to>
|
| 3359 |
+
constexpr borrowed_iterator_t<R> ranges::adjacent_find(R&& r, Pred pred = {}, Proj proj = {});
|
| 3360 |
```
|
| 3361 |
|
| 3362 |
+
Let E be:
|
| 3363 |
+
|
| 3364 |
+
- `*i == *(i + 1)` for the overloads with no parameter `pred`;
|
| 3365 |
+
- `pred(*i, *(i + 1)) != false` for the overloads with a parameter
|
| 3366 |
+
`pred` and no parameter `proj`;
|
| 3367 |
+
- `bool(invoke(pred, invoke(proj, *i), invoke(proj, *(i + 1))))` for the
|
| 3368 |
+
overloads with both parameters `pred` and `proj`.
|
| 3369 |
+
|
| 3370 |
*Returns:* The first iterator `i` such that both `i` and `i + 1` are in
|
| 3371 |
+
the range \[`first`, `last`) for which E holds. Returns `last` if no
|
| 3372 |
+
such iterator is found.
|
|
|
|
| 3373 |
|
| 3374 |
*Complexity:* For the overloads with no `ExecutionPolicy`, exactly
|
| 3375 |
+
$$\min(\texttt{(i - first) + 1}, \ \texttt{(last - first) - 1})$$
|
| 3376 |
+
applications of the corresponding predicate, where `i` is
|
| 3377 |
+
`adjacent_find`’s return value. For the overloads with an
|
| 3378 |
+
`ExecutionPolicy`, 𝑂(`last - first`) applications of the corresponding
|
| 3379 |
+
predicate, and no more than twice as many applications of any
|
| 3380 |
+
projection.
|
| 3381 |
|
| 3382 |
### Count <a id="alg.count">[[alg.count]]</a>
|
| 3383 |
|
| 3384 |
``` cpp
|
| 3385 |
template<class InputIterator, class T>
|
| 3386 |
+
constexpr typename iterator_traits<InputIterator>::difference_type
|
| 3387 |
count(InputIterator first, InputIterator last, const T& value);
|
| 3388 |
template<class ExecutionPolicy, class ForwardIterator, class T>
|
| 3389 |
typename iterator_traits<ForwardIterator>::difference_type
|
| 3390 |
+
count(ExecutionPolicy&& exec,
|
| 3391 |
+
ForwardIterator first, ForwardIterator last, const T& value);
|
| 3392 |
|
| 3393 |
template<class InputIterator, class Predicate>
|
| 3394 |
+
constexpr typename iterator_traits<InputIterator>::difference_type
|
| 3395 |
count_if(InputIterator first, InputIterator last, Predicate pred);
|
| 3396 |
template<class ExecutionPolicy, class ForwardIterator, class Predicate>
|
| 3397 |
typename iterator_traits<ForwardIterator>::difference_type
|
| 3398 |
+
count_if(ExecutionPolicy&& exec,
|
| 3399 |
+
ForwardIterator first, ForwardIterator last, Predicate pred);
|
| 3400 |
+
|
| 3401 |
+
template<input_iterator I, sentinel_for<I> S, class T, class Proj = identity>
|
| 3402 |
+
requires indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T*>
|
| 3403 |
+
constexpr iter_difference_t<I>
|
| 3404 |
+
ranges::count(I first, S last, const T& value, Proj proj = {});
|
| 3405 |
+
template<input_range R, class T, class Proj = identity>
|
| 3406 |
+
requires indirect_binary_predicate<ranges::equal_to, projected<iterator_t<R>, Proj>, const T*>
|
| 3407 |
+
constexpr range_difference_t<R>
|
| 3408 |
+
ranges::count(R&& r, const T& value, Proj proj = {});
|
| 3409 |
+
template<input_iterator I, sentinel_for<I> S, class Proj = identity,
|
| 3410 |
+
indirect_unary_predicate<projected<I, Proj>> Pred>
|
| 3411 |
+
constexpr iter_difference_t<I>
|
| 3412 |
+
ranges::count_if(I first, S last, Pred pred, Proj proj = {});
|
| 3413 |
+
template<input_range R, class Proj = identity,
|
| 3414 |
+
indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
|
| 3415 |
+
constexpr range_difference_t<R>
|
| 3416 |
+
ranges::count_if(R&& r, Pred pred, Proj proj = {});
|
| 3417 |
```
|
| 3418 |
|
| 3419 |
+
Let E be:
|
| 3420 |
+
|
| 3421 |
+
- `*i == value` for the overloads with no parameter `pred` or `proj`;
|
| 3422 |
+
- `pred(*i) != false` for the overloads with a parameter `pred` but no
|
| 3423 |
+
parameter `proj`;
|
| 3424 |
+
- `invoke(proj, *i) == value` for the overloads with a parameter `proj`
|
| 3425 |
+
but no parameter `pred`;
|
| 3426 |
+
- `bool(invoke(pred, invoke(proj, *i)))` for the overloads with both
|
| 3427 |
+
parameters `proj` and `pred`.
|
| 3428 |
+
|
| 3429 |
*Effects:* Returns the number of iterators `i` in the range \[`first`,
|
| 3430 |
+
`last`) for which E holds.
|
|
|
|
| 3431 |
|
| 3432 |
*Complexity:* Exactly `last - first` applications of the corresponding
|
| 3433 |
+
predicate and any projection.
|
| 3434 |
|
| 3435 |
### Mismatch <a id="mismatch">[[mismatch]]</a>
|
| 3436 |
|
| 3437 |
``` cpp
|
| 3438 |
template<class InputIterator1, class InputIterator2>
|
| 3439 |
+
constexpr pair<InputIterator1, InputIterator2>
|
| 3440 |
mismatch(InputIterator1 first1, InputIterator1 last1,
|
| 3441 |
InputIterator2 first2);
|
| 3442 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 3443 |
pair<ForwardIterator1, ForwardIterator2>
|
| 3444 |
mismatch(ExecutionPolicy&& exec,
|
| 3445 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 3446 |
ForwardIterator2 first2);
|
| 3447 |
|
| 3448 |
template<class InputIterator1, class InputIterator2,
|
| 3449 |
class BinaryPredicate>
|
| 3450 |
+
constexpr pair<InputIterator1, InputIterator2>
|
| 3451 |
mismatch(InputIterator1 first1, InputIterator1 last1,
|
| 3452 |
InputIterator2 first2, BinaryPredicate pred);
|
| 3453 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 3454 |
class BinaryPredicate>
|
| 3455 |
pair<ForwardIterator1, ForwardIterator2>
|
| 3456 |
mismatch(ExecutionPolicy&& exec,
|
| 3457 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 3458 |
ForwardIterator2 first2, BinaryPredicate pred);
|
| 3459 |
|
| 3460 |
template<class InputIterator1, class InputIterator2>
|
| 3461 |
+
constexpr pair<InputIterator1, InputIterator2>
|
| 3462 |
mismatch(InputIterator1 first1, InputIterator1 last1,
|
| 3463 |
InputIterator2 first2, InputIterator2 last2);
|
| 3464 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 3465 |
pair<ForwardIterator1, ForwardIterator2>
|
| 3466 |
mismatch(ExecutionPolicy&& exec,
|
| 3467 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 3468 |
ForwardIterator2 first2, ForwardIterator2 last2);
|
| 3469 |
|
| 3470 |
template<class InputIterator1, class InputIterator2,
|
| 3471 |
class BinaryPredicate>
|
| 3472 |
+
constexpr pair<InputIterator1, InputIterator2>
|
| 3473 |
mismatch(InputIterator1 first1, InputIterator1 last1,
|
| 3474 |
InputIterator2 first2, InputIterator2 last2,
|
| 3475 |
BinaryPredicate pred);
|
| 3476 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 3477 |
class BinaryPredicate>
|
| 3478 |
pair<ForwardIterator1, ForwardIterator2>
|
| 3479 |
mismatch(ExecutionPolicy&& exec,
|
| 3480 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 3481 |
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 3482 |
BinaryPredicate pred);
|
| 3483 |
+
|
| 3484 |
+
template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2,
|
| 3485 |
+
class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
|
| 3486 |
+
requires indirectly_comparable<I1, I2, Pred, Proj1, Proj2>
|
| 3487 |
+
constexpr ranges::mismatch_result<I1, I2>
|
| 3488 |
+
ranges::mismatch(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {},
|
| 3489 |
+
Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 3490 |
+
template<input_range R1, input_range R2,
|
| 3491 |
+
class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
|
| 3492 |
+
requires indirectly_comparable<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
|
| 3493 |
+
constexpr ranges::mismatch_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>>
|
| 3494 |
+
ranges::mismatch(R1&& r1, R2&& r2, Pred pred = {},
|
| 3495 |
+
Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 3496 |
```
|
| 3497 |
|
| 3498 |
+
Let `last2` be `first2 + (last1 - first1)` for the overloads with no
|
| 3499 |
+
parameter `last2` or `r2`.
|
| 3500 |
|
| 3501 |
+
Let E be:
|
|
|
|
| 3502 |
|
| 3503 |
+
- `!(*(first1 + n) == *(first2 + n))` for the overloads with no
|
| 3504 |
+
parameter `pred`;
|
| 3505 |
+
- `pred(*(first1 + n), *(first2 + n)) == false` for the overloads with a
|
| 3506 |
+
parameter `pred` and no parameter `proj1`;
|
| 3507 |
+
- `!invoke(pred, invoke(proj1, *(first1 + n)), invoke(proj2, *(first2 + n)))`
|
| 3508 |
+
for the overloads with both parameters `pred` and `proj1`.
|
| 3509 |
|
| 3510 |
+
Let N be min(`last1 - first1`, `last2 - first2`).
|
| 3511 |
|
| 3512 |
+
*Returns:* `{ first1 + n, first2 + n }`, where `n` is the smallest
|
| 3513 |
+
integer in \[`0`, N) such that E holds, or N if no such integer exists.
|
| 3514 |
+
|
| 3515 |
+
*Complexity:* At most N applications of the corresponding predicate and
|
| 3516 |
+
any projections.
|
| 3517 |
|
| 3518 |
### Equal <a id="alg.equal">[[alg.equal]]</a>
|
| 3519 |
|
| 3520 |
``` cpp
|
| 3521 |
template<class InputIterator1, class InputIterator2>
|
| 3522 |
+
constexpr bool equal(InputIterator1 first1, InputIterator1 last1,
|
| 3523 |
InputIterator2 first2);
|
| 3524 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 3525 |
bool equal(ExecutionPolicy&& exec,
|
| 3526 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 3527 |
ForwardIterator2 first2);
|
| 3528 |
|
| 3529 |
template<class InputIterator1, class InputIterator2,
|
| 3530 |
class BinaryPredicate>
|
| 3531 |
+
constexpr bool equal(InputIterator1 first1, InputIterator1 last1,
|
| 3532 |
InputIterator2 first2, BinaryPredicate pred);
|
| 3533 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 3534 |
class BinaryPredicate>
|
| 3535 |
bool equal(ExecutionPolicy&& exec,
|
| 3536 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 3537 |
ForwardIterator2 first2, BinaryPredicate pred);
|
| 3538 |
|
| 3539 |
template<class InputIterator1, class InputIterator2>
|
| 3540 |
+
constexpr bool equal(InputIterator1 first1, InputIterator1 last1,
|
| 3541 |
InputIterator2 first2, InputIterator2 last2);
|
| 3542 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 3543 |
bool equal(ExecutionPolicy&& exec,
|
| 3544 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 3545 |
ForwardIterator2 first2, ForwardIterator2 last2);
|
| 3546 |
|
| 3547 |
template<class InputIterator1, class InputIterator2,
|
| 3548 |
class BinaryPredicate>
|
| 3549 |
+
constexpr bool equal(InputIterator1 first1, InputIterator1 last1,
|
| 3550 |
InputIterator2 first2, InputIterator2 last2,
|
| 3551 |
BinaryPredicate pred);
|
| 3552 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 3553 |
class BinaryPredicate>
|
| 3554 |
bool equal(ExecutionPolicy&& exec,
|
| 3555 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 3556 |
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 3557 |
BinaryPredicate pred);
|
| 3558 |
+
|
| 3559 |
+
template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2,
|
| 3560 |
+
class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
|
| 3561 |
+
requires indirectly_comparable<I1, I2, Pred, Proj1, Proj2>
|
| 3562 |
+
constexpr bool ranges::equal(I1 first1, S1 last1, I2 first2, S2 last2,
|
| 3563 |
+
Pred pred = {},
|
| 3564 |
+
Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 3565 |
+
template<input_range R1, input_range R2, class Pred = ranges::equal_to,
|
| 3566 |
+
class Proj1 = identity, class Proj2 = identity>
|
| 3567 |
+
requires indirectly_comparable<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
|
| 3568 |
+
constexpr bool ranges::equal(R1&& r1, R2&& r2, Pred pred = {},
|
| 3569 |
+
Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 3570 |
```
|
| 3571 |
|
| 3572 |
+
Let:
|
| 3573 |
+
|
| 3574 |
+
- `last2` be `first2 + (last1 - first1)` for the overloads with no
|
| 3575 |
+
parameter `last2` or `r2`;
|
| 3576 |
+
- `pred` be `equal_to{}` for the overloads with no parameter `pred`;
|
| 3577 |
+
- E be:
|
| 3578 |
+
- `pred(*i, *(first2 + (i - first1)))` for the overloads with no
|
| 3579 |
+
parameter `proj1`;
|
| 3580 |
+
- `invoke(pred, invoke(proj1, *i), invoke(proj2, *(first2 + (i - first1))))`
|
| 3581 |
+
for the overloads with parameter `proj1`.
|
| 3582 |
|
| 3583 |
*Returns:* If `last1 - first1 != last2 - first2`, return `false`.
|
| 3584 |
+
Otherwise return `true` if E holds for every iterator `i` in the range
|
| 3585 |
+
\[`first1`, `last1`) Otherwise, returns `false`.
|
|
|
|
|
|
|
| 3586 |
|
| 3587 |
+
*Complexity:* If the types of `first1`, `last1`, `first2`, and `last2`:
|
| 3588 |
|
| 3589 |
+
- meet the *Cpp17RandomAccessIterator*
|
| 3590 |
+
requirements [[random.access.iterators]] for the overloads in
|
| 3591 |
+
namespace `std`;
|
| 3592 |
+
- pairwise model `sized_sentinel_for` [[iterator.concept.sizedsentinel]]
|
| 3593 |
+
for the overloads in namespace `ranges`,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3594 |
|
| 3595 |
+
and `last1 - first1 != last2 - first2`, then no applications of the
|
| 3596 |
+
corresponding predicate and each projection; otherwise,
|
| 3597 |
+
|
| 3598 |
+
- For the overloads with no `ExecutionPolicy`, at most
|
| 3599 |
+
min(`last1 - first1`, `last2 - first2`) applications of the
|
| 3600 |
+
corresponding predicate and any projections.
|
| 3601 |
+
- For the overloads with an `ExecutionPolicy`, 𝑂(min(`last1 - first1`,
|
| 3602 |
+
`last2 - first2`)) applications of the corresponding predicate.
|
| 3603 |
+
|
| 3604 |
+
### Is permutation <a id="alg.is.permutation">[[alg.is.permutation]]</a>
|
| 3605 |
|
| 3606 |
``` cpp
|
| 3607 |
template<class ForwardIterator1, class ForwardIterator2>
|
| 3608 |
+
constexpr bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
|
| 3609 |
ForwardIterator2 first2);
|
| 3610 |
template<class ForwardIterator1, class ForwardIterator2,
|
| 3611 |
class BinaryPredicate>
|
| 3612 |
+
constexpr bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
|
| 3613 |
ForwardIterator2 first2, BinaryPredicate pred);
|
| 3614 |
template<class ForwardIterator1, class ForwardIterator2>
|
| 3615 |
+
constexpr bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
|
| 3616 |
ForwardIterator2 first2, ForwardIterator2 last2);
|
| 3617 |
template<class ForwardIterator1, class ForwardIterator2,
|
| 3618 |
class BinaryPredicate>
|
| 3619 |
+
constexpr bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
|
| 3620 |
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 3621 |
BinaryPredicate pred);
|
| 3622 |
```
|
| 3623 |
|
| 3624 |
+
*Mandates:* `ForwardIterator1` and `ForwardIterator2` have the same
|
| 3625 |
+
value type.
|
| 3626 |
+
|
| 3627 |
+
*Preconditions:* The comparison function is an equivalence relation.
|
| 3628 |
|
| 3629 |
*Remarks:* If `last2` was not given in the argument list, it denotes
|
| 3630 |
`first2 + (last1 - first1)` below.
|
| 3631 |
|
| 3632 |
*Returns:* If `last1 - first1 != last2 - first2`, return `false`.
|
|
|
|
| 3640 |
`ForwardIterator1` and `ForwardIterator2` meet the requirements of
|
| 3641 |
random access iterators and `last1 - first1 != last2 - first2`.
|
| 3642 |
Otherwise, exactly `last1 - first1` applications of the corresponding
|
| 3643 |
predicate if `equal(first1, last1, first2, last2)` would return `true`
|
| 3644 |
if `pred` was not given in the argument list or
|
| 3645 |
+
`equal(first1, last1, first2, last2, pred)` would return `true` if
|
| 3646 |
+
`pred` was given in the argument list; otherwise, at worst 𝑂(N^2), where
|
| 3647 |
+
N has the value `last1 - first1`.
|
| 3648 |
+
|
| 3649 |
+
``` cpp
|
| 3650 |
+
template<forward_iterator I1, sentinel_for<I1> S1, forward_iterator I2,
|
| 3651 |
+
sentinel_for<I2> S2, class Proj1 = identity, class Proj2 = identity,
|
| 3652 |
+
indirect_equivalence_relation<projected<I1, Proj1>,
|
| 3653 |
+
projected<I2, Proj2>> Pred = ranges::equal_to>
|
| 3654 |
+
constexpr bool ranges::is_permutation(I1 first1, S1 last1, I2 first2, S2 last2,
|
| 3655 |
+
Pred pred = {},
|
| 3656 |
+
Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 3657 |
+
template<forward_range R1, forward_range R2,
|
| 3658 |
+
class Proj1 = identity, class Proj2 = identity,
|
| 3659 |
+
indirect_equivalence_relation<projected<iterator_t<R1>, Proj1>,
|
| 3660 |
+
projected<iterator_t<R2>, Proj2>> Pred = ranges::equal_to>
|
| 3661 |
+
constexpr bool ranges::is_permutation(R1&& r1, R2&& r2, Pred pred = {},
|
| 3662 |
+
Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 3663 |
+
```
|
| 3664 |
+
|
| 3665 |
+
*Returns:* If `last1 - first1 != last2 - first2`, return `false`.
|
| 3666 |
+
Otherwise return `true` if there exists a permutation of the elements in
|
| 3667 |
+
the range \[`first2`, `last2`), bounded by \[`pfirst`, `plast`), such
|
| 3668 |
+
that `ranges::equal(first1, last1, pfirst, plast, pred, proj1, proj2)`
|
| 3669 |
+
returns `true`; otherwise, returns `false`.
|
| 3670 |
+
|
| 3671 |
+
*Complexity:* No applications of the corresponding predicate and
|
| 3672 |
+
projections if:
|
| 3673 |
+
|
| 3674 |
+
- `S1` and `I1` model `sized_sentinel_for<S1, I1>`,
|
| 3675 |
+
- `S2` and `I2` model `sized_sentinel_for<S2, I2>`, and
|
| 3676 |
+
- `last1 - first1 != last2 - first2`.
|
| 3677 |
+
|
| 3678 |
+
Otherwise, exactly `last1 - first1` applications of the corresponding
|
| 3679 |
+
predicate and projections if
|
| 3680 |
+
`ranges::equal(first1, last1, first2, last2, pred, proj1, proj2)` would
|
| 3681 |
+
return `true`; otherwise, at worst 𝑂(N^2), where N has the value
|
| 3682 |
+
`last1 - first1`.
|
| 3683 |
|
| 3684 |
### Search <a id="alg.search">[[alg.search]]</a>
|
| 3685 |
|
| 3686 |
``` cpp
|
| 3687 |
template<class ForwardIterator1, class ForwardIterator2>
|
| 3688 |
+
constexpr ForwardIterator1
|
| 3689 |
search(ForwardIterator1 first1, ForwardIterator1 last1,
|
| 3690 |
ForwardIterator2 first2, ForwardIterator2 last2);
|
| 3691 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 3692 |
ForwardIterator1
|
| 3693 |
search(ExecutionPolicy&& exec,
|
| 3694 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 3695 |
ForwardIterator2 first2, ForwardIterator2 last2);
|
| 3696 |
|
| 3697 |
template<class ForwardIterator1, class ForwardIterator2,
|
| 3698 |
class BinaryPredicate>
|
| 3699 |
+
constexpr ForwardIterator1
|
| 3700 |
search(ForwardIterator1 first1, ForwardIterator1 last1,
|
| 3701 |
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 3702 |
BinaryPredicate pred);
|
| 3703 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 3704 |
class BinaryPredicate>
|
|
|
|
| 3707 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 3708 |
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 3709 |
BinaryPredicate pred);
|
| 3710 |
```
|
| 3711 |
|
|
|
|
|
|
|
| 3712 |
*Returns:* The first iterator `i` in the range \[`first1`,
|
| 3713 |
`last1 - (last2-first2)`) such that for every non-negative integer `n`
|
| 3714 |
less than `last2 - first2` the following corresponding conditions hold:
|
| 3715 |
`*(i + n) == *(first2 + n), pred(*(i + n), *(first2 + n)) != false`.
|
| 3716 |
Returns `first1` if \[`first2`, `last2`) is empty, otherwise returns
|
| 3717 |
`last1` if no such iterator is found.
|
| 3718 |
|
| 3719 |
*Complexity:* At most `(last1 - first1) * (last2 - first2)` applications
|
| 3720 |
of the corresponding predicate.
|
| 3721 |
|
| 3722 |
+
``` cpp
|
| 3723 |
+
template<forward_iterator I1, sentinel_for<I1> S1, forward_iterator I2,
|
| 3724 |
+
sentinel_for<I2> S2, class Pred = ranges::equal_to,
|
| 3725 |
+
class Proj1 = identity, class Proj2 = identity>
|
| 3726 |
+
requires indirectly_comparable<I1, I2, Pred, Proj1, Proj2>
|
| 3727 |
+
constexpr subrange<I1>
|
| 3728 |
+
ranges::search(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {},
|
| 3729 |
+
Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 3730 |
+
template<forward_range R1, forward_range R2, class Pred = ranges::equal_to,
|
| 3731 |
+
class Proj1 = identity, class Proj2 = identity>
|
| 3732 |
+
requires indirectly_comparable<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
|
| 3733 |
+
constexpr borrowed_subrange_t<R1>
|
| 3734 |
+
ranges::search(R1&& r1, R2&& r2, Pred pred = {},
|
| 3735 |
+
Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 3736 |
+
```
|
| 3737 |
+
|
| 3738 |
+
*Returns:*
|
| 3739 |
+
|
| 3740 |
+
- `{i, i + (last2 - first2)}`, where `i` is the first iterator in the
|
| 3741 |
+
range \[`first1`, `last1 - (last2 - first2)`) such that for every
|
| 3742 |
+
non-negative integer `n` less than `last2 - first2` the condition
|
| 3743 |
+
``` cpp
|
| 3744 |
+
bool(invoke(pred, invoke(proj1, *(i + n)), invoke(proj2, *(first2 + n))))
|
| 3745 |
+
```
|
| 3746 |
+
|
| 3747 |
+
is `true`.
|
| 3748 |
+
- Returns `{last1, last1}` if no such iterator exists.
|
| 3749 |
+
|
| 3750 |
+
*Complexity:* At most `(last1 - first1) * (last2 - first2)` applications
|
| 3751 |
+
of the corresponding predicate and projections.
|
| 3752 |
+
|
| 3753 |
``` cpp
|
| 3754 |
template<class ForwardIterator, class Size, class T>
|
| 3755 |
+
constexpr ForwardIterator
|
| 3756 |
+
search_n(ForwardIterator first, ForwardIterator last,
|
| 3757 |
+
Size count, const T& value);
|
| 3758 |
+
template<class ExecutionPolicy, class ForwardIterator, class Size, class T>
|
| 3759 |
ForwardIterator
|
| 3760 |
+
search_n(ExecutionPolicy&& exec,
|
| 3761 |
+
ForwardIterator first, ForwardIterator last,
|
| 3762 |
+
Size count, const T& value);
|
| 3763 |
|
| 3764 |
template<class ForwardIterator, class Size, class T,
|
| 3765 |
class BinaryPredicate>
|
| 3766 |
+
constexpr ForwardIterator
|
| 3767 |
+
search_n(ForwardIterator first, ForwardIterator last,
|
| 3768 |
+
Size count, const T& value,
|
| 3769 |
+
BinaryPredicate pred);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3770 |
template<class ExecutionPolicy, class ForwardIterator, class Size, class T,
|
| 3771 |
class BinaryPredicate>
|
| 3772 |
ForwardIterator
|
| 3773 |
search_n(ExecutionPolicy&& exec,
|
| 3774 |
ForwardIterator first, ForwardIterator last,
|
| 3775 |
Size count, const T& value,
|
| 3776 |
BinaryPredicate pred);
|
| 3777 |
```
|
| 3778 |
|
| 3779 |
+
*Mandates:* The type `Size` is convertible to an integral
|
| 3780 |
type ([[conv.integral]], [[class.conv]]).
|
| 3781 |
|
|
|
|
|
|
|
| 3782 |
*Returns:* The first iterator `i` in the range \[`first`, `last-count`)
|
| 3783 |
such that for every non-negative integer `n` less than `count` the
|
| 3784 |
following corresponding conditions hold:
|
| 3785 |
`*(i + n) == value, pred(*(i + n),value) != false`. Returns `last` if no
|
| 3786 |
such iterator is found.
|
| 3787 |
|
| 3788 |
*Complexity:* At most `last - first` applications of the corresponding
|
| 3789 |
predicate.
|
| 3790 |
|
| 3791 |
+
``` cpp
|
| 3792 |
+
template<forward_iterator I, sentinel_for<I> S, class T,
|
| 3793 |
+
class Pred = ranges::equal_to, class Proj = identity>
|
| 3794 |
+
requires indirectly_comparable<I, const T*, Pred, Proj>
|
| 3795 |
+
constexpr subrange<I>
|
| 3796 |
+
ranges::search_n(I first, S last, iter_difference_t<I> count,
|
| 3797 |
+
const T& value, Pred pred = {}, Proj proj = {});
|
| 3798 |
+
template<forward_range R, class T, class Pred = ranges::equal_to,
|
| 3799 |
+
class Proj = identity>
|
| 3800 |
+
requires indirectly_comparable<iterator_t<R>, const T*, Pred, Proj>
|
| 3801 |
+
constexpr borrowed_subrange_t<R>
|
| 3802 |
+
ranges::search_n(R&& r, range_difference_t<R> count,
|
| 3803 |
+
const T& value, Pred pred = {}, Proj proj = {});
|
| 3804 |
+
```
|
| 3805 |
+
|
| 3806 |
+
*Returns:* `{i, i + count}` where `i` is the first iterator in the range
|
| 3807 |
+
\[`first`, `last - count`) such that for every non-negative integer `n`
|
| 3808 |
+
less than `count`, the following condition holds:
|
| 3809 |
+
`invoke(pred, invoke(proj, *(i + n)), value)`. Returns `{last, last}` if
|
| 3810 |
+
no such iterator is found.
|
| 3811 |
+
|
| 3812 |
+
*Complexity:* At most `last - first` applications of the corresponding
|
| 3813 |
+
predicate and projection.
|
| 3814 |
+
|
| 3815 |
``` cpp
|
| 3816 |
template<class ForwardIterator, class Searcher>
|
| 3817 |
+
constexpr ForwardIterator
|
| 3818 |
+
search(ForwardIterator first, ForwardIterator last, const Searcher& searcher);
|
| 3819 |
```
|
| 3820 |
|
| 3821 |
*Effects:* Equivalent to: `return searcher(first, last).first;`
|
| 3822 |
|
| 3823 |
+
*Remarks:* `Searcher` need not meet the *Cpp17CopyConstructible*
|
| 3824 |
requirements.
|
| 3825 |
|
| 3826 |
## Mutating sequence operations <a id="alg.modifying.operations">[[alg.modifying.operations]]</a>
|
| 3827 |
|
| 3828 |
### Copy <a id="alg.copy">[[alg.copy]]</a>
|
| 3829 |
|
| 3830 |
``` cpp
|
| 3831 |
template<class InputIterator, class OutputIterator>
|
| 3832 |
+
constexpr OutputIterator copy(InputIterator first, InputIterator last,
|
| 3833 |
OutputIterator result);
|
| 3834 |
+
|
| 3835 |
+
template<input_iterator I, sentinel_for<I> S, weakly_incrementable O>
|
| 3836 |
+
requires indirectly_copyable<I, O>
|
| 3837 |
+
constexpr ranges::copy_result<I, O> ranges::copy(I first, S last, O result);
|
| 3838 |
+
template<input_range R, weakly_incrementable O>
|
| 3839 |
+
requires indirectly_copyable<iterator_t<R>, O>
|
| 3840 |
+
constexpr ranges::copy_result<borrowed_iterator_t<R>, O> ranges::copy(R&& r, O result);
|
| 3841 |
```
|
| 3842 |
|
| 3843 |
+
Let N be `last - first`.
|
| 3844 |
+
|
| 3845 |
+
*Preconditions:* `result` is not in the range \[`first`, `last`).
|
| 3846 |
|
| 3847 |
*Effects:* Copies elements in the range \[`first`, `last`) into the
|
| 3848 |
+
range \[`result`, `result + `N) starting from `first` and proceeding to
|
| 3849 |
+
`last`. For each non-negative integer n < N, performs
|
| 3850 |
+
`*(result + `n`) = *(first + `n`)`.
|
| 3851 |
|
| 3852 |
+
*Returns:*
|
| 3853 |
|
| 3854 |
+
- `result + `N for the overload in namespace `std`.
|
| 3855 |
+
- `{last, result + `N`}` for the overloads in namespace `ranges`.
|
| 3856 |
+
|
| 3857 |
+
*Complexity:* Exactly N assignments.
|
| 3858 |
|
| 3859 |
``` cpp
|
| 3860 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 3861 |
ForwardIterator2 copy(ExecutionPolicy&& policy,
|
| 3862 |
ForwardIterator1 first, ForwardIterator1 last,
|
| 3863 |
ForwardIterator2 result);
|
| 3864 |
```
|
| 3865 |
|
| 3866 |
+
*Preconditions:* The ranges \[`first`, `last`) and \[`result`,
|
| 3867 |
+
`result + (last - first)`) do not overlap.
|
| 3868 |
|
| 3869 |
*Effects:* Copies elements in the range \[`first`, `last`) into the
|
| 3870 |
range \[`result`, `result + (last - first)`). For each non-negative
|
| 3871 |
integer `n < (last - first)`, performs `*(result + n) = *(first + n)`.
|
| 3872 |
|
|
|
|
| 3874 |
|
| 3875 |
*Complexity:* Exactly `last - first` assignments.
|
| 3876 |
|
| 3877 |
``` cpp
|
| 3878 |
template<class InputIterator, class Size, class OutputIterator>
|
| 3879 |
+
constexpr OutputIterator copy_n(InputIterator first, Size n,
|
| 3880 |
OutputIterator result);
|
| 3881 |
template<class ExecutionPolicy, class ForwardIterator1, class Size, class ForwardIterator2>
|
| 3882 |
ForwardIterator2 copy_n(ExecutionPolicy&& exec,
|
| 3883 |
ForwardIterator1 first, Size n,
|
| 3884 |
ForwardIterator2 result);
|
| 3885 |
+
|
| 3886 |
+
template<input_iterator I, weakly_incrementable O>
|
| 3887 |
+
requires indirectly_copyable<I, O>
|
| 3888 |
+
constexpr ranges::copy_n_result<I, O>
|
| 3889 |
+
ranges::copy_n(I first, iter_difference_t<I> n, O result);
|
| 3890 |
```
|
| 3891 |
|
| 3892 |
+
Let N be max(0, `n`).
|
| 3893 |
+
|
| 3894 |
+
*Mandates:* The type `Size` is convertible to an integral
|
| 3895 |
+
type ([[conv.integral]], [[class.conv]]).
|
| 3896 |
+
|
| 3897 |
+
*Effects:* For each non-negative integer i < N, performs
|
| 3898 |
`*(result + i) = *(first + i)`.
|
| 3899 |
|
| 3900 |
+
*Returns:*
|
| 3901 |
|
| 3902 |
+
- `result + `N for the overloads in namespace `std`.
|
| 3903 |
+
- `{first + `N`, result + `N`}` for the overload in namespace `ranges`.
|
| 3904 |
+
|
| 3905 |
+
*Complexity:* Exactly N assignments.
|
| 3906 |
|
| 3907 |
``` cpp
|
| 3908 |
template<class InputIterator, class OutputIterator, class Predicate>
|
| 3909 |
+
constexpr OutputIterator copy_if(InputIterator first, InputIterator last,
|
| 3910 |
OutputIterator result, Predicate pred);
|
| 3911 |
+
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 3912 |
+
class Predicate>
|
| 3913 |
ForwardIterator2 copy_if(ExecutionPolicy&& exec,
|
| 3914 |
ForwardIterator1 first, ForwardIterator1 last,
|
| 3915 |
ForwardIterator2 result, Predicate pred);
|
| 3916 |
+
|
| 3917 |
+
template<input_iterator I, sentinel_for<I> S, weakly_incrementable O, class Proj = identity,
|
| 3918 |
+
indirect_unary_predicate<projected<I, Proj>> Pred>
|
| 3919 |
+
requires indirectly_copyable<I, O>
|
| 3920 |
+
constexpr ranges::copy_if_result<I, O>
|
| 3921 |
+
ranges::copy_if(I first, S last, O result, Pred pred, Proj proj = {});
|
| 3922 |
+
template<input_range R, weakly_incrementable O, class Proj = identity,
|
| 3923 |
+
indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
|
| 3924 |
+
requires indirectly_copyable<iterator_t<R>, O>
|
| 3925 |
+
constexpr ranges::copy_if_result<borrowed_iterator_t<R>, O>
|
| 3926 |
+
ranges::copy_if(R&& r, O result, Pred pred, Proj proj = {});
|
| 3927 |
```
|
| 3928 |
|
| 3929 |
+
Let E be:
|
| 3930 |
+
|
| 3931 |
+
- `bool(pred(*i))` for the overloads in namespace `std`;
|
| 3932 |
+
- `bool(invoke(pred, invoke(proj, *i)))` for the overloads in namespace
|
| 3933 |
+
`ranges`,
|
| 3934 |
+
|
| 3935 |
+
and N be the number of iterators `i` in the range \[`first`, `last`) for
|
| 3936 |
+
which the condition E holds.
|
| 3937 |
+
|
| 3938 |
+
*Preconditions:* The ranges \[`first`, `last`) and \[`result`,
|
| 3939 |
+
`result + (last - first)`) do not overlap.
|
| 3940 |
|
| 3941 |
[*Note 1*: For the overload with an `ExecutionPolicy`, there may be a
|
| 3942 |
performance cost if `iterator_traits<ForwardIterator1>::value_type` is
|
| 3943 |
+
not *Cpp17MoveConstructible*
|
| 3944 |
+
([[cpp17.moveconstructible]]). — *end note*]
|
| 3945 |
|
| 3946 |
*Effects:* Copies all of the elements referred to by the iterator `i` in
|
| 3947 |
+
the range \[`first`, `last`) for which E is `true`.
|
| 3948 |
|
| 3949 |
+
*Returns:*
|
| 3950 |
+
|
| 3951 |
+
- `result + `N for the overloads in namespace `std`.
|
| 3952 |
+
- `{last, result + `N`}` for the overloads in namespace `ranges`.
|
| 3953 |
|
| 3954 |
*Complexity:* Exactly `last - first` applications of the corresponding
|
| 3955 |
+
predicate and any projection.
|
| 3956 |
|
| 3957 |
+
*Remarks:* Stable [[algorithm.stable]].
|
| 3958 |
|
| 3959 |
``` cpp
|
| 3960 |
template<class BidirectionalIterator1, class BidirectionalIterator2>
|
| 3961 |
+
constexpr BidirectionalIterator2
|
| 3962 |
copy_backward(BidirectionalIterator1 first,
|
| 3963 |
BidirectionalIterator1 last,
|
| 3964 |
BidirectionalIterator2 result);
|
| 3965 |
+
|
| 3966 |
+
template<bidirectional_iterator I1, sentinel_for<I1> S1, bidirectional_iterator I2>
|
| 3967 |
+
requires indirectly_copyable<I1, I2>
|
| 3968 |
+
constexpr ranges::copy_backward_result<I1, I2>
|
| 3969 |
+
ranges::copy_backward(I1 first, S1 last, I2 result);
|
| 3970 |
+
template<bidirectional_range R, bidirectional_iterator I>
|
| 3971 |
+
requires indirectly_copyable<iterator_t<R>, I>
|
| 3972 |
+
constexpr ranges::copy_backward_result<borrowed_iterator_t<R>, I>
|
| 3973 |
+
ranges::copy_backward(R&& r, I result);
|
| 3974 |
```
|
| 3975 |
|
| 3976 |
+
Let N be `last - first`.
|
| 3977 |
+
|
| 3978 |
+
*Preconditions:* `result` is not in the range (`first`, `last`).
|
| 3979 |
|
| 3980 |
*Effects:* Copies elements in the range \[`first`, `last`) into the
|
| 3981 |
+
range \[`result - `N, `result`) starting from `last - 1` and proceeding
|
| 3982 |
+
to `first`. [^2] For each positive integer n ≤ N, performs
|
| 3983 |
+
`*(result - `n`) = *(last - `n`)`.
|
| 3984 |
|
| 3985 |
+
*Returns:*
|
| 3986 |
|
| 3987 |
+
- `result - `N for the overload in namespace `std`.
|
| 3988 |
+
- `{last, result - `N`}` for the overloads in namespace `ranges`.
|
| 3989 |
+
|
| 3990 |
+
*Complexity:* Exactly N assignments.
|
| 3991 |
|
| 3992 |
### Move <a id="alg.move">[[alg.move]]</a>
|
| 3993 |
|
| 3994 |
``` cpp
|
| 3995 |
template<class InputIterator, class OutputIterator>
|
| 3996 |
+
constexpr OutputIterator move(InputIterator first, InputIterator last,
|
| 3997 |
+
OutputIterator result);
|
| 3998 |
+
|
| 3999 |
+
template<input_iterator I, sentinel_for<I> S, weakly_incrementable O>
|
| 4000 |
+
requires indirectly_movable<I, O>
|
| 4001 |
+
constexpr ranges::move_result<I, O>
|
| 4002 |
+
ranges::move(I first, S last, O result);
|
| 4003 |
+
template<input_range R, weakly_incrementable O>
|
| 4004 |
+
requires indirectly_movable<iterator_t<R>, O>
|
| 4005 |
+
constexpr ranges::move_result<borrowed_iterator_t<R>, O>
|
| 4006 |
+
ranges::move(R&& r, O result);
|
| 4007 |
```
|
| 4008 |
|
| 4009 |
+
Let E be
|
| 4010 |
+
|
| 4011 |
+
- `std::move(*(first + `n`))` for the overload in namespace `std`;
|
| 4012 |
+
- `ranges::iter_move(first + `n`)` for the overloads in namespace
|
| 4013 |
+
`ranges`.
|
| 4014 |
+
|
| 4015 |
+
Let N be `last - first`.
|
| 4016 |
+
|
| 4017 |
+
*Preconditions:* `result` is not in the range \[`first`, `last`).
|
| 4018 |
|
| 4019 |
*Effects:* Moves elements in the range \[`first`, `last`) into the range
|
| 4020 |
+
\[`result`, `result + `N) starting from `first` and proceeding to
|
| 4021 |
+
`last`. For each non-negative integer n < N, performs
|
| 4022 |
+
`*(result + `n`) = `E.
|
| 4023 |
|
| 4024 |
+
*Returns:*
|
| 4025 |
|
| 4026 |
+
- `result + `N for the overload in namespace `std`.
|
| 4027 |
+
- `{last, result + `N`}` for the overloads in namespace `ranges`.
|
| 4028 |
+
|
| 4029 |
+
*Complexity:* Exactly N assignments.
|
| 4030 |
|
| 4031 |
``` cpp
|
| 4032 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 4033 |
ForwardIterator2 move(ExecutionPolicy&& policy,
|
| 4034 |
ForwardIterator1 first, ForwardIterator1 last,
|
| 4035 |
ForwardIterator2 result);
|
| 4036 |
```
|
| 4037 |
|
| 4038 |
+
Let N be `last - first`.
|
| 4039 |
+
|
| 4040 |
+
*Preconditions:* The ranges \[`first`, `last`) and \[`result`,
|
| 4041 |
+
`result + `N) do not overlap.
|
| 4042 |
|
| 4043 |
*Effects:* Moves elements in the range \[`first`, `last`) into the range
|
| 4044 |
+
\[`result`, `result + `N). For each non-negative integer n < N, performs
|
| 4045 |
+
`*(result + `n`) = std::move(*(first + `n`))`.
|
|
|
|
| 4046 |
|
| 4047 |
+
*Returns:* `result + `N.
|
| 4048 |
|
| 4049 |
+
*Complexity:* Exactly N assignments.
|
| 4050 |
|
| 4051 |
``` cpp
|
| 4052 |
template<class BidirectionalIterator1, class BidirectionalIterator2>
|
| 4053 |
+
constexpr BidirectionalIterator2
|
| 4054 |
+
move_backward(BidirectionalIterator1 first, BidirectionalIterator1 last,
|
|
|
|
| 4055 |
BidirectionalIterator2 result);
|
| 4056 |
+
|
| 4057 |
+
template<bidirectional_iterator I1, sentinel_for<I1> S1, bidirectional_iterator I2>
|
| 4058 |
+
requires indirectly_movable<I1, I2>
|
| 4059 |
+
constexpr ranges::move_backward_result<I1, I2>
|
| 4060 |
+
ranges::move_backward(I1 first, S1 last, I2 result);
|
| 4061 |
+
template<bidirectional_range R, bidirectional_iterator I>
|
| 4062 |
+
requires indirectly_movable<iterator_t<R>, I>
|
| 4063 |
+
constexpr ranges::move_backward_result<borrowed_iterator_t<R>, I>
|
| 4064 |
+
ranges::move_backward(R&& r, I result);
|
| 4065 |
```
|
| 4066 |
|
| 4067 |
+
Let E be
|
| 4068 |
+
|
| 4069 |
+
- `std::move(*(last - `n`))` for the overload in namespace `std`;
|
| 4070 |
+
- `ranges::iter_move(last - `n`)` for the overloads in namespace
|
| 4071 |
+
`ranges`.
|
| 4072 |
+
|
| 4073 |
+
Let N be `last - first`.
|
| 4074 |
+
|
| 4075 |
+
*Preconditions:* `result` is not in the range (`first`, `last`).
|
| 4076 |
|
| 4077 |
*Effects:* Moves elements in the range \[`first`, `last`) into the range
|
| 4078 |
+
\[`result - `N, `result`) starting from `last - 1` and proceeding to
|
| 4079 |
+
`first`. [^3] For each positive integer n ≤ N, performs
|
| 4080 |
+
`*(result - `n`) = `E.
|
|
|
|
| 4081 |
|
| 4082 |
+
*Returns:*
|
| 4083 |
|
| 4084 |
+
- `result - `N for the overload in namespace `std`.
|
| 4085 |
+
- `{last, result - `N`}` for the overloads in namespace `ranges`.
|
| 4086 |
+
|
| 4087 |
+
*Complexity:* Exactly N assignments.
|
| 4088 |
|
| 4089 |
### Swap <a id="alg.swap">[[alg.swap]]</a>
|
| 4090 |
|
| 4091 |
``` cpp
|
| 4092 |
template<class ForwardIterator1, class ForwardIterator2>
|
| 4093 |
+
constexpr ForwardIterator2
|
| 4094 |
swap_ranges(ForwardIterator1 first1, ForwardIterator1 last1,
|
| 4095 |
ForwardIterator2 first2);
|
| 4096 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 4097 |
ForwardIterator2
|
| 4098 |
swap_ranges(ExecutionPolicy&& exec,
|
| 4099 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 4100 |
ForwardIterator2 first2);
|
| 4101 |
+
|
| 4102 |
+
template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2>
|
| 4103 |
+
requires indirectly_swappable<I1, I2>
|
| 4104 |
+
constexpr ranges::swap_ranges_result<I1, I2>
|
| 4105 |
+
ranges::swap_ranges(I1 first1, S1 last1, I2 first2, S2 last2);
|
| 4106 |
+
template<input_range R1, input_range R2>
|
| 4107 |
+
requires indirectly_swappable<iterator_t<R1>, iterator_t<R2>>
|
| 4108 |
+
constexpr ranges::swap_ranges_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>>
|
| 4109 |
+
ranges::swap_ranges(R1&& r1, R2&& r2);
|
| 4110 |
```
|
| 4111 |
|
| 4112 |
+
Let:
|
|
|
|
|
|
|
| 4113 |
|
| 4114 |
+
- `last2` be `first2 + (last1 - first1)` for the overloads with no
|
| 4115 |
+
parameter named `last2`;
|
| 4116 |
+
- M be min(`last1 - first1`, `last2 - first2`).
|
| 4117 |
|
| 4118 |
+
*Preconditions:* The two ranges \[`first1`, `last1`) and \[`first2`,
|
| 4119 |
+
`last2`) do not overlap. For the overloads in namespace `std`,
|
| 4120 |
+
`*(first1 + `n`)` is swappable with [[swappable.requirements]]
|
| 4121 |
+
`*(first2 + `n`)`.
|
| 4122 |
|
| 4123 |
+
*Effects:* For each non-negative integer n < M performs:
|
| 4124 |
+
|
| 4125 |
+
- `swap(*(first1 + `n`), *(first2 + `n`))` for the overloads in
|
| 4126 |
+
namespace `std`;
|
| 4127 |
+
- `ranges::iter_swap(first1 + `n`, first2 + `n`)` for the overloads in
|
| 4128 |
+
namespace `ranges`.
|
| 4129 |
+
|
| 4130 |
+
*Returns:*
|
| 4131 |
+
|
| 4132 |
+
- `last2` for the overloads in namespace `std`.
|
| 4133 |
+
- `{first1 + `M`, first2 + `M`}` for the overloads in namespace
|
| 4134 |
+
`ranges`.
|
| 4135 |
+
|
| 4136 |
+
*Complexity:* Exactly M swaps.
|
| 4137 |
|
| 4138 |
``` cpp
|
| 4139 |
template<class ForwardIterator1, class ForwardIterator2>
|
| 4140 |
+
constexpr void iter_swap(ForwardIterator1 a, ForwardIterator2 b);
|
| 4141 |
```
|
| 4142 |
|
| 4143 |
+
*Preconditions:* `a` and `b` are dereferenceable. `*a` is swappable
|
| 4144 |
+
with [[swappable.requirements]] `*b`.
|
| 4145 |
|
| 4146 |
*Effects:* As if by `swap(*a, *b)`.
|
| 4147 |
|
| 4148 |
### Transform <a id="alg.transform">[[alg.transform]]</a>
|
| 4149 |
|
| 4150 |
``` cpp
|
| 4151 |
template<class InputIterator, class OutputIterator,
|
| 4152 |
class UnaryOperation>
|
| 4153 |
+
constexpr OutputIterator
|
| 4154 |
+
transform(InputIterator first1, InputIterator last1,
|
| 4155 |
OutputIterator result, UnaryOperation op);
|
| 4156 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 4157 |
class UnaryOperation>
|
| 4158 |
ForwardIterator2
|
| 4159 |
transform(ExecutionPolicy&& exec,
|
| 4160 |
+
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 4161 |
ForwardIterator2 result, UnaryOperation op);
|
| 4162 |
|
| 4163 |
template<class InputIterator1, class InputIterator2,
|
| 4164 |
class OutputIterator, class BinaryOperation>
|
| 4165 |
+
constexpr OutputIterator
|
| 4166 |
transform(InputIterator1 first1, InputIterator1 last1,
|
| 4167 |
InputIterator2 first2, OutputIterator result,
|
| 4168 |
BinaryOperation binary_op);
|
| 4169 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 4170 |
class ForwardIterator, class BinaryOperation>
|
| 4171 |
ForwardIterator
|
| 4172 |
transform(ExecutionPolicy&& exec,
|
| 4173 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 4174 |
ForwardIterator2 first2, ForwardIterator result,
|
| 4175 |
BinaryOperation binary_op);
|
| 4176 |
+
|
| 4177 |
+
template<input_iterator I, sentinel_for<I> S, weakly_incrementable O,
|
| 4178 |
+
copy_constructible F, class Proj = identity>
|
| 4179 |
+
requires indirectly_writable<O, indirect_result_t<F&, projected<I, Proj>>>
|
| 4180 |
+
constexpr ranges::unary_transform_result<I, O>
|
| 4181 |
+
ranges::transform(I first1, S last1, O result, F op, Proj proj = {});
|
| 4182 |
+
template<input_range R, weakly_incrementable O, copy_constructible F,
|
| 4183 |
+
class Proj = identity>
|
| 4184 |
+
requires indirectly_writable<O, indirect_result_t<F&, projected<iterator_t<R>, Proj>>>
|
| 4185 |
+
constexpr ranges::unary_transform_result<borrowed_iterator_t<R>, O>
|
| 4186 |
+
ranges::transform(R&& r, O result, F op, Proj proj = {});
|
| 4187 |
+
template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2,
|
| 4188 |
+
weakly_incrementable O, copy_constructible F, class Proj1 = identity,
|
| 4189 |
+
class Proj2 = identity>
|
| 4190 |
+
requires indirectly_writable<O, indirect_result_t<F&, projected<I1, Proj1>,
|
| 4191 |
+
projected<I2, Proj2>>>
|
| 4192 |
+
constexpr ranges::binary_transform_result<I1, I2, O>
|
| 4193 |
+
ranges::transform(I1 first1, S1 last1, I2 first2, S2 last2, O result,
|
| 4194 |
+
F binary_op, Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 4195 |
+
template<input_range R1, input_range R2, weakly_incrementable O,
|
| 4196 |
+
copy_constructible F, class Proj1 = identity, class Proj2 = identity>
|
| 4197 |
+
requires indirectly_writable<O, indirect_result_t<F&, projected<iterator_t<R1>, Proj1>,
|
| 4198 |
+
projected<iterator_t<R2>, Proj2>>>
|
| 4199 |
+
constexpr ranges::binary_transform_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>, O>
|
| 4200 |
+
ranges::transform(R1&& r1, R2&& r2, O result,
|
| 4201 |
+
F binary_op, Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 4202 |
```
|
| 4203 |
|
| 4204 |
+
Let:
|
|
|
|
| 4205 |
|
| 4206 |
+
- `last2` be `first2 + (last1 - first1)` for the overloads with
|
| 4207 |
+
parameter `first2` but no parameter `last2`;
|
| 4208 |
+
- N be `last1 - first1` for unary transforms, or
|
| 4209 |
+
min(`last1 - first1`, `last2 - first2`) for binary transforms;
|
| 4210 |
+
- E be
|
| 4211 |
+
- `op(*(first1 + (i - result)))` for unary transforms defined in
|
| 4212 |
+
namespace `std`;
|
| 4213 |
+
- `binary_op(*(first1 + (i - result)), *(first2 + (i - result)))` for
|
| 4214 |
+
binary transforms defined in namespace `std`;
|
| 4215 |
+
- `invoke(op, invoke(proj, *(first1 + (i - result))))` for unary
|
| 4216 |
+
transforms defined in namespace `ranges`;
|
| 4217 |
+
- `invoke(binary_op, invoke(proj1, *(first1 + (i - result))), invoke(proj2,*(first2 + (i - result))))`
|
| 4218 |
+
for binary transforms defined in namespace `ranges`.
|
| 4219 |
+
|
| 4220 |
+
*Preconditions:* `op` and `binary_op` do not invalidate iterators or
|
| 4221 |
+
subranges, nor modify elements in the ranges
|
| 4222 |
+
|
| 4223 |
+
- \[`first1`, `first1 + `N\],
|
| 4224 |
+
- \[`first2`, `first2 + `N\], and
|
| 4225 |
+
- \[`result`, `result + `N\]. [^4]
|
| 4226 |
|
| 4227 |
*Effects:* Assigns through every iterator `i` in the range \[`result`,
|
| 4228 |
+
`result + `N) a new corresponding value equal to E.
|
|
|
|
|
|
|
| 4229 |
|
| 4230 |
+
*Returns:*
|
| 4231 |
|
| 4232 |
+
- `result + `N for the overloads defined in namespace `std`.
|
| 4233 |
+
- `{first1 + `N`, result + `N`}` for unary transforms defined in
|
| 4234 |
+
namespace `ranges`.
|
| 4235 |
+
- `{first1 + `N`, first2 + `N`, result + `N`}` for binary transforms
|
| 4236 |
+
defined in namespace `ranges`.
|
| 4237 |
+
|
| 4238 |
+
*Complexity:* Exactly N applications of `op` or `binary_op`, and any
|
| 4239 |
+
projections. This requirement also applies to the overload with an
|
| 4240 |
`ExecutionPolicy`.
|
| 4241 |
|
| 4242 |
+
*Remarks:* `result` may be equal to `first1` or `first2`.
|
|
|
|
| 4243 |
|
| 4244 |
### Replace <a id="alg.replace">[[alg.replace]]</a>
|
| 4245 |
|
| 4246 |
``` cpp
|
| 4247 |
template<class ForwardIterator, class T>
|
| 4248 |
+
constexpr void replace(ForwardIterator first, ForwardIterator last,
|
| 4249 |
const T& old_value, const T& new_value);
|
| 4250 |
template<class ExecutionPolicy, class ForwardIterator, class T>
|
| 4251 |
void replace(ExecutionPolicy&& exec,
|
| 4252 |
ForwardIterator first, ForwardIterator last,
|
| 4253 |
const T& old_value, const T& new_value);
|
| 4254 |
|
| 4255 |
template<class ForwardIterator, class Predicate, class T>
|
| 4256 |
+
constexpr void replace_if(ForwardIterator first, ForwardIterator last,
|
| 4257 |
Predicate pred, const T& new_value);
|
| 4258 |
template<class ExecutionPolicy, class ForwardIterator, class Predicate, class T>
|
| 4259 |
void replace_if(ExecutionPolicy&& exec,
|
| 4260 |
ForwardIterator first, ForwardIterator last,
|
| 4261 |
Predicate pred, const T& new_value);
|
| 4262 |
+
|
| 4263 |
+
template<input_iterator I, sentinel_for<I> S, class T1, class T2, class Proj = identity>
|
| 4264 |
+
requires indirectly_writable<I, const T2&> &&
|
| 4265 |
+
indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T1*>
|
| 4266 |
+
constexpr I
|
| 4267 |
+
ranges::replace(I first, S last, const T1& old_value, const T2& new_value, Proj proj = {});
|
| 4268 |
+
template<input_range R, class T1, class T2, class Proj = identity>
|
| 4269 |
+
requires indirectly_writable<iterator_t<R>, const T2&> &&
|
| 4270 |
+
indirect_binary_predicate<ranges::equal_to, projected<iterator_t<R>, Proj>, const T1*>
|
| 4271 |
+
constexpr borrowed_iterator_t<R>
|
| 4272 |
+
ranges::replace(R&& r, const T1& old_value, const T2& new_value, Proj proj = {});
|
| 4273 |
+
template<input_iterator I, sentinel_for<I> S, class T, class Proj = identity,
|
| 4274 |
+
indirect_unary_predicate<projected<I, Proj>> Pred>
|
| 4275 |
+
requires indirectly_writable<I, const T&>
|
| 4276 |
+
constexpr I ranges::replace_if(I first, S last, Pred pred, const T& new_value, Proj proj = {});
|
| 4277 |
+
template<input_range R, class T, class Proj = identity,
|
| 4278 |
+
indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
|
| 4279 |
+
requires indirectly_writable<iterator_t<R>, const T&>
|
| 4280 |
+
constexpr borrowed_iterator_t<R>
|
| 4281 |
+
ranges::replace_if(R&& r, Pred pred, const T& new_value, Proj proj = {});
|
| 4282 |
```
|
| 4283 |
|
| 4284 |
+
Let E be
|
| 4285 |
+
|
| 4286 |
+
- `bool(*i == old_value)` for `replace`;
|
| 4287 |
+
- `bool(pred(*i))` for `replace_if`;
|
| 4288 |
+
- `bool(invoke(proj, *i) == old_value)` for `ranges::replace`;
|
| 4289 |
+
- `bool(invoke(pred, invoke(proj, *i)))` for `ranges::replace_if`.
|
| 4290 |
+
|
| 4291 |
+
*Mandates:* `new_value` is writable [[iterator.requirements.general]] to
|
| 4292 |
+
`first`.
|
| 4293 |
|
| 4294 |
*Effects:* Substitutes elements referred by the iterator `i` in the
|
| 4295 |
+
range \[`first`, `last`) with `new_value`, when E is `true`.
|
| 4296 |
+
|
| 4297 |
+
*Returns:* `last` for the overloads in namespace `ranges`.
|
| 4298 |
|
| 4299 |
*Complexity:* Exactly `last - first` applications of the corresponding
|
| 4300 |
+
predicate and any projection.
|
| 4301 |
|
| 4302 |
``` cpp
|
| 4303 |
template<class InputIterator, class OutputIterator, class T>
|
| 4304 |
+
constexpr OutputIterator
|
| 4305 |
replace_copy(InputIterator first, InputIterator last,
|
| 4306 |
OutputIterator result,
|
| 4307 |
const T& old_value, const T& new_value);
|
| 4308 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class T>
|
| 4309 |
ForwardIterator2
|
|
|
|
| 4311 |
ForwardIterator1 first, ForwardIterator1 last,
|
| 4312 |
ForwardIterator2 result,
|
| 4313 |
const T& old_value, const T& new_value);
|
| 4314 |
|
| 4315 |
template<class InputIterator, class OutputIterator, class Predicate, class T>
|
| 4316 |
+
constexpr OutputIterator
|
| 4317 |
replace_copy_if(InputIterator first, InputIterator last,
|
| 4318 |
OutputIterator result,
|
| 4319 |
Predicate pred, const T& new_value);
|
| 4320 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 4321 |
class Predicate, class T>
|
| 4322 |
ForwardIterator2
|
| 4323 |
replace_copy_if(ExecutionPolicy&& exec,
|
| 4324 |
ForwardIterator1 first, ForwardIterator1 last,
|
| 4325 |
ForwardIterator2 result,
|
| 4326 |
Predicate pred, const T& new_value);
|
| 4327 |
+
|
| 4328 |
+
template<input_iterator I, sentinel_for<I> S, class T1, class T2, output_iterator<const T2&> O,
|
| 4329 |
+
class Proj = identity>
|
| 4330 |
+
requires indirectly_copyable<I, O> &&
|
| 4331 |
+
indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T1*>
|
| 4332 |
+
constexpr ranges::replace_copy_result<I, O>
|
| 4333 |
+
ranges::replace_copy(I first, S last, O result, const T1& old_value, const T2& new_value,
|
| 4334 |
+
Proj proj = {});
|
| 4335 |
+
template<input_range R, class T1, class T2, output_iterator<const T2&> O,
|
| 4336 |
+
class Proj = identity>
|
| 4337 |
+
requires indirectly_copyable<iterator_t<R>, O> &&
|
| 4338 |
+
indirect_binary_predicate<ranges::equal_to, projected<iterator_t<R>, Proj>, const T1*>
|
| 4339 |
+
constexpr ranges::replace_copy_result<borrowed_iterator_t<R>, O>
|
| 4340 |
+
ranges::replace_copy(R&& r, O result, const T1& old_value, const T2& new_value,
|
| 4341 |
+
Proj proj = {});
|
| 4342 |
+
|
| 4343 |
+
template<input_iterator I, sentinel_for<I> S, class T, output_iterator<const T&> O,
|
| 4344 |
+
class Proj = identity, indirect_unary_predicate<projected<I, Proj>> Pred>
|
| 4345 |
+
requires indirectly_copyable<I, O>
|
| 4346 |
+
constexpr ranges::replace_copy_if_result<I, O>
|
| 4347 |
+
ranges::replace_copy_if(I first, S last, O result, Pred pred, const T& new_value,
|
| 4348 |
+
Proj proj = {});
|
| 4349 |
+
template<input_range R, class T, output_iterator<const T&> O, class Proj = identity,
|
| 4350 |
+
indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
|
| 4351 |
+
requires indirectly_copyable<iterator_t<R>, O>
|
| 4352 |
+
constexpr ranges::replace_copy_if_result<borrowed_iterator_t<R>, O>
|
| 4353 |
+
ranges::replace_copy_if(R&& r, O result, Pred pred, const T& new_value,
|
| 4354 |
+
Proj proj = {});
|
| 4355 |
```
|
| 4356 |
|
| 4357 |
+
Let E be
|
|
|
|
|
|
|
|
|
|
| 4358 |
|
| 4359 |
+
- `bool(*(first + (i - result)) == old_value)` for `replace_copy`;
|
| 4360 |
+
- `bool(pred(*(first + (i - result))))` for `replace_copy_if`;
|
| 4361 |
+
- `bool(invoke(proj, *(first + (i - result))) == old_value)` for
|
| 4362 |
+
`ranges::replace_copy`;
|
| 4363 |
+
- `bool(invoke(pred, invoke(proj, *(first + (i - result)))))` for
|
| 4364 |
+
`ranges::replace_copy_if`.
|
| 4365 |
|
| 4366 |
+
*Mandates:* The results of the expressions `*first` and `new_value` are
|
| 4367 |
+
writable [[iterator.requirements.general]] to `result`.
|
| 4368 |
+
|
| 4369 |
+
*Preconditions:* The ranges \[`first`, `last`) and \[`result`,
|
| 4370 |
+
`result + (last - first)`) do not overlap.
|
| 4371 |
+
|
| 4372 |
+
*Effects:* Assigns through every iterator `i` in the range \[`result`,
|
| 4373 |
+
`result + (last - first)`) a new corresponding value
|
| 4374 |
+
|
| 4375 |
+
- `new_value` if E is `true` or
|
| 4376 |
+
- `*(first + (i - result))` otherwise.
|
| 4377 |
+
|
| 4378 |
+
*Returns:*
|
| 4379 |
|
| 4380 |
+
- `result + (last - first)` for the overloads in namespace `std`.
|
| 4381 |
+
- `{last, result + (last - first)}` for the overloads in namespace
|
| 4382 |
+
`ranges`.
|
| 4383 |
|
| 4384 |
*Complexity:* Exactly `last - first` applications of the corresponding
|
| 4385 |
+
predicate and any projection.
|
| 4386 |
|
| 4387 |
### Fill <a id="alg.fill">[[alg.fill]]</a>
|
| 4388 |
|
| 4389 |
``` cpp
|
| 4390 |
template<class ForwardIterator, class T>
|
| 4391 |
+
constexpr void fill(ForwardIterator first, ForwardIterator last, const T& value);
|
| 4392 |
template<class ExecutionPolicy, class ForwardIterator, class T>
|
| 4393 |
void fill(ExecutionPolicy&& exec,
|
| 4394 |
ForwardIterator first, ForwardIterator last, const T& value);
|
| 4395 |
|
| 4396 |
template<class OutputIterator, class Size, class T>
|
| 4397 |
+
constexpr OutputIterator fill_n(OutputIterator first, Size n, const T& value);
|
| 4398 |
template<class ExecutionPolicy, class ForwardIterator, class Size, class T>
|
| 4399 |
ForwardIterator fill_n(ExecutionPolicy&& exec,
|
| 4400 |
ForwardIterator first, Size n, const T& value);
|
| 4401 |
+
|
| 4402 |
+
|
| 4403 |
+
template<class T, output_iterator<const T&> O, sentinel_for<O> S>
|
| 4404 |
+
constexpr O ranges::fill(O first, S last, const T& value);
|
| 4405 |
+
template<class T, output_range<const T&> R>
|
| 4406 |
+
constexpr borrowed_iterator_t<R> ranges::fill(R&& r, const T& value);
|
| 4407 |
+
template<class T, output_iterator<const T&> O>
|
| 4408 |
+
constexpr O ranges::fill_n(O first, iter_difference_t<O> n, const T& value);
|
| 4409 |
```
|
| 4410 |
|
| 4411 |
+
Let N be max(0, `n`) for the `fill_n` algorithms, and `last - first` for
|
| 4412 |
+
the `fill` algorithms.
|
|
|
|
|
|
|
| 4413 |
|
| 4414 |
+
*Mandates:* The expression `value` is
|
| 4415 |
+
writable [[iterator.requirements.general]] to the output iterator. The
|
| 4416 |
+
type `Size` is convertible to an integral type ([[conv.integral]],
|
| 4417 |
+
[[class.conv]]).
|
| 4418 |
|
| 4419 |
+
*Effects:* Assigns `value` through all the iterators in the range
|
| 4420 |
+
\[`first`, `first + `N).
|
| 4421 |
|
| 4422 |
+
*Returns:* `first + `N.
|
| 4423 |
+
|
| 4424 |
+
*Complexity:* Exactly N assignments.
|
| 4425 |
|
| 4426 |
### Generate <a id="alg.generate">[[alg.generate]]</a>
|
| 4427 |
|
| 4428 |
``` cpp
|
| 4429 |
template<class ForwardIterator, class Generator>
|
| 4430 |
+
constexpr void generate(ForwardIterator first, ForwardIterator last,
|
| 4431 |
Generator gen);
|
| 4432 |
template<class ExecutionPolicy, class ForwardIterator, class Generator>
|
| 4433 |
void generate(ExecutionPolicy&& exec,
|
| 4434 |
ForwardIterator first, ForwardIterator last,
|
| 4435 |
Generator gen);
|
| 4436 |
|
| 4437 |
template<class OutputIterator, class Size, class Generator>
|
| 4438 |
+
constexpr OutputIterator generate_n(OutputIterator first, Size n, Generator gen);
|
| 4439 |
template<class ExecutionPolicy, class ForwardIterator, class Size, class Generator>
|
| 4440 |
ForwardIterator generate_n(ExecutionPolicy&& exec,
|
| 4441 |
ForwardIterator first, Size n, Generator gen);
|
| 4442 |
+
|
| 4443 |
+
template<input_or_output_iterator O, sentinel_for<O> S, copy_constructible F>
|
| 4444 |
+
requires invocable<F&> && indirectly_writable<O, invoke_result_t<F&>>
|
| 4445 |
+
constexpr O ranges::generate(O first, S last, F gen);
|
| 4446 |
+
template<class R, copy_constructible F>
|
| 4447 |
+
requires invocable<F&> && output_range<R, invoke_result_t<F&>>
|
| 4448 |
+
constexpr borrowed_iterator_t<R> ranges::generate(R&& r, F gen);
|
| 4449 |
+
template<input_or_output_iterator O, copy_constructible F>
|
| 4450 |
+
requires invocable<F&> && indirectly_writable<O, invoke_result_t<F&>>
|
| 4451 |
+
constexpr O ranges::generate_n(O first, iter_difference_t<O> n, F gen);
|
| 4452 |
```
|
| 4453 |
|
| 4454 |
+
Let N be max(0, `n`) for the `generate_n` algorithms, and `last - first`
|
| 4455 |
+
for the `generate` algorithms.
|
| 4456 |
|
| 4457 |
+
*Mandates:* `Size` is convertible to an integral
|
| 4458 |
+
type ([[conv.integral]], [[class.conv]]).
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4459 |
|
| 4460 |
+
*Effects:* Assigns the result of successive evaluations of `gen()`
|
| 4461 |
+
through each iterator in the range \[`first`, `first + `N).
|
| 4462 |
|
| 4463 |
+
*Returns:* `first + `N.
|
| 4464 |
+
|
| 4465 |
+
*Complexity:* Exactly N evaluations of `gen()` and assignments.
|
| 4466 |
|
| 4467 |
### Remove <a id="alg.remove">[[alg.remove]]</a>
|
| 4468 |
|
| 4469 |
``` cpp
|
| 4470 |
template<class ForwardIterator, class T>
|
| 4471 |
+
constexpr ForwardIterator remove(ForwardIterator first, ForwardIterator last,
|
| 4472 |
const T& value);
|
| 4473 |
template<class ExecutionPolicy, class ForwardIterator, class T>
|
| 4474 |
ForwardIterator remove(ExecutionPolicy&& exec,
|
| 4475 |
ForwardIterator first, ForwardIterator last,
|
| 4476 |
const T& value);
|
| 4477 |
|
| 4478 |
template<class ForwardIterator, class Predicate>
|
| 4479 |
+
constexpr ForwardIterator remove_if(ForwardIterator first, ForwardIterator last,
|
| 4480 |
Predicate pred);
|
| 4481 |
template<class ExecutionPolicy, class ForwardIterator, class Predicate>
|
| 4482 |
ForwardIterator remove_if(ExecutionPolicy&& exec,
|
| 4483 |
ForwardIterator first, ForwardIterator last,
|
| 4484 |
Predicate pred);
|
| 4485 |
+
|
| 4486 |
+
template<permutable I, sentinel_for<I> S, class T, class Proj = identity>
|
| 4487 |
+
requires indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T*>
|
| 4488 |
+
constexpr subrange<I> ranges::remove(I first, S last, const T& value, Proj proj = {});
|
| 4489 |
+
template<forward_range R, class T, class Proj = identity>
|
| 4490 |
+
requires permutable<iterator_t<R>> &&
|
| 4491 |
+
indirect_binary_predicate<ranges::equal_to, projected<iterator_t<R>, Proj>, const T*>
|
| 4492 |
+
constexpr borrowed_subrange_t<R>
|
| 4493 |
+
ranges::remove(R&& r, const T& value, Proj proj = {});
|
| 4494 |
+
template<permutable I, sentinel_for<I> S, class Proj = identity,
|
| 4495 |
+
indirect_unary_predicate<projected<I, Proj>> Pred>
|
| 4496 |
+
constexpr subrange<I> ranges::remove_if(I first, S last, Pred pred, Proj proj = {});
|
| 4497 |
+
template<forward_range R, class Proj = identity,
|
| 4498 |
+
indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
|
| 4499 |
+
requires permutable<iterator_t<R>>
|
| 4500 |
+
constexpr borrowed_subrange_t<R>
|
| 4501 |
+
ranges::remove_if(R&& r, Pred pred, Proj proj = {});
|
| 4502 |
```
|
| 4503 |
|
| 4504 |
+
Let E be
|
| 4505 |
+
|
| 4506 |
+
- `bool(*i == value)` for `remove`;
|
| 4507 |
+
- `bool(pred(*i))` for `remove_if`;
|
| 4508 |
+
- `bool(invoke(proj, *i) == value)` for `ranges::remove`;
|
| 4509 |
+
- `bool(invoke(pred, invoke(proj, *i)))` for `ranges::remove_if`.
|
| 4510 |
+
|
| 4511 |
+
*Preconditions:* For the algorithms in namespace `std`, the type of
|
| 4512 |
+
`*first` meets the *Cpp17MoveAssignable* requirements
|
| 4513 |
+
([[cpp17.moveassignable]]).
|
| 4514 |
|
| 4515 |
*Effects:* Eliminates all the elements referred to by iterator `i` in
|
| 4516 |
+
the range \[`first`, `last`) for which E holds.
|
|
|
|
| 4517 |
|
| 4518 |
+
*Returns:* Let j be the end of the resulting range. Returns:
|
| 4519 |
|
| 4520 |
+
- j for the overloads in namespace `std`.
|
| 4521 |
+
- `{`j`, last}` for the overloads in namespace `ranges`.
|
| 4522 |
+
|
| 4523 |
+
*Remarks:* Stable [[algorithm.stable]].
|
| 4524 |
|
| 4525 |
*Complexity:* Exactly `last - first` applications of the corresponding
|
| 4526 |
+
predicate and any projection.
|
| 4527 |
|
| 4528 |
[*Note 1*: Each element in the range \[`ret`, `last`), where `ret` is
|
| 4529 |
the returned value, has a valid but unspecified state, because the
|
| 4530 |
algorithms can eliminate elements by moving from elements that were
|
| 4531 |
originally in that range. — *end note*]
|
| 4532 |
|
| 4533 |
``` cpp
|
| 4534 |
template<class InputIterator, class OutputIterator, class T>
|
| 4535 |
+
constexpr OutputIterator
|
| 4536 |
remove_copy(InputIterator first, InputIterator last,
|
| 4537 |
OutputIterator result, const T& value);
|
| 4538 |
+
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 4539 |
+
class T>
|
| 4540 |
ForwardIterator2
|
| 4541 |
remove_copy(ExecutionPolicy&& exec,
|
| 4542 |
ForwardIterator1 first, ForwardIterator1 last,
|
| 4543 |
ForwardIterator2 result, const T& value);
|
| 4544 |
|
| 4545 |
template<class InputIterator, class OutputIterator, class Predicate>
|
| 4546 |
+
constexpr OutputIterator
|
| 4547 |
remove_copy_if(InputIterator first, InputIterator last,
|
| 4548 |
OutputIterator result, Predicate pred);
|
| 4549 |
+
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 4550 |
+
class Predicate>
|
| 4551 |
ForwardIterator2
|
| 4552 |
remove_copy_if(ExecutionPolicy&& exec,
|
| 4553 |
ForwardIterator1 first, ForwardIterator1 last,
|
| 4554 |
ForwardIterator2 result, Predicate pred);
|
| 4555 |
+
|
| 4556 |
+
template<input_iterator I, sentinel_for<I> S, weakly_incrementable O, class T,
|
| 4557 |
+
class Proj = identity>
|
| 4558 |
+
requires indirectly_copyable<I, O> &&
|
| 4559 |
+
indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T*>
|
| 4560 |
+
constexpr ranges::remove_copy_result<I, O>
|
| 4561 |
+
ranges::remove_copy(I first, S last, O result, const T& value, Proj proj = {});
|
| 4562 |
+
template<input_range R, weakly_incrementable O, class T, class Proj = identity>
|
| 4563 |
+
requires indirectly_copyable<iterator_t<R>, O> &&
|
| 4564 |
+
indirect_binary_predicate<ranges::equal_to, projected<iterator_t<R>, Proj>, const T*>
|
| 4565 |
+
constexpr ranges::remove_copy_result<borrowed_iterator_t<R>, O>
|
| 4566 |
+
ranges::remove_copy(R&& r, O result, const T& value, Proj proj = {});
|
| 4567 |
+
template<input_iterator I, sentinel_for<I> S, weakly_incrementable O,
|
| 4568 |
+
class Proj = identity, indirect_unary_predicate<projected<I, Proj>> Pred>
|
| 4569 |
+
requires indirectly_copyable<I, O>
|
| 4570 |
+
constexpr ranges::remove_copy_if_result<I, O>
|
| 4571 |
+
ranges::remove_copy_if(I first, S last, O result, Pred pred, Proj proj = {});
|
| 4572 |
+
template<input_range R, weakly_incrementable O, class Proj = identity,
|
| 4573 |
+
indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
|
| 4574 |
+
requires indirectly_copyable<iterator_t<R>, O>
|
| 4575 |
+
constexpr ranges::remove_copy_if_result<borrowed_iterator_t<R>, O>
|
| 4576 |
+
ranges::remove_copy_if(R&& r, O result, Pred pred, Proj proj = {});
|
| 4577 |
```
|
| 4578 |
|
| 4579 |
+
Let E be
|
| 4580 |
+
|
| 4581 |
+
- `bool(*i == value)` for `remove_copy`;
|
| 4582 |
+
- `bool(pred(*i))` for `remove_copy_if`;
|
| 4583 |
+
- `bool(invoke(proj, *i) == value)` for `ranges::remove_copy`;
|
| 4584 |
+
- `bool(invoke(pred, invoke(proj, *i)))` for `ranges::remove_copy_if`.
|
| 4585 |
+
|
| 4586 |
+
Let N be the number of elements in \[`first`, `last`) for which E is
|
| 4587 |
+
`false`.
|
| 4588 |
+
|
| 4589 |
+
*Mandates:* `*first` is writable [[iterator.requirements.general]] to
|
| 4590 |
+
`result`.
|
| 4591 |
+
|
| 4592 |
+
*Preconditions:* The ranges \[`first`, `last`) and \[`result`,
|
| 4593 |
+
`result + (last - first)`) do not overlap.
|
| 4594 |
|
| 4595 |
[*Note 2*: For the overloads with an `ExecutionPolicy`, there may be a
|
| 4596 |
+
performance cost if `iterator_traits<ForwardIterator1>::value_type` does
|
| 4597 |
+
not meet the *Cpp17MoveConstructible* ([[cpp17.moveconstructible]])
|
| 4598 |
+
requirements. — *end note*]
|
| 4599 |
|
| 4600 |
*Effects:* Copies all the elements referred to by the iterator `i` in
|
| 4601 |
+
the range \[`first`, `last`) for which E is `false`.
|
|
|
|
| 4602 |
|
| 4603 |
+
*Returns:*
|
| 4604 |
+
|
| 4605 |
+
- `result + `N, for the algorithms in namespace `std`.
|
| 4606 |
+
- `{last, result + `N`}`, for the algorithms in namespace `ranges`.
|
| 4607 |
|
| 4608 |
*Complexity:* Exactly `last - first` applications of the corresponding
|
| 4609 |
+
predicate and any projection.
|
| 4610 |
|
| 4611 |
+
*Remarks:* Stable [[algorithm.stable]].
|
| 4612 |
|
| 4613 |
### Unique <a id="alg.unique">[[alg.unique]]</a>
|
| 4614 |
|
| 4615 |
``` cpp
|
| 4616 |
template<class ForwardIterator>
|
| 4617 |
+
constexpr ForwardIterator unique(ForwardIterator first, ForwardIterator last);
|
| 4618 |
template<class ExecutionPolicy, class ForwardIterator>
|
| 4619 |
ForwardIterator unique(ExecutionPolicy&& exec,
|
| 4620 |
ForwardIterator first, ForwardIterator last);
|
| 4621 |
|
| 4622 |
template<class ForwardIterator, class BinaryPredicate>
|
| 4623 |
+
constexpr ForwardIterator unique(ForwardIterator first, ForwardIterator last,
|
| 4624 |
BinaryPredicate pred);
|
| 4625 |
template<class ExecutionPolicy, class ForwardIterator, class BinaryPredicate>
|
| 4626 |
ForwardIterator unique(ExecutionPolicy&& exec,
|
| 4627 |
ForwardIterator first, ForwardIterator last,
|
| 4628 |
BinaryPredicate pred);
|
| 4629 |
+
|
| 4630 |
+
template<permutable I, sentinel_for<I> S, class Proj = identity,
|
| 4631 |
+
indirect_equivalence_relation<projected<I, Proj>> C = ranges::equal_to>
|
| 4632 |
+
constexpr subrange<I> ranges::unique(I first, S last, C comp = {}, Proj proj = {});
|
| 4633 |
+
template<forward_range R, class Proj = identity,
|
| 4634 |
+
indirect_equivalence_relation<projected<iterator_t<R>, Proj>> C = ranges::equal_to>
|
| 4635 |
+
requires permutable<iterator_t<R>>
|
| 4636 |
+
constexpr borrowed_subrange_t<R>
|
| 4637 |
+
ranges::unique(R&& r, C comp = {}, Proj proj = {});
|
| 4638 |
```
|
| 4639 |
|
| 4640 |
+
Let `pred` be `equal_to{}` for the overloads with no parameter `pred`,
|
| 4641 |
+
and let E be
|
| 4642 |
+
|
| 4643 |
+
- `bool(pred(*(i - 1), *i))` for the overloads in namespace `std`;
|
| 4644 |
+
- `bool(invoke(comp, invoke(proj, *(i - 1)), invoke(proj, *i)))` for the
|
| 4645 |
+
overloads in namespace `ranges`.
|
| 4646 |
+
|
| 4647 |
+
*Preconditions:* For the overloads in namepace `std`, `pred` is an
|
| 4648 |
+
equivalence relation and the type of `*first` meets the
|
| 4649 |
+
*Cpp17MoveAssignable* requirements ([[cpp17.moveassignable]]).
|
| 4650 |
|
| 4651 |
*Effects:* For a nonempty range, eliminates all but the first element
|
| 4652 |
from every consecutive group of equivalent elements referred to by the
|
| 4653 |
+
iterator `i` in the range \[`first + 1`, `last`) for which E is `true`.
|
|
|
|
| 4654 |
|
| 4655 |
+
*Returns:* Let j be the end of the resulting range. Returns:
|
| 4656 |
+
|
| 4657 |
+
- j for the overloads in namespace `std`.
|
| 4658 |
+
- `{`j`, last}` for the overloads in namespace `ranges`.
|
| 4659 |
|
| 4660 |
*Complexity:* For nonempty ranges, exactly `(last - first) - 1`
|
| 4661 |
+
applications of the corresponding predicate and no more than twice as
|
| 4662 |
+
many applications of any projection.
|
| 4663 |
|
| 4664 |
``` cpp
|
| 4665 |
template<class InputIterator, class OutputIterator>
|
| 4666 |
+
constexpr OutputIterator
|
| 4667 |
unique_copy(InputIterator first, InputIterator last,
|
| 4668 |
OutputIterator result);
|
| 4669 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 4670 |
ForwardIterator2
|
| 4671 |
unique_copy(ExecutionPolicy&& exec,
|
| 4672 |
ForwardIterator1 first, ForwardIterator1 last,
|
| 4673 |
ForwardIterator2 result);
|
| 4674 |
|
| 4675 |
template<class InputIterator, class OutputIterator,
|
| 4676 |
class BinaryPredicate>
|
| 4677 |
+
constexpr OutputIterator
|
| 4678 |
unique_copy(InputIterator first, InputIterator last,
|
| 4679 |
OutputIterator result, BinaryPredicate pred);
|
| 4680 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 4681 |
class BinaryPredicate>
|
| 4682 |
ForwardIterator2
|
| 4683 |
unique_copy(ExecutionPolicy&& exec,
|
| 4684 |
ForwardIterator1 first, ForwardIterator1 last,
|
| 4685 |
ForwardIterator2 result, BinaryPredicate pred);
|
| 4686 |
+
|
| 4687 |
+
template<input_iterator I, sentinel_for<I> S, weakly_incrementable O, class Proj = identity,
|
| 4688 |
+
indirect_equivalence_relation<projected<I, Proj>> C = ranges::equal_to>
|
| 4689 |
+
requires indirectly_copyable<I, O> &&
|
| 4690 |
+
(forward_iterator<I> ||
|
| 4691 |
+
(input_iterator<O> && same_as<iter_value_t<I>, iter_value_t<O>>) ||
|
| 4692 |
+
indirectly_copyable_storable<I, O>)
|
| 4693 |
+
constexpr ranges::unique_copy_result<I, O>
|
| 4694 |
+
ranges::unique_copy(I first, S last, O result, C comp = {}, Proj proj = {});
|
| 4695 |
+
template<input_range R, weakly_incrementable O, class Proj = identity,
|
| 4696 |
+
indirect_equivalence_relation<projected<iterator_t<R>, Proj>> C = ranges::equal_to>
|
| 4697 |
+
requires indirectly_copyable<iterator_t<R>, O> &&
|
| 4698 |
+
(forward_iterator<iterator_t<R>> ||
|
| 4699 |
+
(input_iterator<O> && same_as<range_value_t<R>, iter_value_t<O>>) ||
|
| 4700 |
+
indirectly_copyable_storable<iterator_t<R>, O>)
|
| 4701 |
+
constexpr ranges::unique_copy_result<borrowed_iterator_t<R>, O>
|
| 4702 |
+
ranges::unique_copy(R&& r, O result, C comp = {}, Proj proj = {});
|
| 4703 |
```
|
| 4704 |
|
| 4705 |
+
Let `pred` be `equal_to{}` for the overloads in namespace `std` with no
|
| 4706 |
+
parameter `pred`, and let E be
|
| 4707 |
+
|
| 4708 |
+
- `bool(pred(*i, *(i - 1)))` for the overloads in namespace `std`;
|
| 4709 |
+
- `bool(invoke(comp, invoke(proj, *i), invoke(proj, *(i - 1))))` for the
|
| 4710 |
+
overloads in namespace `ranges`.
|
| 4711 |
+
|
| 4712 |
+
*Mandates:* `*first` is writable [[iterator.requirements.general]] to
|
| 4713 |
+
`result`.
|
| 4714 |
+
|
| 4715 |
+
*Preconditions:*
|
| 4716 |
|
|
|
|
| 4717 |
- The ranges \[`first`, `last`) and \[`result`, `result+(last-first)`)
|
| 4718 |
+
do not overlap.
|
| 4719 |
+
- For the overloads in namespace `std`:
|
| 4720 |
+
- The comparison function is an equivalence relation.
|
| 4721 |
+
- For the overloads with no `ExecutionPolicy`, let `T` be the value
|
| 4722 |
+
type of `InputIterator`. If `InputIterator` meets the
|
| 4723 |
+
*Cpp17ForwardIterator* requirements, then there are no additional
|
| 4724 |
+
requirements for `T`. Otherwise, if `OutputIterator` meets the
|
| 4725 |
+
*Cpp17ForwardIterator* requirements and its value type is the same
|
| 4726 |
+
as `T`, then `T` meets the *Cpp17CopyAssignable*
|
| 4727 |
+
([[cpp17.copyassignable]]) requirements. Otherwise, `T` meets both
|
| 4728 |
+
the *Cpp17CopyConstructible* ([[cpp17.copyconstructible]]) and
|
| 4729 |
+
*Cpp17CopyAssignable* requirements. \[*Note 1*: For the overloads
|
| 4730 |
+
with an `ExecutionPolicy`, there may be a performance cost if the
|
| 4731 |
+
value type of `ForwardIterator1` does not meet both the
|
| 4732 |
+
*Cpp17CopyConstructible* and *Cpp17CopyAssignable*
|
| 4733 |
+
requirements. — *end note*]
|
| 4734 |
|
| 4735 |
*Effects:* Copies only the first element from every consecutive group of
|
| 4736 |
equal elements referred to by the iterator `i` in the range \[`first`,
|
| 4737 |
+
`last`) for which E holds.
|
|
|
|
| 4738 |
|
| 4739 |
+
*Returns:*
|
| 4740 |
|
| 4741 |
+
- `result + `N for the overloads in namespace `std`.
|
| 4742 |
+
- `{last, result + `N`}` for the overloads in namespace `ranges`.
|
| 4743 |
+
|
| 4744 |
+
*Complexity:* Exactly `last - first - 1` applications of the
|
| 4745 |
+
corresponding predicate and no more than twice as many applications of
|
| 4746 |
+
any projection.
|
| 4747 |
|
| 4748 |
### Reverse <a id="alg.reverse">[[alg.reverse]]</a>
|
| 4749 |
|
| 4750 |
``` cpp
|
| 4751 |
template<class BidirectionalIterator>
|
| 4752 |
+
constexpr void reverse(BidirectionalIterator first, BidirectionalIterator last);
|
| 4753 |
template<class ExecutionPolicy, class BidirectionalIterator>
|
| 4754 |
void reverse(ExecutionPolicy&& exec,
|
| 4755 |
BidirectionalIterator first, BidirectionalIterator last);
|
| 4756 |
+
|
| 4757 |
+
template<bidirectional_iterator I, sentinel_for<I> S>
|
| 4758 |
+
requires permutable<I>
|
| 4759 |
+
constexpr I ranges::reverse(I first, S last);
|
| 4760 |
+
template<bidirectional_range R>
|
| 4761 |
+
requires permutable<iterator_t<R>>
|
| 4762 |
+
constexpr borrowed_iterator_t<R> ranges::reverse(R&& r);
|
| 4763 |
```
|
| 4764 |
|
| 4765 |
+
*Preconditions:* For the overloads in namespace `std`,
|
| 4766 |
+
`BidirectionalIterator` meets the *Cpp17ValueSwappable*
|
| 4767 |
+
requirements [[swappable.requirements]].
|
| 4768 |
|
| 4769 |
*Effects:* For each non-negative integer `i < (last - first) / 2`,
|
| 4770 |
+
applies `std::iter_swap`, or `ranges::iter_swap` for the overloads in
|
| 4771 |
+
namespace `ranges`, to all pairs of iterators
|
| 4772 |
`first + i, (last - i) - 1`.
|
| 4773 |
|
| 4774 |
+
*Returns:* `last` for the overloads in namespace `ranges`.
|
|
|
|
| 4775 |
|
| 4776 |
*Complexity:* Exactly `(last - first)/2` swaps.
|
| 4777 |
|
| 4778 |
``` cpp
|
| 4779 |
template<class BidirectionalIterator, class OutputIterator>
|
| 4780 |
+
constexpr OutputIterator
|
| 4781 |
reverse_copy(BidirectionalIterator first, BidirectionalIterator last,
|
| 4782 |
OutputIterator result);
|
| 4783 |
template<class ExecutionPolicy, class BidirectionalIterator, class ForwardIterator>
|
| 4784 |
ForwardIterator
|
| 4785 |
reverse_copy(ExecutionPolicy&& exec,
|
| 4786 |
BidirectionalIterator first, BidirectionalIterator last,
|
| 4787 |
ForwardIterator result);
|
| 4788 |
+
|
| 4789 |
+
template<bidirectional_iterator I, sentinel_for<I> S, weakly_incrementable O>
|
| 4790 |
+
requires indirectly_copyable<I, O>
|
| 4791 |
+
constexpr ranges::reverse_copy_result<I, O>
|
| 4792 |
+
ranges::reverse_copy(I first, S last, O result);
|
| 4793 |
+
template<bidirectional_range R, weakly_incrementable O>
|
| 4794 |
+
requires indirectly_copyable<iterator_t<R>, O>
|
| 4795 |
+
constexpr ranges::reverse_copy_result<borrowed_iterator_t<R>, O>
|
| 4796 |
+
ranges::reverse_copy(R&& r, O result);
|
| 4797 |
```
|
| 4798 |
|
| 4799 |
+
Let N be `last - first`.
|
| 4800 |
+
|
| 4801 |
+
*Preconditions:* The ranges \[`first`, `last`) and \[`result`,
|
| 4802 |
+
`result + `N) do not overlap.
|
| 4803 |
|
| 4804 |
*Effects:* Copies the range \[`first`, `last`) to the range \[`result`,
|
| 4805 |
+
`result + `N) such that for every non-negative integer `i < `N the
|
| 4806 |
+
following assignment takes place:
|
| 4807 |
+
`*(result + `N` - 1 - i) = *(first + i)`.
|
| 4808 |
|
| 4809 |
+
*Returns:*
|
| 4810 |
|
| 4811 |
+
- `result + `N for the overloads in namespace `std`.
|
| 4812 |
+
- `{last, result + `N`}` for the overloads in namespace `ranges`.
|
| 4813 |
+
|
| 4814 |
+
*Complexity:* Exactly N assignments.
|
| 4815 |
|
| 4816 |
### Rotate <a id="alg.rotate">[[alg.rotate]]</a>
|
| 4817 |
|
| 4818 |
``` cpp
|
| 4819 |
template<class ForwardIterator>
|
| 4820 |
+
constexpr ForwardIterator
|
| 4821 |
rotate(ForwardIterator first, ForwardIterator middle, ForwardIterator last);
|
| 4822 |
template<class ExecutionPolicy, class ForwardIterator>
|
| 4823 |
ForwardIterator
|
| 4824 |
rotate(ExecutionPolicy&& exec,
|
| 4825 |
ForwardIterator first, ForwardIterator middle, ForwardIterator last);
|
| 4826 |
+
|
| 4827 |
+
template<permutable I, sentinel_for<I> S>
|
| 4828 |
+
constexpr subrange<I> ranges::rotate(I first, I middle, S last);
|
| 4829 |
```
|
| 4830 |
|
| 4831 |
+
*Preconditions:* \[`first`, `middle`) and \[`middle`, `last`) are valid
|
| 4832 |
+
ranges. For the overloads in namespace `std`, `ForwardIterator` meets
|
| 4833 |
+
the *Cpp17ValueSwappable* requirements [[swappable.requirements]], and
|
| 4834 |
+
the type of `*first` meets the *Cpp17MoveConstructible*
|
| 4835 |
+
([[cpp17.moveconstructible]]) and *Cpp17MoveAssignable*
|
| 4836 |
+
([[cpp17.moveassignable]]) requirements.
|
| 4837 |
|
| 4838 |
*Effects:* For each non-negative integer `i < (last - first)`, places
|
| 4839 |
the element from the position `first + i` into position
|
| 4840 |
`first + (i + (last - middle)) % (last - first)`.
|
| 4841 |
|
| 4842 |
+
[*Note 1*: This is a left rotate. — *end note*]
|
| 4843 |
|
| 4844 |
+
*Returns:*
|
| 4845 |
+
|
| 4846 |
+
- `first + (last - middle)` for the overloads in namespace `std`.
|
| 4847 |
+
- `{first + (last - middle), last}` for the overload in namespace
|
| 4848 |
+
`ranges`.
|
| 4849 |
|
| 4850 |
*Complexity:* At most `last - first` swaps.
|
| 4851 |
|
| 4852 |
+
``` cpp
|
| 4853 |
+
template<forward_range R>
|
| 4854 |
+
requires permutable<iterator_t<R>>
|
| 4855 |
+
constexpr borrowed_subrange_t<R> ranges::rotate(R&& r, iterator_t<R> middle);
|
| 4856 |
+
```
|
| 4857 |
+
|
| 4858 |
+
*Effects:* Equivalent to:
|
| 4859 |
+
`return ranges::rotate(ranges::begin(r), middle, ranges::end(r));`
|
| 4860 |
+
|
| 4861 |
``` cpp
|
| 4862 |
template<class ForwardIterator, class OutputIterator>
|
| 4863 |
+
constexpr OutputIterator
|
| 4864 |
rotate_copy(ForwardIterator first, ForwardIterator middle, ForwardIterator last,
|
| 4865 |
OutputIterator result);
|
| 4866 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 4867 |
ForwardIterator2
|
| 4868 |
rotate_copy(ExecutionPolicy&& exec,
|
| 4869 |
ForwardIterator1 first, ForwardIterator1 middle, ForwardIterator1 last,
|
| 4870 |
ForwardIterator2 result);
|
| 4871 |
+
|
| 4872 |
+
template<forward_iterator I, sentinel_for<I> S, weakly_incrementable O>
|
| 4873 |
+
requires indirectly_copyable<I, O>
|
| 4874 |
+
constexpr ranges::rotate_copy_result<I, O>
|
| 4875 |
+
ranges::rotate_copy(I first, I middle, S last, O result);
|
| 4876 |
```
|
| 4877 |
|
| 4878 |
+
Let N be `last - first`.
|
| 4879 |
+
|
| 4880 |
+
*Preconditions:* \[`first`, `middle`) and \[`middle`, `last`) are valid
|
| 4881 |
+
ranges. The ranges \[`first`, `last`) and \[`result`, `result + `N) do
|
| 4882 |
+
not overlap.
|
| 4883 |
|
| 4884 |
*Effects:* Copies the range \[`first`, `last`) to the range \[`result`,
|
| 4885 |
+
`result + `N) such that for each non-negative integer i < N the
|
| 4886 |
+
following assignment takes place:
|
| 4887 |
+
`*(result + `i`) = *(first + (`i` + (middle - first)) % `N`)`.
|
| 4888 |
|
| 4889 |
+
*Returns:*
|
| 4890 |
|
| 4891 |
+
- `result + `N for the overloads in namespace `std`.
|
| 4892 |
+
- `{last, result + `N`}` for the overload in namespace `ranges`.
|
| 4893 |
+
|
| 4894 |
+
*Complexity:* Exactly N assignments.
|
| 4895 |
+
|
| 4896 |
+
``` cpp
|
| 4897 |
+
template<forward_range R, weakly_incrementable O>
|
| 4898 |
+
requires indirectly_copyable<iterator_t<R>, O>
|
| 4899 |
+
constexpr ranges::rotate_copy_result<borrowed_iterator_t<R>, O>
|
| 4900 |
+
ranges::rotate_copy(R&& r, iterator_t<R> middle, O result);
|
| 4901 |
+
```
|
| 4902 |
+
|
| 4903 |
+
*Effects:* Equivalent to:
|
| 4904 |
+
|
| 4905 |
+
``` cpp
|
| 4906 |
+
return ranges::rotate_copy(ranges::begin(r), middle, ranges::end(r), result);
|
| 4907 |
+
```
|
| 4908 |
|
| 4909 |
### Sample <a id="alg.random.sample">[[alg.random.sample]]</a>
|
| 4910 |
|
| 4911 |
``` cpp
|
| 4912 |
template<class PopulationIterator, class SampleIterator,
|
| 4913 |
class Distance, class UniformRandomBitGenerator>
|
| 4914 |
SampleIterator sample(PopulationIterator first, PopulationIterator last,
|
| 4915 |
SampleIterator out, Distance n,
|
| 4916 |
UniformRandomBitGenerator&& g);
|
| 4917 |
+
|
| 4918 |
+
template<input_iterator I, sentinel_for<I> S, weakly_incrementable O, class Gen>
|
| 4919 |
+
requires (forward_iterator<I> || random_access_iterator<O>) &&
|
| 4920 |
+
indirectly_copyable<I, O> &&
|
| 4921 |
+
uniform_random_bit_generator<remove_reference_t<Gen>>
|
| 4922 |
+
O ranges::sample(I first, S last, O out, iter_difference_t<I> n, Gen&& g);
|
| 4923 |
+
template<input_range R, weakly_incrementable O, class Gen>
|
| 4924 |
+
requires (forward_range<R> || random_access_iterator<O>) &&
|
| 4925 |
+
indirectly_copyable<iterator_t<R>, O> &&
|
| 4926 |
+
uniform_random_bit_generator<remove_reference_t<Gen>>
|
| 4927 |
+
O ranges::sample(R&& r, O out, range_difference_t<R> n, Gen&& g);
|
| 4928 |
```
|
| 4929 |
|
| 4930 |
+
*Mandates:* For the overload in namespace `std`, `Distance` is an
|
| 4931 |
+
integer type and `*first` is writable [[iterator.requirements.general]]
|
| 4932 |
+
to `out`.
|
| 4933 |
|
| 4934 |
+
*Preconditions:* `out` is not in the range \[`first`, `last`). For the
|
| 4935 |
+
overload in namespace `std`:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4936 |
|
| 4937 |
+
- `PopulationIterator` meets the *Cpp17InputIterator*
|
| 4938 |
+
requirements [[input.iterators]].
|
| 4939 |
+
- `SampleIterator` meets the *Cpp17OutputIterator*
|
| 4940 |
+
requirements [[output.iterators]].
|
| 4941 |
+
- `SampleIterator` meets the *Cpp17RandomAccessIterator*
|
| 4942 |
+
requirements [[random.access.iterators]] unless `PopulationIterator`
|
| 4943 |
+
meets the *Cpp17ForwardIterator* requirements [[forward.iterators]].
|
| 4944 |
+
- `remove_reference_t<UniformRandomBitGenerator>` meets the requirements
|
| 4945 |
+
of a uniform random bit generator type [[rand.req.urng]].
|
| 4946 |
+
|
| 4947 |
+
*Effects:* Copies min(`last - first`, `n`) elements (the *sample*) from
|
| 4948 |
\[`first`, `last`) (the *population*) to `out` such that each possible
|
| 4949 |
sample has equal probability of appearance.
|
| 4950 |
|
| 4951 |
[*Note 1*: Algorithms that obtain such effects include *selection
|
| 4952 |
sampling* and *reservoir sampling*. — *end note*]
|
|
|
|
| 4955 |
|
| 4956 |
*Complexity:* 𝑂(`last - first`).
|
| 4957 |
|
| 4958 |
*Remarks:*
|
| 4959 |
|
| 4960 |
+
- For the overload in namespace `std`, stable if and only if
|
| 4961 |
+
`PopulationIterator` meets the *Cpp17ForwardIterator* requirements.
|
| 4962 |
+
For the first overload in namespace `ranges`, stable if and only if
|
| 4963 |
+
`I` models `forward_iterator`.
|
| 4964 |
- To the extent that the implementation of this function makes use of
|
| 4965 |
+
random numbers, the object `g` serves as the implementation’s source
|
| 4966 |
+
of randomness.
|
| 4967 |
|
| 4968 |
### Shuffle <a id="alg.random.shuffle">[[alg.random.shuffle]]</a>
|
| 4969 |
|
| 4970 |
``` cpp
|
| 4971 |
template<class RandomAccessIterator, class UniformRandomBitGenerator>
|
| 4972 |
void shuffle(RandomAccessIterator first,
|
| 4973 |
RandomAccessIterator last,
|
| 4974 |
UniformRandomBitGenerator&& g);
|
| 4975 |
+
|
| 4976 |
+
template<random_access_iterator I, sentinel_for<I> S, class Gen>
|
| 4977 |
+
requires permutable<I> &&
|
| 4978 |
+
uniform_random_bit_generator<remove_reference_t<Gen>>
|
| 4979 |
+
I ranges::shuffle(I first, S last, Gen&& g);
|
| 4980 |
+
template<random_access_range R, class Gen>
|
| 4981 |
+
requires permutable<iterator_t<R>> &&
|
| 4982 |
+
uniform_random_bit_generator<remove_reference_t<Gen>>
|
| 4983 |
+
borrowed_iterator_t<R> ranges::shuffle(R&& r, Gen&& g);
|
| 4984 |
```
|
| 4985 |
|
| 4986 |
+
*Preconditions:* For the overload in namespace `std`:
|
| 4987 |
+
|
| 4988 |
+
- `RandomAccessIterator` meets the *Cpp17ValueSwappable*
|
| 4989 |
+
requirements [[swappable.requirements]].
|
| 4990 |
+
- The type `remove_reference_t<UniformRandomBitGenerator>` meets the
|
| 4991 |
+
uniform random bit generator [[rand.req.urng]] requirements.
|
| 4992 |
|
| 4993 |
*Effects:* Permutes the elements in the range \[`first`, `last`) such
|
| 4994 |
that each possible permutation of those elements has equal probability
|
| 4995 |
of appearance.
|
| 4996 |
|
| 4997 |
+
*Returns:* `last` for the overloads in namespace `ranges`.
|
| 4998 |
+
|
| 4999 |
*Complexity:* Exactly `(last - first) - 1` swaps.
|
| 5000 |
|
| 5001 |
*Remarks:* To the extent that the implementation of this function makes
|
| 5002 |
+
use of random numbers, the object referenced by `g` shall serve as the
|
| 5003 |
implementation’s source of randomness.
|
| 5004 |
|
| 5005 |
+
### Shift <a id="alg.shift">[[alg.shift]]</a>
|
| 5006 |
+
|
| 5007 |
+
``` cpp
|
| 5008 |
+
template<class ForwardIterator>
|
| 5009 |
+
constexpr ForwardIterator
|
| 5010 |
+
shift_left(ForwardIterator first, ForwardIterator last,
|
| 5011 |
+
typename iterator_traits<ForwardIterator>::difference_type n);
|
| 5012 |
+
template<class ExecutionPolicy, class ForwardIterator>
|
| 5013 |
+
ForwardIterator
|
| 5014 |
+
shift_left(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last,
|
| 5015 |
+
typename iterator_traits<ForwardIterator>::difference_type n);
|
| 5016 |
+
```
|
| 5017 |
+
|
| 5018 |
+
*Preconditions:* `n >= 0` is `true`. The type of `*first` meets the
|
| 5019 |
+
*Cpp17MoveAssignable* requirements.
|
| 5020 |
+
|
| 5021 |
+
*Effects:* If `n == 0` or `n >= last - first`, does nothing. Otherwise,
|
| 5022 |
+
moves the element from position `first + n + i` into position
|
| 5023 |
+
`first + i` for each non-negative integer `i < (last - first) - n`. In
|
| 5024 |
+
the first overload case, does so in order starting from `i = 0` and
|
| 5025 |
+
proceeding to `i = (last - first) - n - 1`.
|
| 5026 |
+
|
| 5027 |
+
*Returns:* `first + (last - first - n)` if `n < last - first`, otherwise
|
| 5028 |
+
`first`.
|
| 5029 |
+
|
| 5030 |
+
*Complexity:* At most `(last - first) - n` assignments.
|
| 5031 |
+
|
| 5032 |
+
``` cpp
|
| 5033 |
+
template<class ForwardIterator>
|
| 5034 |
+
constexpr ForwardIterator
|
| 5035 |
+
shift_right(ForwardIterator first, ForwardIterator last,
|
| 5036 |
+
typename iterator_traits<ForwardIterator>::difference_type n);
|
| 5037 |
+
template<class ExecutionPolicy, class ForwardIterator>
|
| 5038 |
+
ForwardIterator
|
| 5039 |
+
shift_right(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last,
|
| 5040 |
+
typename iterator_traits<ForwardIterator>::difference_type n);
|
| 5041 |
+
```
|
| 5042 |
+
|
| 5043 |
+
*Preconditions:* `n >= 0` is `true`. The type of `*first` meets the
|
| 5044 |
+
*Cpp17MoveAssignable* requirements. `ForwardIterator` meets the
|
| 5045 |
+
*Cpp17BidirectionalIterator* requirements [[bidirectional.iterators]] or
|
| 5046 |
+
the *Cpp17ValueSwappable* requirements.
|
| 5047 |
+
|
| 5048 |
+
*Effects:* If `n == 0` or `n >= last - first`, does nothing. Otherwise,
|
| 5049 |
+
moves the element from position `first + i` into position
|
| 5050 |
+
`first + n + i` for each non-negative integer `i < (last - first) - n`.
|
| 5051 |
+
In the first overload case, if `ForwardIterator` meets the
|
| 5052 |
+
*Cpp17BidirectionalIterator* requirements, does so in order starting
|
| 5053 |
+
from `i = (last - first) - n - 1` and proceeding to `i = 0`.
|
| 5054 |
+
|
| 5055 |
+
*Returns:* `first + n` if `n < last - first`, otherwise `last`.
|
| 5056 |
+
|
| 5057 |
+
*Complexity:* At most `(last - first) - n` assignments or swaps.
|
| 5058 |
+
|
| 5059 |
## Sorting and related operations <a id="alg.sorting">[[alg.sorting]]</a>
|
| 5060 |
|
| 5061 |
+
The operations in [[alg.sorting]] defined directly in namespace `std`
|
| 5062 |
+
have two versions: one that takes a function object of type `Compare`
|
| 5063 |
+
and one that uses an `operator<`.
|
| 5064 |
|
| 5065 |
+
`Compare` is a function object type [[function.objects]] that meets the
|
| 5066 |
+
requirements for a template parameter named `BinaryPredicate`
|
| 5067 |
+
[[algorithms.requirements]]. The return value of the function call
|
| 5068 |
+
operation applied to an object of type `Compare`, when contextually
|
| 5069 |
+
converted to `bool` [[conv]], yields `true` if the first argument of the
|
| 5070 |
+
call is less than the second, and `false` otherwise. `Compare comp` is
|
| 5071 |
+
used throughout for algorithms assuming an ordering relation.
|
|
|
|
|
|
|
| 5072 |
|
| 5073 |
For all algorithms that take `Compare`, there is a version that uses
|
| 5074 |
`operator<` instead. That is, `comp(*i, *j) != false` defaults to
|
| 5075 |
`*i < *j != false`. For algorithms other than those described in
|
| 5076 |
[[alg.binary.search]], `comp` shall induce a strict weak ordering on the
|
|
|
|
| 5088 |
|
| 5089 |
[*Note 1*:
|
| 5090 |
|
| 5091 |
Under these conditions, it can be shown that
|
| 5092 |
|
| 5093 |
+
- `equiv` is an equivalence relation,
|
| 5094 |
- `comp` induces a well-defined relation on the equivalence classes
|
| 5095 |
+
determined by `equiv`, and
|
| 5096 |
+
- the induced relation is a strict total ordering.
|
| 5097 |
|
| 5098 |
— *end note*]
|
| 5099 |
|
| 5100 |
+
A sequence is *sorted with respect to a `comp` and `proj`* for a
|
| 5101 |
+
comparator and projection `comp` and `proj` if for every iterator `i`
|
| 5102 |
+
pointing to the sequence and every non-negative integer `n` such that
|
| 5103 |
+
`i + n` is a valid iterator pointing to an element of the sequence,
|
| 5104 |
+
|
| 5105 |
+
``` cpp
|
| 5106 |
+
bool(invoke(comp, invoke(proj, *(i + n)), invoke(proj, *i)))
|
| 5107 |
+
```
|
| 5108 |
+
|
| 5109 |
+
is `false`.
|
| 5110 |
|
| 5111 |
A sequence \[`start`, `finish`) is *partitioned with respect to an
|
| 5112 |
expression* `f(e)` if there exists an integer `n` such that for all
|
| 5113 |
`0 <= i < (finish - start)`, `f(*(start + i))` is `true` if and only if
|
| 5114 |
`i < n`.
|
|
|
|
| 5124 |
|
| 5125 |
#### `sort` <a id="sort">[[sort]]</a>
|
| 5126 |
|
| 5127 |
``` cpp
|
| 5128 |
template<class RandomAccessIterator>
|
| 5129 |
+
constexpr void sort(RandomAccessIterator first, RandomAccessIterator last);
|
| 5130 |
template<class ExecutionPolicy, class RandomAccessIterator>
|
| 5131 |
void sort(ExecutionPolicy&& exec,
|
| 5132 |
RandomAccessIterator first, RandomAccessIterator last);
|
| 5133 |
|
| 5134 |
template<class RandomAccessIterator, class Compare>
|
| 5135 |
+
constexpr void sort(RandomAccessIterator first, RandomAccessIterator last,
|
| 5136 |
Compare comp);
|
| 5137 |
template<class ExecutionPolicy, class RandomAccessIterator, class Compare>
|
| 5138 |
void sort(ExecutionPolicy&& exec,
|
| 5139 |
RandomAccessIterator first, RandomAccessIterator last,
|
| 5140 |
Compare comp);
|
| 5141 |
+
|
| 5142 |
+
template<random_access_iterator I, sentinel_for<I> S, class Comp = ranges::less,
|
| 5143 |
+
class Proj = identity>
|
| 5144 |
+
requires sortable<I, Comp, Proj>
|
| 5145 |
+
constexpr I
|
| 5146 |
+
ranges::sort(I first, S last, Comp comp = {}, Proj proj = {});
|
| 5147 |
+
template<random_access_range R, class Comp = ranges::less, class Proj = identity>
|
| 5148 |
+
requires sortable<iterator_t<R>, Comp, Proj>
|
| 5149 |
+
constexpr borrowed_iterator_t<R>
|
| 5150 |
+
ranges::sort(R&& r, Comp comp = {}, Proj proj = {});
|
| 5151 |
```
|
| 5152 |
|
| 5153 |
+
Let `comp` be `less{}` and `proj` be `identity{}` for the overloads with
|
| 5154 |
+
no parameters by those names.
|
|
|
|
|
|
|
|
|
|
| 5155 |
|
| 5156 |
+
*Preconditions:* For the overloads in namespace `std`,
|
| 5157 |
+
`RandomAccessIterator` meets the *Cpp17ValueSwappable*
|
| 5158 |
+
requirements [[swappable.requirements]] and the type of `*first` meets
|
| 5159 |
+
the *Cpp17MoveConstructible* ([[cpp17.moveconstructible]]) and
|
| 5160 |
+
*Cpp17MoveAssignable* ([[cpp17.moveassignable]]) requirements.
|
| 5161 |
|
| 5162 |
+
*Effects:* Sorts the elements in the range \[`first`, `last`) with
|
| 5163 |
+
respect to `comp` and `proj`.
|
| 5164 |
+
|
| 5165 |
+
*Returns:* `last` for the overloads in namespace `ranges`.
|
| 5166 |
+
|
| 5167 |
+
*Complexity:* Let N be `last - first`. 𝑂(N log N) comparisons and
|
| 5168 |
+
projections.
|
| 5169 |
|
| 5170 |
#### `stable_sort` <a id="stable.sort">[[stable.sort]]</a>
|
| 5171 |
|
| 5172 |
``` cpp
|
| 5173 |
template<class RandomAccessIterator>
|
|
|
|
| 5181 |
Compare comp);
|
| 5182 |
template<class ExecutionPolicy, class RandomAccessIterator, class Compare>
|
| 5183 |
void stable_sort(ExecutionPolicy&& exec,
|
| 5184 |
RandomAccessIterator first, RandomAccessIterator last,
|
| 5185 |
Compare comp);
|
| 5186 |
+
|
| 5187 |
+
template<random_access_iterator I, sentinel_for<I> S, class Comp = ranges::less,
|
| 5188 |
+
class Proj = identity>
|
| 5189 |
+
requires sortable<I, Comp, Proj>
|
| 5190 |
+
I ranges::stable_sort(I first, S last, Comp comp = {}, Proj proj = {});
|
| 5191 |
+
template<random_access_range R, class Comp = ranges::less, class Proj = identity>
|
| 5192 |
+
requires sortable<iterator_t<R>, Comp, Proj>
|
| 5193 |
+
borrowed_iterator_t<R>
|
| 5194 |
+
ranges::stable_sort(R&& r, Comp comp = {}, Proj proj = {});
|
| 5195 |
```
|
| 5196 |
|
| 5197 |
+
Let `comp` be `less{}` and `proj` be `identity{}` for the overloads with
|
| 5198 |
+
no parameters by those names.
|
|
|
|
|
|
|
|
|
|
| 5199 |
|
| 5200 |
+
*Preconditions:* For the overloads in namespace `std`,
|
| 5201 |
+
`RandomAccessIterator` meets the *Cpp17ValueSwappable*
|
| 5202 |
+
requirements [[swappable.requirements]] and the type of `*first` meets
|
| 5203 |
+
the *Cpp17MoveConstructible* ([[cpp17.moveconstructible]]) and
|
| 5204 |
+
*Cpp17MoveAssignable* ([[cpp17.moveassignable]]) requirements.
|
| 5205 |
|
| 5206 |
+
*Effects:* Sorts the elements in the range \[`first`, `last`) with
|
| 5207 |
+
respect to `comp` and `proj`.
|
| 5208 |
|
| 5209 |
+
*Returns:* `last` for the overloads in namespace `ranges`.
|
| 5210 |
+
|
| 5211 |
+
*Complexity:* Let N be `last - first`. If enough extra memory is
|
| 5212 |
+
available, N log(N) comparisons. Otherwise, at most N log²(N)
|
| 5213 |
+
comparisons. In either case, twice as many projections as the number of
|
| 5214 |
+
comparisons.
|
| 5215 |
+
|
| 5216 |
+
*Remarks:* Stable [[algorithm.stable]].
|
| 5217 |
|
| 5218 |
#### `partial_sort` <a id="partial.sort">[[partial.sort]]</a>
|
| 5219 |
|
| 5220 |
``` cpp
|
| 5221 |
template<class RandomAccessIterator>
|
| 5222 |
+
constexpr void partial_sort(RandomAccessIterator first,
|
| 5223 |
RandomAccessIterator middle,
|
| 5224 |
RandomAccessIterator last);
|
| 5225 |
template<class ExecutionPolicy, class RandomAccessIterator>
|
| 5226 |
void partial_sort(ExecutionPolicy&& exec,
|
| 5227 |
RandomAccessIterator first,
|
| 5228 |
RandomAccessIterator middle,
|
| 5229 |
RandomAccessIterator last);
|
| 5230 |
|
| 5231 |
template<class RandomAccessIterator, class Compare>
|
| 5232 |
+
constexpr void partial_sort(RandomAccessIterator first,
|
| 5233 |
RandomAccessIterator middle,
|
| 5234 |
RandomAccessIterator last,
|
| 5235 |
Compare comp);
|
| 5236 |
template<class ExecutionPolicy, class RandomAccessIterator, class Compare>
|
| 5237 |
void partial_sort(ExecutionPolicy&& exec,
|
| 5238 |
RandomAccessIterator first,
|
| 5239 |
RandomAccessIterator middle,
|
| 5240 |
RandomAccessIterator last,
|
| 5241 |
Compare comp);
|
| 5242 |
+
|
| 5243 |
+
template<random_access_iterator I, sentinel_for<I> S, class Comp = ranges::less,
|
| 5244 |
+
class Proj = identity>
|
| 5245 |
+
requires sortable<I, Comp, Proj>
|
| 5246 |
+
constexpr I
|
| 5247 |
+
ranges::partial_sort(I first, I middle, S last, Comp comp = {}, Proj proj = {});
|
| 5248 |
```
|
| 5249 |
|
| 5250 |
+
Let `comp` be `less{}` and `proj` be `identity{}` for the overloads with
|
| 5251 |
+
no parameters by those names.
|
|
|
|
|
|
|
|
|
|
| 5252 |
|
| 5253 |
+
*Preconditions:* \[`first`, `middle`) and \[`middle`, `last`) are valid
|
| 5254 |
+
ranges. For the overloads in namespace `std`, `RandomAccessIterator`
|
| 5255 |
+
meets the *Cpp17ValueSwappable* requirements [[swappable.requirements]]
|
| 5256 |
+
and the type of `*first` meets the *Cpp17MoveConstructible*
|
| 5257 |
+
([[cpp17.moveconstructible]]) and *Cpp17MoveAssignable*
|
| 5258 |
+
([[cpp17.moveassignable]]) requirements.
|
| 5259 |
+
|
| 5260 |
+
*Effects:* Places the first `middle - first` elements from the range
|
| 5261 |
+
\[`first`, `last`) as sorted with respect to `comp` and `proj` into the
|
| 5262 |
+
range \[`first`, `middle`). The rest of the elements in the range
|
| 5263 |
+
\[`middle`, `last`) are placed in an unspecified order.
|
| 5264 |
+
|
| 5265 |
+
*Returns:* `last` for the overload in namespace `ranges`.
|
| 5266 |
|
| 5267 |
*Complexity:* Approximately `(last - first) * log(middle - first)`
|
| 5268 |
+
comparisons, and twice as many projections.
|
| 5269 |
+
|
| 5270 |
+
``` cpp
|
| 5271 |
+
template<random_access_range R, class Comp = ranges::less, class Proj = identity>
|
| 5272 |
+
requires sortable<iterator_t<R>, Comp, Proj>
|
| 5273 |
+
constexpr borrowed_iterator_t<R>
|
| 5274 |
+
ranges::partial_sort(R&& r, iterator_t<R> middle, Comp comp = {}, Proj proj = {});
|
| 5275 |
+
```
|
| 5276 |
+
|
| 5277 |
+
*Effects:* Equivalent to:
|
| 5278 |
+
|
| 5279 |
+
``` cpp
|
| 5280 |
+
return ranges::partial_sort(ranges::begin(r), middle, ranges::end(r), comp, proj);
|
| 5281 |
+
```
|
| 5282 |
|
| 5283 |
#### `partial_sort_copy` <a id="partial.sort.copy">[[partial.sort.copy]]</a>
|
| 5284 |
|
| 5285 |
``` cpp
|
| 5286 |
template<class InputIterator, class RandomAccessIterator>
|
| 5287 |
+
constexpr RandomAccessIterator
|
| 5288 |
partial_sort_copy(InputIterator first, InputIterator last,
|
| 5289 |
RandomAccessIterator result_first,
|
| 5290 |
RandomAccessIterator result_last);
|
| 5291 |
template<class ExecutionPolicy, class ForwardIterator, class RandomAccessIterator>
|
| 5292 |
RandomAccessIterator
|
|
|
|
| 5295 |
RandomAccessIterator result_first,
|
| 5296 |
RandomAccessIterator result_last);
|
| 5297 |
|
| 5298 |
template<class InputIterator, class RandomAccessIterator,
|
| 5299 |
class Compare>
|
| 5300 |
+
constexpr RandomAccessIterator
|
| 5301 |
partial_sort_copy(InputIterator first, InputIterator last,
|
| 5302 |
RandomAccessIterator result_first,
|
| 5303 |
RandomAccessIterator result_last,
|
| 5304 |
Compare comp);
|
| 5305 |
template<class ExecutionPolicy, class ForwardIterator, class RandomAccessIterator,
|
|
|
|
| 5308 |
partial_sort_copy(ExecutionPolicy&& exec,
|
| 5309 |
ForwardIterator first, ForwardIterator last,
|
| 5310 |
RandomAccessIterator result_first,
|
| 5311 |
RandomAccessIterator result_last,
|
| 5312 |
Compare comp);
|
| 5313 |
+
|
| 5314 |
+
template<input_iterator I1, sentinel_for<I1> S1, random_access_iterator I2, sentinel_for<I2> S2,
|
| 5315 |
+
class Comp = ranges::less, class Proj1 = identity, class Proj2 = identity>
|
| 5316 |
+
requires indirectly_copyable<I1, I2> && sortable<I2, Comp, Proj2> &&
|
| 5317 |
+
indirect_strict_weak_order<Comp, projected<I1, Proj1>, projected<I2, Proj2>>
|
| 5318 |
+
constexpr ranges::partial_sort_copy_result<I1, I2>
|
| 5319 |
+
ranges::partial_sort_copy(I1 first, S1 last, I2 result_first, S2 result_last,
|
| 5320 |
+
Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 5321 |
+
template<input_range R1, random_access_range R2, class Comp = ranges::less,
|
| 5322 |
+
class Proj1 = identity, class Proj2 = identity>
|
| 5323 |
+
requires indirectly_copyable<iterator_t<R1>, iterator_t<R2>> &&
|
| 5324 |
+
sortable<iterator_t<R2>, Comp, Proj2> &&
|
| 5325 |
+
indirect_strict_weak_order<Comp, projected<iterator_t<R1>, Proj1>,
|
| 5326 |
+
projected<iterator_t<R2>, Proj2>>
|
| 5327 |
+
constexpr ranges::partial_sort_copy_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>>
|
| 5328 |
+
ranges::partial_sort_copy(R1&& r, R2&& result_r, Comp comp = {},
|
| 5329 |
+
Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 5330 |
```
|
| 5331 |
|
| 5332 |
+
Let N be min(`last - first`, `result_last - result_first`). Let `comp`
|
| 5333 |
+
be `less{}`, and `proj1` and `proj2` be `identity{}` for the overloads
|
| 5334 |
+
with no parameters by those names.
|
| 5335 |
+
|
| 5336 |
+
*Mandates:* For the overloads in namespace `std`, the expression
|
| 5337 |
+
`*first` is writable [[iterator.requirements.general]] to
|
| 5338 |
+
`result_first`.
|
| 5339 |
+
|
| 5340 |
+
*Preconditions:* For the overloads in namespace `std`,
|
| 5341 |
+
`RandomAccessIterator` meets the *Cpp17ValueSwappable*
|
| 5342 |
+
requirements [[swappable.requirements]], the type of `*result_first`
|
| 5343 |
+
meets the *Cpp17MoveConstructible* ([[cpp17.moveconstructible]]) and
|
| 5344 |
+
*Cpp17MoveAssignable* ([[cpp17.moveassignable]]) requirements.
|
| 5345 |
+
|
| 5346 |
+
*Preconditions:* For iterators `a1` and `b1` in \[`first`, `last`), and
|
| 5347 |
+
iterators `x2` and `y2` in \[`result_first`, `result_last`), after
|
| 5348 |
+
evaluating the assignment `*y2 = *b1`, let E be the value of
|
| 5349 |
+
|
| 5350 |
+
``` cpp
|
| 5351 |
+
bool(invoke(comp, invoke(proj1, *a1), invoke(proj2, *y2))).
|
| 5352 |
+
```
|
| 5353 |
+
|
| 5354 |
+
Then, after evaluating the assignment `*x2 = *a1`, E is equal to
|
| 5355 |
+
|
| 5356 |
+
``` cpp
|
| 5357 |
+
bool(invoke(comp, invoke(proj2, *x2), invoke(proj2, *y2))).
|
| 5358 |
+
```
|
| 5359 |
+
|
| 5360 |
+
[*Note 1*: Writing a value from the input range into the output range
|
| 5361 |
+
does not affect how it is ordered by `comp` and `proj1` or
|
| 5362 |
+
`proj2`. — *end note*]
|
| 5363 |
+
|
| 5364 |
+
*Effects:* Places the first N elements as sorted with respect to `comp`
|
| 5365 |
+
and `proj2` into the range \[`result_first`, `result_first + `N).
|
| 5366 |
|
| 5367 |
+
*Returns:*
|
|
|
|
|
|
|
|
|
|
| 5368 |
|
| 5369 |
+
- `result_first + `N for the overloads in namespace `std`.
|
| 5370 |
+
- `{last, result_first + `N`}` for the overloads in namespace `ranges`.
|
| 5371 |
|
| 5372 |
+
*Complexity:* Approximately `(last - first) * log `N comparisons, and
|
| 5373 |
+
twice as many projections.
|
|
|
|
| 5374 |
|
| 5375 |
#### `is_sorted` <a id="is.sorted">[[is.sorted]]</a>
|
| 5376 |
|
| 5377 |
``` cpp
|
| 5378 |
template<class ForwardIterator>
|
| 5379 |
+
constexpr bool is_sorted(ForwardIterator first, ForwardIterator last);
|
| 5380 |
```
|
| 5381 |
|
| 5382 |
+
*Effects:* Equivalent to: `return is_sorted_until(first, last) == last;`
|
| 5383 |
|
| 5384 |
``` cpp
|
| 5385 |
template<class ExecutionPolicy, class ForwardIterator>
|
| 5386 |
bool is_sorted(ExecutionPolicy&& exec,
|
| 5387 |
ForwardIterator first, ForwardIterator last);
|
| 5388 |
```
|
| 5389 |
|
| 5390 |
+
*Effects:* Equivalent to:
|
| 5391 |
+
|
| 5392 |
+
``` cpp
|
| 5393 |
+
return is_sorted_until(std::forward<ExecutionPolicy>(exec), first, last) == last;
|
| 5394 |
+
```
|
| 5395 |
|
| 5396 |
``` cpp
|
| 5397 |
template<class ForwardIterator, class Compare>
|
| 5398 |
+
constexpr bool is_sorted(ForwardIterator first, ForwardIterator last,
|
| 5399 |
Compare comp);
|
| 5400 |
```
|
| 5401 |
|
| 5402 |
+
*Effects:* Equivalent to:
|
| 5403 |
+
`return is_sorted_until(first, last, comp) == last;`
|
| 5404 |
|
| 5405 |
``` cpp
|
| 5406 |
template<class ExecutionPolicy, class ForwardIterator, class Compare>
|
| 5407 |
bool is_sorted(ExecutionPolicy&& exec,
|
| 5408 |
ForwardIterator first, ForwardIterator last,
|
| 5409 |
Compare comp);
|
| 5410 |
```
|
| 5411 |
|
| 5412 |
+
*Effects:* Equivalent to:
|
| 5413 |
|
| 5414 |
``` cpp
|
| 5415 |
+
return is_sorted_until(std::forward<ExecutionPolicy>(exec), first, last, comp) == last;
|
| 5416 |
```
|
| 5417 |
|
| 5418 |
+
``` cpp
|
| 5419 |
+
template<forward_iterator I, sentinel_for<I> S, class Proj = identity,
|
| 5420 |
+
indirect_strict_weak_order<projected<I, Proj>> Comp = ranges::less>
|
| 5421 |
+
constexpr bool ranges::is_sorted(I first, S last, Comp comp = {}, Proj proj = {});
|
| 5422 |
+
template<forward_range R, class Proj = identity,
|
| 5423 |
+
indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less>
|
| 5424 |
+
constexpr bool ranges::is_sorted(R&& r, Comp comp = {}, Proj proj = {});
|
| 5425 |
+
```
|
| 5426 |
+
|
| 5427 |
+
*Effects:* Equivalent to:
|
| 5428 |
+
`return ranges::is_sorted_until(first, last, comp, proj) == last;`
|
| 5429 |
+
|
| 5430 |
``` cpp
|
| 5431 |
template<class ForwardIterator>
|
| 5432 |
+
constexpr ForwardIterator
|
| 5433 |
+
is_sorted_until(ForwardIterator first, ForwardIterator last);
|
| 5434 |
template<class ExecutionPolicy, class ForwardIterator>
|
| 5435 |
+
ForwardIterator
|
| 5436 |
+
is_sorted_until(ExecutionPolicy&& exec,
|
| 5437 |
ForwardIterator first, ForwardIterator last);
|
| 5438 |
|
| 5439 |
template<class ForwardIterator, class Compare>
|
| 5440 |
+
constexpr ForwardIterator
|
| 5441 |
+
is_sorted_until(ForwardIterator first, ForwardIterator last,
|
| 5442 |
Compare comp);
|
| 5443 |
template<class ExecutionPolicy, class ForwardIterator, class Compare>
|
| 5444 |
+
ForwardIterator
|
| 5445 |
+
is_sorted_until(ExecutionPolicy&& exec,
|
| 5446 |
ForwardIterator first, ForwardIterator last,
|
| 5447 |
Compare comp);
|
| 5448 |
+
|
| 5449 |
+
template<forward_iterator I, sentinel_for<I> S, class Proj = identity,
|
| 5450 |
+
indirect_strict_weak_order<projected<I, Proj>> Comp = ranges::less>
|
| 5451 |
+
constexpr I ranges::is_sorted_until(I first, S last, Comp comp = {}, Proj proj = {});
|
| 5452 |
+
template<forward_range R, class Proj = identity,
|
| 5453 |
+
indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less>
|
| 5454 |
+
constexpr borrowed_iterator_t<R>
|
| 5455 |
+
ranges::is_sorted_until(R&& r, Comp comp = {}, Proj proj = {});
|
| 5456 |
```
|
| 5457 |
|
| 5458 |
+
Let `comp` be `less{}` and `proj` be `identity{}` for the overloads with
|
| 5459 |
+
no parameters by those names.
|
| 5460 |
+
|
| 5461 |
+
*Returns:* The last iterator `i` in \[`first`, `last`\] for which the
|
| 5462 |
+
range \[`first`, `i`) is sorted with respect to `comp` and `proj`.
|
| 5463 |
|
| 5464 |
*Complexity:* Linear.
|
| 5465 |
|
| 5466 |
### Nth element <a id="alg.nth.element">[[alg.nth.element]]</a>
|
| 5467 |
|
| 5468 |
``` cpp
|
| 5469 |
template<class RandomAccessIterator>
|
| 5470 |
+
constexpr void nth_element(RandomAccessIterator first, RandomAccessIterator nth,
|
| 5471 |
RandomAccessIterator last);
|
| 5472 |
template<class ExecutionPolicy, class RandomAccessIterator>
|
| 5473 |
void nth_element(ExecutionPolicy&& exec,
|
| 5474 |
RandomAccessIterator first, RandomAccessIterator nth,
|
| 5475 |
RandomAccessIterator last);
|
| 5476 |
|
| 5477 |
template<class RandomAccessIterator, class Compare>
|
| 5478 |
+
constexpr void nth_element(RandomAccessIterator first, RandomAccessIterator nth,
|
| 5479 |
RandomAccessIterator last, Compare comp);
|
| 5480 |
template<class ExecutionPolicy, class RandomAccessIterator, class Compare>
|
| 5481 |
void nth_element(ExecutionPolicy&& exec,
|
| 5482 |
RandomAccessIterator first, RandomAccessIterator nth,
|
| 5483 |
RandomAccessIterator last, Compare comp);
|
| 5484 |
+
|
| 5485 |
+
template<random_access_iterator I, sentinel_for<I> S, class Comp = ranges::less,
|
| 5486 |
+
class Proj = identity>
|
| 5487 |
+
requires sortable<I, Comp, Proj>
|
| 5488 |
+
constexpr I
|
| 5489 |
+
ranges::nth_element(I first, I nth, S last, Comp comp = {}, Proj proj = {});
|
| 5490 |
```
|
| 5491 |
|
| 5492 |
+
Let `comp` be `less{}` and `proj` be `identity{}` for the overloads with
|
| 5493 |
+
no parameters by those names.
|
| 5494 |
+
|
| 5495 |
+
*Preconditions:* \[`first`, `nth`) and \[`nth`, `last`) are valid
|
| 5496 |
+
ranges. For the overloads in namespace `std`, `RandomAccessIterator`
|
| 5497 |
+
meets the *Cpp17ValueSwappable* requirements [[swappable.requirements]],
|
| 5498 |
+
and the type of `*first` meets the *Cpp17MoveConstructible*
|
| 5499 |
+
([[cpp17.moveconstructible]]) and *Cpp17MoveAssignable*
|
| 5500 |
+
([[cpp17.moveassignable]]) requirements.
|
| 5501 |
|
| 5502 |
*Effects:* After `nth_element` the element in the position pointed to by
|
| 5503 |
`nth` is the element that would be in that position if the whole range
|
| 5504 |
+
were sorted with respect to `comp` and `proj`, unless `nth == last`.
|
| 5505 |
+
Also for every iterator `i` in the range \[`first`, `nth`) and every
|
| 5506 |
+
iterator `j` in the range \[`nth`, `last`) it holds that:
|
| 5507 |
+
`bool(invoke(comp, invoke(proj, *j), invoke(proj, *i)))` is `false`.
|
| 5508 |
+
|
| 5509 |
+
*Returns:* `last` for the overload in namespace `ranges`.
|
| 5510 |
|
| 5511 |
*Complexity:* For the overloads with no `ExecutionPolicy`, linear on
|
| 5512 |
average. For the overloads with an `ExecutionPolicy`, 𝑂(N) applications
|
| 5513 |
of the predicate, and 𝑂(N log N) swaps, where N = `last - first`.
|
| 5514 |
|
| 5515 |
+
``` cpp
|
| 5516 |
+
template<random_access_range R, class Comp = ranges::less, class Proj = identity>
|
| 5517 |
+
requires sortable<iterator_t<R>, Comp, Proj>
|
| 5518 |
+
constexpr borrowed_iterator_t<R>
|
| 5519 |
+
ranges::nth_element(R&& r, iterator_t<R> nth, Comp comp = {}, Proj proj = {});
|
| 5520 |
+
```
|
| 5521 |
+
|
| 5522 |
+
*Effects:* Equivalent to:
|
| 5523 |
+
|
| 5524 |
+
``` cpp
|
| 5525 |
+
return ranges::nth_element(ranges::begin(r), nth, ranges::end(r), comp, proj);
|
| 5526 |
+
```
|
| 5527 |
+
|
| 5528 |
### Binary search <a id="alg.binary.search">[[alg.binary.search]]</a>
|
| 5529 |
|
| 5530 |
+
All of the algorithms in this subclause are versions of binary search
|
| 5531 |
+
and assume that the sequence being searched is partitioned with respect
|
| 5532 |
+
to an expression formed by binding the search key to an argument of the
|
| 5533 |
+
comparison function. They work on non-random access iterators minimizing
|
| 5534 |
+
the number of comparisons, which will be logarithmic for all types of
|
| 5535 |
+
iterators. They are especially appropriate for random access iterators,
|
| 5536 |
+
because these algorithms do a logarithmic number of steps through the
|
| 5537 |
+
data structure. For non-random access iterators they execute a linear
|
| 5538 |
+
number of steps.
|
| 5539 |
|
| 5540 |
#### `lower_bound` <a id="lower.bound">[[lower.bound]]</a>
|
| 5541 |
|
| 5542 |
``` cpp
|
| 5543 |
template<class ForwardIterator, class T>
|
| 5544 |
+
constexpr ForwardIterator
|
| 5545 |
lower_bound(ForwardIterator first, ForwardIterator last,
|
| 5546 |
const T& value);
|
| 5547 |
|
| 5548 |
template<class ForwardIterator, class T, class Compare>
|
| 5549 |
+
constexpr ForwardIterator
|
| 5550 |
lower_bound(ForwardIterator first, ForwardIterator last,
|
| 5551 |
const T& value, Compare comp);
|
| 5552 |
+
|
| 5553 |
+
template<forward_iterator I, sentinel_for<I> S, class T, class Proj = identity,
|
| 5554 |
+
indirect_strict_weak_order<const T*, projected<I, Proj>> Comp = ranges::less>
|
| 5555 |
+
constexpr I ranges::lower_bound(I first, S last, const T& value, Comp comp = {},
|
| 5556 |
+
Proj proj = {});
|
| 5557 |
+
template<forward_range R, class T, class Proj = identity,
|
| 5558 |
+
indirect_strict_weak_order<const T*, projected<iterator_t<R>, Proj>> Comp =
|
| 5559 |
+
ranges::less>
|
| 5560 |
+
constexpr borrowed_iterator_t<R>
|
| 5561 |
+
ranges::lower_bound(R&& r, const T& value, Comp comp = {}, Proj proj = {});
|
| 5562 |
```
|
| 5563 |
|
| 5564 |
+
Let `comp` be `less{}` and `proj` be `identity{}` for overloads with no
|
| 5565 |
+
parameters by those names.
|
| 5566 |
+
|
| 5567 |
+
*Preconditions:* The elements `e` of \[`first`, `last`) are partitioned
|
| 5568 |
+
with respect to the expression
|
| 5569 |
+
`bool(invoke(comp, invoke(proj, e), value))`.
|
| 5570 |
|
| 5571 |
*Returns:* The furthermost iterator `i` in the range \[`first`, `last`\]
|
| 5572 |
+
such that for every iterator `j` in the range \[`first`, `i`),
|
| 5573 |
+
`bool(invoke(comp, invoke(proj, *j), value))` is `true`.
|
|
|
|
| 5574 |
|
| 5575 |
+
*Complexity:* At most log₂(`last - first`) + 𝑂(1) comparisons and
|
| 5576 |
+
projections.
|
| 5577 |
|
| 5578 |
#### `upper_bound` <a id="upper.bound">[[upper.bound]]</a>
|
| 5579 |
|
| 5580 |
``` cpp
|
| 5581 |
template<class ForwardIterator, class T>
|
| 5582 |
+
constexpr ForwardIterator
|
| 5583 |
upper_bound(ForwardIterator first, ForwardIterator last,
|
| 5584 |
const T& value);
|
| 5585 |
|
| 5586 |
template<class ForwardIterator, class T, class Compare>
|
| 5587 |
+
constexpr ForwardIterator
|
| 5588 |
upper_bound(ForwardIterator first, ForwardIterator last,
|
| 5589 |
const T& value, Compare comp);
|
| 5590 |
+
|
| 5591 |
+
template<forward_iterator I, sentinel_for<I> S, class T, class Proj = identity,
|
| 5592 |
+
indirect_strict_weak_order<const T*, projected<I, Proj>> Comp = ranges::less>
|
| 5593 |
+
constexpr I ranges::upper_bound(I first, S last, const T& value, Comp comp = {}, Proj proj = {});
|
| 5594 |
+
template<forward_range R, class T, class Proj = identity,
|
| 5595 |
+
indirect_strict_weak_order<const T*, projected<iterator_t<R>, Proj>> Comp =
|
| 5596 |
+
ranges::less>
|
| 5597 |
+
constexpr borrowed_iterator_t<R>
|
| 5598 |
+
ranges::upper_bound(R&& r, const T& value, Comp comp = {}, Proj proj = {});
|
| 5599 |
```
|
| 5600 |
|
| 5601 |
+
Let `comp` be `less{}` and `proj` be `identity{}` for overloads with no
|
| 5602 |
+
parameters by those names.
|
| 5603 |
+
|
| 5604 |
+
*Preconditions:* The elements `e` of \[`first`, `last`) are partitioned
|
| 5605 |
+
with respect to the expression
|
| 5606 |
+
`!bool(invoke(comp, value, invoke(proj, e)))`.
|
| 5607 |
|
| 5608 |
*Returns:* The furthermost iterator `i` in the range \[`first`, `last`\]
|
| 5609 |
+
such that for every iterator `j` in the range \[`first`, `i`),
|
| 5610 |
+
`!bool(invoke(comp, value, invoke(proj, *j)))` is `true`.
|
|
|
|
| 5611 |
|
| 5612 |
+
*Complexity:* At most log₂(`last - first`) + 𝑂(1) comparisons and
|
| 5613 |
+
projections.
|
| 5614 |
|
| 5615 |
#### `equal_range` <a id="equal.range">[[equal.range]]</a>
|
| 5616 |
|
| 5617 |
``` cpp
|
| 5618 |
template<class ForwardIterator, class T>
|
| 5619 |
+
constexpr pair<ForwardIterator, ForwardIterator>
|
| 5620 |
equal_range(ForwardIterator first,
|
| 5621 |
ForwardIterator last, const T& value);
|
| 5622 |
|
| 5623 |
template<class ForwardIterator, class T, class Compare>
|
| 5624 |
+
constexpr pair<ForwardIterator, ForwardIterator>
|
| 5625 |
equal_range(ForwardIterator first,
|
| 5626 |
ForwardIterator last, const T& value,
|
| 5627 |
Compare comp);
|
| 5628 |
+
|
| 5629 |
+
template<forward_iterator I, sentinel_for<I> S, class T, class Proj = identity,
|
| 5630 |
+
indirect_strict_weak_order<const T*, projected<I, Proj>> Comp = ranges::less>
|
| 5631 |
+
constexpr subrange<I>
|
| 5632 |
+
ranges::equal_range(I first, S last, const T& value, Comp comp = {}, Proj proj = {});
|
| 5633 |
+
template<forward_range R, class T, class Proj = identity,
|
| 5634 |
+
indirect_strict_weak_order<const T*, projected<iterator_t<R>, Proj>> Comp =
|
| 5635 |
+
ranges::less>
|
| 5636 |
+
constexpr borrowed_subrange_t<R>
|
| 5637 |
+
ranges::equal_range(R&& r, const T& value, Comp comp = {}, Proj proj = {});
|
| 5638 |
```
|
| 5639 |
|
| 5640 |
+
Let `comp` be `less{}` and `proj` be `identity{}` for overloads with no
|
| 5641 |
+
parameters by those names.
|
| 5642 |
+
|
| 5643 |
+
*Preconditions:* The elements `e` of \[`first`, `last`) are partitioned
|
| 5644 |
+
with respect to the expressions
|
| 5645 |
+
`bool(invoke(comp, invoke(proj, e), value))` and
|
| 5646 |
+
`!bool(invoke(comp, value, invoke(proj, e)))`. Also, for all elements
|
| 5647 |
+
`e` of `[first, last)`, `bool(comp(e, value))` implies
|
| 5648 |
+
`!bool(comp(value, e))` for the overloads in namespace `std`.
|
| 5649 |
|
| 5650 |
*Returns:*
|
| 5651 |
|
| 5652 |
+
- For the overloads in namespace `std`:
|
| 5653 |
``` cpp
|
| 5654 |
+
{lower_bound(first, last, value, comp),
|
| 5655 |
+
upper_bound(first, last, value, comp)}
|
| 5656 |
```
|
| 5657 |
+
- For the overloads in namespace `ranges`:
|
|
|
|
|
|
|
| 5658 |
``` cpp
|
| 5659 |
+
{ranges::lower_bound(first, last, value, comp, proj),
|
| 5660 |
+
ranges::upper_bound(first, last, value, comp, proj)}
|
| 5661 |
```
|
| 5662 |
|
| 5663 |
+
*Complexity:* At most 2 * log₂(`last - first`) + 𝑂(1) comparisons and
|
| 5664 |
+
projections.
|
| 5665 |
|
| 5666 |
#### `binary_search` <a id="binary.search">[[binary.search]]</a>
|
| 5667 |
|
| 5668 |
``` cpp
|
| 5669 |
template<class ForwardIterator, class T>
|
| 5670 |
+
constexpr bool
|
| 5671 |
+
binary_search(ForwardIterator first, ForwardIterator last,
|
| 5672 |
const T& value);
|
| 5673 |
|
| 5674 |
template<class ForwardIterator, class T, class Compare>
|
| 5675 |
+
constexpr bool
|
| 5676 |
+
binary_search(ForwardIterator first, ForwardIterator last,
|
| 5677 |
const T& value, Compare comp);
|
| 5678 |
+
|
| 5679 |
+
template<forward_iterator I, sentinel_for<I> S, class T, class Proj = identity,
|
| 5680 |
+
indirect_strict_weak_order<const T*, projected<I, Proj>> Comp = ranges::less>
|
| 5681 |
+
constexpr bool ranges::binary_search(I first, S last, const T& value, Comp comp = {},
|
| 5682 |
+
Proj proj = {});
|
| 5683 |
+
template<forward_range R, class T, class Proj = identity,
|
| 5684 |
+
indirect_strict_weak_order<const T*, projected<iterator_t<R>, Proj>> Comp =
|
| 5685 |
+
ranges::less>
|
| 5686 |
+
constexpr bool ranges::binary_search(R&& r, const T& value, Comp comp = {},
|
| 5687 |
+
Proj proj = {});
|
| 5688 |
```
|
| 5689 |
|
| 5690 |
+
Let `comp` be `less{}` and `proj` be `identity{}` for overloads with no
|
| 5691 |
+
parameters by those names.
|
|
|
|
|
|
|
|
|
|
| 5692 |
|
| 5693 |
+
*Preconditions:* The elements `e` of \[`first`, `last`) are partitioned
|
| 5694 |
+
with respect to the expressions
|
| 5695 |
+
`bool(invoke(comp, invoke(proj, e), value))` and
|
| 5696 |
+
`!bool(invoke(comp, value, invoke(proj, e)))`. Also, for all elements
|
| 5697 |
+
`e` of `[first, last)`, `bool(comp(e, value))` implies
|
| 5698 |
+
`!bool(comp(value, e))` for the overloads in namespace `std`.
|
| 5699 |
|
| 5700 |
+
*Returns:* `true` if and only if for some iterator `i` in the range
|
| 5701 |
+
\[`first`, `last`),
|
| 5702 |
+
`!bool(invoke(comp, invoke(proj, *i), value)) && !bool(invoke(comp, value, invoke(proj, *i)))`
|
| 5703 |
+
is `true`.
|
| 5704 |
+
|
| 5705 |
+
*Complexity:* At most log₂(`last - first`) + 𝑂(1) comparisons and
|
| 5706 |
+
projections.
|
| 5707 |
|
| 5708 |
### Partitions <a id="alg.partitions">[[alg.partitions]]</a>
|
| 5709 |
|
| 5710 |
``` cpp
|
| 5711 |
template<class InputIterator, class Predicate>
|
| 5712 |
+
constexpr bool is_partitioned(InputIterator first, InputIterator last, Predicate pred);
|
| 5713 |
template<class ExecutionPolicy, class ForwardIterator, class Predicate>
|
| 5714 |
bool is_partitioned(ExecutionPolicy&& exec,
|
| 5715 |
ForwardIterator first, ForwardIterator last, Predicate pred);
|
| 5716 |
+
|
| 5717 |
+
template<input_iterator I, sentinel_for<I> S, class Proj = identity,
|
| 5718 |
+
indirect_unary_predicate<projected<I, Proj>> Pred>
|
| 5719 |
+
constexpr bool ranges::is_partitioned(I first, S last, Pred pred, Proj proj = {});
|
| 5720 |
+
template<input_range R, class Proj = identity,
|
| 5721 |
+
indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
|
| 5722 |
+
constexpr bool ranges::is_partitioned(R&& r, Pred pred, Proj proj = {});
|
| 5723 |
```
|
| 5724 |
|
| 5725 |
+
Let `proj` be `identity{}` for the overloads with no parameter named
|
| 5726 |
+
`proj`.
|
|
|
|
|
|
|
|
|
|
| 5727 |
|
| 5728 |
+
*Returns:* `true` if and only if the elements `e` of \[`first`, `last`)
|
| 5729 |
+
are partitioned with respect to the expression
|
| 5730 |
+
`bool(invoke(pred, invoke(proj, e)))`.
|
| 5731 |
|
| 5732 |
+
*Complexity:* Linear. At most `last - first` applications of `pred` and
|
| 5733 |
+
`proj`.
|
| 5734 |
|
| 5735 |
``` cpp
|
| 5736 |
template<class ForwardIterator, class Predicate>
|
| 5737 |
+
constexpr ForwardIterator
|
| 5738 |
partition(ForwardIterator first, ForwardIterator last, Predicate pred);
|
| 5739 |
template<class ExecutionPolicy, class ForwardIterator, class Predicate>
|
| 5740 |
ForwardIterator
|
| 5741 |
partition(ExecutionPolicy&& exec,
|
| 5742 |
ForwardIterator first, ForwardIterator last, Predicate pred);
|
| 5743 |
+
|
| 5744 |
+
template<permutable I, sentinel_for<I> S, class Proj = identity,
|
| 5745 |
+
indirect_unary_predicate<projected<I, Proj>> Pred>
|
| 5746 |
+
constexpr subrange<I>
|
| 5747 |
+
ranges::partition(I first, S last, Pred pred, Proj proj = {});
|
| 5748 |
+
template<forward_range R, class Proj = identity,
|
| 5749 |
+
indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
|
| 5750 |
+
requires permutable<iterator_t<R>>
|
| 5751 |
+
constexpr borrowed_subrange_t<R>
|
| 5752 |
+
ranges::partition(R&& r, Pred pred, Proj proj = {});
|
| 5753 |
```
|
| 5754 |
|
| 5755 |
+
Let `proj` be `identity{}` for the overloads with no parameter named
|
| 5756 |
+
`proj` and let E(x) be `bool(invoke(pred, invoke(proj, `x`)))`.
|
| 5757 |
|
| 5758 |
+
*Preconditions:* For the overloads in namespace `std`, `ForwardIterator`
|
| 5759 |
+
meets the *Cpp17ValueSwappable* requirements [[swappable.requirements]].
|
| 5760 |
|
| 5761 |
+
*Effects:* Places all the elements `e` in \[`first`, `last`) that
|
| 5762 |
+
satisfy E(`e`) before all the elements that do not.
|
| 5763 |
+
|
| 5764 |
+
*Returns:* Let `i` be an iterator such that E(`*j`) is `true` for every
|
| 5765 |
+
iterator `j` in \[`first`, `i`) and `false` for every iterator `j` in
|
| 5766 |
+
\[`i`, `last`). Returns:
|
| 5767 |
+
|
| 5768 |
+
- `i` for the overloads in namespace `std`.
|
| 5769 |
+
- `{i, last}` for the overloads in namespace `ranges`.
|
| 5770 |
|
| 5771 |
*Complexity:* Let N = `last - first`:
|
| 5772 |
|
| 5773 |
- For the overload with no `ExecutionPolicy`, exactly N applications of
|
| 5774 |
+
the predicate and projection. At most N / 2 swaps if the type of
|
| 5775 |
+
`first` meets the *Cpp17BidirectionalIterator* requirements for the
|
| 5776 |
+
overloads in namespace `std` or models `bidirectional_iterator` for
|
| 5777 |
+
the overloads in namespace `ranges`, and at most N swaps otherwise.
|
| 5778 |
- For the overload with an `ExecutionPolicy`, 𝑂(N log N) swaps and 𝑂(N)
|
| 5779 |
applications of the predicate.
|
| 5780 |
|
| 5781 |
``` cpp
|
| 5782 |
template<class BidirectionalIterator, class Predicate>
|
| 5783 |
BidirectionalIterator
|
| 5784 |
+
stable_partition(BidirectionalIterator first, BidirectionalIterator last, Predicate pred);
|
|
|
|
| 5785 |
template<class ExecutionPolicy, class BidirectionalIterator, class Predicate>
|
| 5786 |
BidirectionalIterator
|
| 5787 |
stable_partition(ExecutionPolicy&& exec,
|
| 5788 |
+
BidirectionalIterator first, BidirectionalIterator last, Predicate pred);
|
| 5789 |
+
|
| 5790 |
+
template<bidirectional_iterator I, sentinel_for<I> S, class Proj = identity,
|
| 5791 |
+
indirect_unary_predicate<projected<I, Proj>> Pred>
|
| 5792 |
+
requires permutable<I>
|
| 5793 |
+
subrange<I> ranges::stable_partition(I first, S last, Pred pred, Proj proj = {});
|
| 5794 |
+
template<bidirectional_range R, class Proj = identity,
|
| 5795 |
+
indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
|
| 5796 |
+
requires permutable<iterator_t<R>>
|
| 5797 |
+
borrowed_subrange_t<R> ranges::stable_partition(R&& r, Pred pred, Proj proj = {});
|
| 5798 |
```
|
| 5799 |
|
| 5800 |
+
Let `proj` be `identity{}` for the overloads with no parameter named
|
| 5801 |
+
`proj` and let E(x) be `bool(invoke(pred, invoke(proj, `x`)))`.
|
| 5802 |
+
|
| 5803 |
+
*Preconditions:* For the overloads in namespace `std`,
|
| 5804 |
+
`BidirectionalIterator` meets the *Cpp17ValueSwappable*
|
| 5805 |
+
requirements [[swappable.requirements]] and the type of `*first` meets
|
| 5806 |
+
the *Cpp17MoveConstructible* ([[cpp17.moveconstructible]]) and
|
| 5807 |
+
*Cpp17MoveAssignable* ([[cpp17.moveassignable]]) requirements.
|
| 5808 |
+
|
| 5809 |
+
*Effects:* Places all the elements `e` in \[`first`, `last`) that
|
| 5810 |
+
satisfy E(`e`) before all the elements that do not. The relative order
|
| 5811 |
+
of the elements in both groups is preserved.
|
| 5812 |
+
|
| 5813 |
+
*Returns:* Let `i` be an iterator such that for every iterator `j` in
|
| 5814 |
+
\[`first`, `i`), E(`*j`) is `true`, and for every iterator `j` in the
|
| 5815 |
+
range \[`i`, `last`), E(`*j`) is `false`. Returns:
|
| 5816 |
+
|
| 5817 |
+
- `i` for the overloads in namespace `std`.
|
| 5818 |
+
- `{i, last}` for the overloads in namespace `ranges`.
|
| 5819 |
|
| 5820 |
*Complexity:* Let N = `last - first`:
|
| 5821 |
|
| 5822 |
+
- For the overloads with no `ExecutionPolicy`, at most N log N swaps,
|
| 5823 |
+
but only 𝑂(N) swaps if there is enough extra memory. Exactly N
|
| 5824 |
+
applications of the predicate and projection.
|
| 5825 |
- For the overload with an `ExecutionPolicy`, 𝑂(N log N) swaps and 𝑂(N)
|
| 5826 |
applications of the predicate.
|
| 5827 |
|
| 5828 |
``` cpp
|
| 5829 |
template<class InputIterator, class OutputIterator1,
|
| 5830 |
class OutputIterator2, class Predicate>
|
| 5831 |
+
constexpr pair<OutputIterator1, OutputIterator2>
|
| 5832 |
partition_copy(InputIterator first, InputIterator last,
|
| 5833 |
+
OutputIterator1 out_true, OutputIterator2 out_false, Predicate pred);
|
|
|
|
| 5834 |
template<class ExecutionPolicy, class ForwardIterator, class ForwardIterator1,
|
| 5835 |
class ForwardIterator2, class Predicate>
|
| 5836 |
pair<ForwardIterator1, ForwardIterator2>
|
| 5837 |
partition_copy(ExecutionPolicy&& exec,
|
| 5838 |
ForwardIterator first, ForwardIterator last,
|
| 5839 |
+
ForwardIterator1 out_true, ForwardIterator2 out_false, Predicate pred);
|
| 5840 |
+
|
| 5841 |
+
template<input_iterator I, sentinel_for<I> S, weakly_incrementable O1, weakly_incrementable O2,
|
| 5842 |
+
class Proj = identity, indirect_unary_predicate<projected<I, Proj>> Pred>
|
| 5843 |
+
requires indirectly_copyable<I, O1> && indirectly_copyable<I, O2>
|
| 5844 |
+
constexpr ranges::partition_copy_result<I, O1, O2>
|
| 5845 |
+
ranges::partition_copy(I first, S last, O1 out_true, O2 out_false, Pred pred,
|
| 5846 |
+
Proj proj = {});
|
| 5847 |
+
template<input_range R, weakly_incrementable O1, weakly_incrementable O2,
|
| 5848 |
+
class Proj = identity,
|
| 5849 |
+
indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
|
| 5850 |
+
requires indirectly_copyable<iterator_t<R>, O1> &&
|
| 5851 |
+
indirectly_copyable<iterator_t<R>, O2>
|
| 5852 |
+
constexpr ranges::partition_copy_result<borrowed_iterator_t<R>, O1, O2>
|
| 5853 |
+
ranges::partition_copy(R&& r, O1 out_true, O2 out_false, Pred pred, Proj proj = {});
|
| 5854 |
```
|
| 5855 |
|
| 5856 |
+
Let `proj` be `identity{}` for the overloads with no parameter named
|
| 5857 |
+
`proj` and let E(x) be `bool(invoke(pred, invoke(proj, `x`)))`.
|
| 5858 |
|
| 5859 |
+
*Mandates:* For the overloads in namespace `std`, the expression
|
| 5860 |
+
`*first` is writable [[iterator.requirements.general]] to `out_true` and
|
| 5861 |
+
`out_false`.
|
| 5862 |
+
|
| 5863 |
+
*Preconditions:* The input range and output ranges do not overlap.
|
| 5864 |
+
|
| 5865 |
+
[*Note 1*: For the overload with an `ExecutionPolicy`, there may be a
|
| 5866 |
+
performance cost if `first`’s value type does not meet the
|
| 5867 |
+
*Cpp17CopyConstructible* requirements. — *end note*]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5868 |
|
| 5869 |
*Effects:* For each iterator `i` in \[`first`, `last`), copies `*i` to
|
| 5870 |
+
the output range beginning with `out_true` if E(`*i`) is `true`, or to
|
| 5871 |
+
the output range beginning with `out_false` otherwise.
|
| 5872 |
|
| 5873 |
+
*Returns:* Let `o1` be the end of the output range beginning at
|
| 5874 |
+
`out_true`, and `o2` the end of the output range beginning at
|
| 5875 |
+
`out_false`. Returns
|
| 5876 |
|
| 5877 |
+
- `{o1, o2}` for the overloads in namespace `std`.
|
| 5878 |
+
- `{last, o1, o2}` for the overloads in namespace `ranges`.
|
| 5879 |
+
|
| 5880 |
+
*Complexity:* Exactly `last - first` applications of `pred` and `proj`.
|
| 5881 |
|
| 5882 |
``` cpp
|
| 5883 |
template<class ForwardIterator, class Predicate>
|
| 5884 |
+
constexpr ForwardIterator
|
| 5885 |
+
partition_point(ForwardIterator first, ForwardIterator last, Predicate pred);
|
| 5886 |
+
|
| 5887 |
+
template<forward_iterator I, sentinel_for<I> S, class Proj = identity,
|
| 5888 |
+
indirect_unary_predicate<projected<I, Proj>> Pred>
|
| 5889 |
+
constexpr I ranges::partition_point(I first, S last, Pred pred, Proj proj = {});
|
| 5890 |
+
template<forward_range R, class Proj = identity,
|
| 5891 |
+
indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
|
| 5892 |
+
constexpr borrowed_iterator_t<R>
|
| 5893 |
+
ranges::partition_point(R&& r, Pred pred, Proj proj = {});
|
| 5894 |
```
|
| 5895 |
|
| 5896 |
+
Let `proj` be `identity{}` for the overloads with no parameter named
|
| 5897 |
+
`proj` and let E(x) be `bool(invoke(pred, invoke(proj, `x`)))`.
|
|
|
|
|
|
|
| 5898 |
|
| 5899 |
+
*Preconditions:* The elements `e` of \[`first`, `last`) are partitioned
|
| 5900 |
+
with respect to E(`e`).
|
| 5901 |
|
| 5902 |
+
*Returns:* An iterator `mid` such that E(`*i`) is `true` for all
|
| 5903 |
+
iterators `i` in \[`first`, `mid`), and `false` for all iterators `i` in
|
| 5904 |
+
\[`mid`, `last`).
|
| 5905 |
+
|
| 5906 |
+
*Complexity:* 𝑂(log(`last - first`)) applications of `pred` and `proj`.
|
| 5907 |
|
| 5908 |
### Merge <a id="alg.merge">[[alg.merge]]</a>
|
| 5909 |
|
| 5910 |
``` cpp
|
| 5911 |
template<class InputIterator1, class InputIterator2,
|
| 5912 |
class OutputIterator>
|
| 5913 |
+
constexpr OutputIterator
|
| 5914 |
merge(InputIterator1 first1, InputIterator1 last1,
|
| 5915 |
InputIterator2 first2, InputIterator2 last2,
|
| 5916 |
OutputIterator result);
|
| 5917 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 5918 |
class ForwardIterator>
|
|
|
|
| 5922 |
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 5923 |
ForwardIterator result);
|
| 5924 |
|
| 5925 |
template<class InputIterator1, class InputIterator2,
|
| 5926 |
class OutputIterator, class Compare>
|
| 5927 |
+
constexpr OutputIterator
|
| 5928 |
merge(InputIterator1 first1, InputIterator1 last1,
|
| 5929 |
InputIterator2 first2, InputIterator2 last2,
|
| 5930 |
OutputIterator result, Compare comp);
|
| 5931 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 5932 |
class ForwardIterator, class Compare>
|
| 5933 |
ForwardIterator
|
| 5934 |
merge(ExecutionPolicy&& exec,
|
| 5935 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 5936 |
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 5937 |
ForwardIterator result, Compare comp);
|
| 5938 |
+
|
| 5939 |
+
template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2,
|
| 5940 |
+
weakly_incrementable O, class Comp = ranges::less, class Proj1 = identity,
|
| 5941 |
+
class Proj2 = identity>
|
| 5942 |
+
requires mergeable<I1, I2, O, Comp, Proj1, Proj2>
|
| 5943 |
+
constexpr ranges::merge_result<I1, I2, O>
|
| 5944 |
+
ranges::merge(I1 first1, S1 last1, I2 first2, S2 last2, O result,
|
| 5945 |
+
Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 5946 |
+
template<input_range R1, input_range R2, weakly_incrementable O, class Comp = ranges::less,
|
| 5947 |
+
class Proj1 = identity, class Proj2 = identity>
|
| 5948 |
+
requires mergeable<iterator_t<R1>, iterator_t<R2>, O, Comp, Proj1, Proj2>
|
| 5949 |
+
constexpr ranges::merge_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>, O>
|
| 5950 |
+
ranges::merge(R1&& r1, R2&& r2, O result,
|
| 5951 |
+
Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 5952 |
```
|
| 5953 |
|
| 5954 |
+
Let N be `(last1 - first1) + (last2 - first2)`. Let `comp` be `less{}`,
|
| 5955 |
+
`proj1` be `identity{}`, and `proj2` be `identity{}`, for the overloads
|
| 5956 |
+
with no parameters by those names.
|
| 5957 |
|
| 5958 |
+
*Preconditions:* The ranges \[`first1`, `last1`) and \[`first2`,
|
| 5959 |
+
`last2`) are sorted with respect to `comp` and `proj1` or `proj2`,
|
| 5960 |
+
respectively. The resulting range does not overlap with either of the
|
| 5961 |
+
original ranges.
|
| 5962 |
+
|
| 5963 |
+
*Effects:* Copies all the elements of the two ranges \[`first1`,
|
| 5964 |
`last1`) and \[`first2`, `last2`) into the range \[`result`,
|
| 5965 |
+
`result_last`), where `result_last` is `result + `N. If an element `a`
|
| 5966 |
+
precedes `b` in an input range, `a` is copied into the output range
|
| 5967 |
+
before `b`. If `e1` is an element of \[`first1`, `last1`) and `e2` of
|
| 5968 |
+
\[`first2`, `last2`), `e2` is copied into the output range before `e1`
|
| 5969 |
+
if and only if
|
| 5970 |
+
`bool(invoke(comp, invoke(proj2, e2), invoke(proj1, e1)))` is `true`.
|
| 5971 |
|
| 5972 |
+
*Returns:*
|
| 5973 |
|
| 5974 |
+
- `result_last` for the overloads in namespace `std`.
|
| 5975 |
+
- `{last1, last2, result_last}` for the overloads in namespace `ranges`.
|
| 5976 |
|
| 5977 |
+
*Complexity:*
|
| 5978 |
+
|
| 5979 |
+
- For the overloads with no `ExecutionPolicy`, at most N - 1 comparisons
|
| 5980 |
+
and applications of each projection.
|
| 5981 |
- For the overloads with an `ExecutionPolicy`, 𝑂(N) comparisons.
|
| 5982 |
|
| 5983 |
+
*Remarks:* Stable [[algorithm.stable]].
|
| 5984 |
|
| 5985 |
``` cpp
|
| 5986 |
template<class BidirectionalIterator>
|
| 5987 |
void inplace_merge(BidirectionalIterator first,
|
| 5988 |
BidirectionalIterator middle,
|
|
|
|
| 6000 |
template<class ExecutionPolicy, class BidirectionalIterator, class Compare>
|
| 6001 |
void inplace_merge(ExecutionPolicy&& exec,
|
| 6002 |
BidirectionalIterator first,
|
| 6003 |
BidirectionalIterator middle,
|
| 6004 |
BidirectionalIterator last, Compare comp);
|
| 6005 |
+
|
| 6006 |
+
template<bidirectional_iterator I, sentinel_for<I> S, class Comp = ranges::less,
|
| 6007 |
+
class Proj = identity>
|
| 6008 |
+
requires sortable<I, Comp, Proj>
|
| 6009 |
+
I ranges::inplace_merge(I first, I middle, S last, Comp comp = {}, Proj proj = {});
|
| 6010 |
```
|
| 6011 |
|
| 6012 |
+
Let `comp` be `less{}` and `proj` be `identity{}` for the overloads with
|
| 6013 |
+
no parameters by those names.
|
| 6014 |
+
|
| 6015 |
+
*Preconditions:* \[`first`, `middle`) and \[`middle`, `last`) are valid
|
| 6016 |
+
ranges sorted with respect to `comp` and `proj`. For the overloads in
|
| 6017 |
+
namespace `std`, `BidirectionalIterator` meets the *Cpp17ValueSwappable*
|
| 6018 |
+
requirements [[swappable.requirements]] and the type of `*first` meets
|
| 6019 |
+
the *Cpp17MoveConstructible* ([[cpp17.moveconstructible]]) and
|
| 6020 |
+
*Cpp17MoveAssignable* ([[cpp17.moveassignable]]) requirements.
|
| 6021 |
|
| 6022 |
*Effects:* Merges two sorted consecutive ranges \[`first`, `middle`) and
|
| 6023 |
\[`middle`, `last`), putting the result of the merge into the range
|
| 6024 |
+
\[`first`, `last`). The resulting range is sorted with respect to `comp`
|
| 6025 |
+
and `proj`.
|
| 6026 |
+
|
| 6027 |
+
*Returns:* `last` for the overload in namespace `ranges`.
|
| 6028 |
|
| 6029 |
*Complexity:* Let N = `last - first`:
|
| 6030 |
|
| 6031 |
+
- For the overloads with no `ExecutionPolicy`, and if enough additional
|
| 6032 |
memory is available, exactly N - 1 comparisons.
|
| 6033 |
+
- Otherwise, 𝑂(N log N) comparisons.
|
|
|
|
|
|
|
| 6034 |
|
| 6035 |
+
In either case, twice as many projections as comparisons.
|
| 6036 |
+
|
| 6037 |
+
*Remarks:* Stable [[algorithm.stable]].
|
| 6038 |
+
|
| 6039 |
+
``` cpp
|
| 6040 |
+
template<bidirectional_range R, class Comp = ranges::less, class Proj = identity>
|
| 6041 |
+
requires sortable<iterator_t<R>, Comp, Proj>
|
| 6042 |
+
borrowed_iterator_t<R>
|
| 6043 |
+
ranges::inplace_merge(R&& r, iterator_t<R> middle, Comp comp = {}, Proj proj = {});
|
| 6044 |
+
```
|
| 6045 |
+
|
| 6046 |
+
*Effects:* Equivalent to:
|
| 6047 |
+
|
| 6048 |
+
``` cpp
|
| 6049 |
+
return ranges::inplace_merge(ranges::begin(r), middle, ranges::end(r), comp, proj);
|
| 6050 |
+
```
|
| 6051 |
|
| 6052 |
### Set operations on sorted structures <a id="alg.set.operations">[[alg.set.operations]]</a>
|
| 6053 |
|
| 6054 |
+
This subclause defines all the basic set operations on sorted
|
| 6055 |
+
structures. They also work with `multiset`s [[multiset]] containing
|
| 6056 |
+
multiple copies of equivalent elements. The semantics of the set
|
| 6057 |
+
operations are generalized to `multiset`s in a standard way by defining
|
| 6058 |
+
`set_union` to contain the maximum number of occurrences of every
|
| 6059 |
+
element, `set_intersection` to contain the minimum, and so on.
|
| 6060 |
|
| 6061 |
#### `includes` <a id="includes">[[includes]]</a>
|
| 6062 |
|
| 6063 |
``` cpp
|
| 6064 |
template<class InputIterator1, class InputIterator2>
|
| 6065 |
+
constexpr bool includes(InputIterator1 first1, InputIterator1 last1,
|
| 6066 |
InputIterator2 first2, InputIterator2 last2);
|
| 6067 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 6068 |
bool includes(ExecutionPolicy&& exec,
|
| 6069 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 6070 |
ForwardIterator2 first2, ForwardIterator2 last2);
|
| 6071 |
|
| 6072 |
template<class InputIterator1, class InputIterator2, class Compare>
|
| 6073 |
+
constexpr bool includes(InputIterator1 first1, InputIterator1 last1,
|
| 6074 |
InputIterator2 first2, InputIterator2 last2,
|
| 6075 |
Compare comp);
|
| 6076 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class Compare>
|
| 6077 |
bool includes(ExecutionPolicy&& exec,
|
| 6078 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 6079 |
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 6080 |
Compare comp);
|
| 6081 |
+
|
| 6082 |
+
template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2,
|
| 6083 |
+
class Proj1 = identity, class Proj2 = identity,
|
| 6084 |
+
indirect_strict_weak_order<projected<I1, Proj1>,
|
| 6085 |
+
projected<I2, Proj2>> Comp = ranges::less>
|
| 6086 |
+
constexpr bool ranges::includes(I1 first1, S1 last1, I2 first2, S2 last2, Comp comp = {},
|
| 6087 |
+
Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 6088 |
+
template<input_range R1, input_range R2, class Proj1 = identity,
|
| 6089 |
+
class Proj2 = identity,
|
| 6090 |
+
indirect_strict_weak_order<projected<iterator_t<R1>, Proj1>,
|
| 6091 |
+
projected<iterator_t<R2>, Proj2>> Comp = ranges::less>
|
| 6092 |
+
constexpr bool ranges::includes(R1&& r1, R2&& r2, Comp comp = {},
|
| 6093 |
+
Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 6094 |
```
|
| 6095 |
|
| 6096 |
+
Let `comp` be `less{}`, `proj1` be `identity{}`, and `proj2` be
|
| 6097 |
+
`identity{}`, for the overloads with no parameters by those names.
|
| 6098 |
+
|
| 6099 |
+
*Preconditions:* The ranges \[`first1`, `last1`) and \[`first2`,
|
| 6100 |
+
`last2`) are sorted with respect to `comp` and `proj1` or `proj2`,
|
| 6101 |
+
respectively.
|
| 6102 |
+
|
| 6103 |
+
*Returns:* `true` if and only if \[`first2`, `last2`) is a subsequence
|
| 6104 |
+
of \[`first1`, `last1`).
|
| 6105 |
+
|
| 6106 |
+
[*Note 1*: A sequence S is a subsequence of another sequence T if S can
|
| 6107 |
+
be obtained from T by removing some, all, or none of T’s elements and
|
| 6108 |
+
keeping the remaining elements in the same order. — *end note*]
|
| 6109 |
|
| 6110 |
*Complexity:* At most `2 * ((last1 - first1) + (last2 - first2)) - 1`
|
| 6111 |
+
comparisons and applications of each projection.
|
| 6112 |
|
| 6113 |
#### `set_union` <a id="set.union">[[set.union]]</a>
|
| 6114 |
|
| 6115 |
``` cpp
|
| 6116 |
template<class InputIterator1, class InputIterator2,
|
| 6117 |
class OutputIterator>
|
| 6118 |
+
constexpr OutputIterator
|
| 6119 |
set_union(InputIterator1 first1, InputIterator1 last1,
|
| 6120 |
InputIterator2 first2, InputIterator2 last2,
|
| 6121 |
OutputIterator result);
|
| 6122 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 6123 |
class ForwardIterator>
|
|
|
|
| 6127 |
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 6128 |
ForwardIterator result);
|
| 6129 |
|
| 6130 |
template<class InputIterator1, class InputIterator2,
|
| 6131 |
class OutputIterator, class Compare>
|
| 6132 |
+
constexpr OutputIterator
|
| 6133 |
set_union(InputIterator1 first1, InputIterator1 last1,
|
| 6134 |
InputIterator2 first2, InputIterator2 last2,
|
| 6135 |
OutputIterator result, Compare comp);
|
| 6136 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 6137 |
class ForwardIterator, class Compare>
|
| 6138 |
ForwardIterator
|
| 6139 |
set_union(ExecutionPolicy&& exec,
|
| 6140 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 6141 |
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 6142 |
ForwardIterator result, Compare comp);
|
| 6143 |
+
|
| 6144 |
+
template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2,
|
| 6145 |
+
weakly_incrementable O, class Comp = ranges::less,
|
| 6146 |
+
class Proj1 = identity, class Proj2 = identity>
|
| 6147 |
+
requires mergeable<I1, I2, O, Comp, Proj1, Proj2>
|
| 6148 |
+
constexpr ranges::set_union_result<I1, I2, O>
|
| 6149 |
+
ranges::set_union(I1 first1, S1 last1, I2 first2, S2 last2, O result, Comp comp = {},
|
| 6150 |
+
Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 6151 |
+
template<input_range R1, input_range R2, weakly_incrementable O,
|
| 6152 |
+
class Comp = ranges::less, class Proj1 = identity, class Proj2 = identity>
|
| 6153 |
+
requires mergeable<iterator_t<R1>, iterator_t<R2>, O, Comp, Proj1, Proj2>
|
| 6154 |
+
constexpr ranges::set_union_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>, O>
|
| 6155 |
+
ranges::set_union(R1&& r1, R2&& r2, O result, Comp comp = {},
|
| 6156 |
+
Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 6157 |
```
|
| 6158 |
|
| 6159 |
+
Let `comp` be `less{}`, and `proj1` and `proj2` be `identity{}` for the
|
| 6160 |
+
overloads with no parameters by those names.
|
| 6161 |
+
|
| 6162 |
+
*Preconditions:* The ranges \[`first1`, `last1`) and \[`first2`,
|
| 6163 |
+
`last2`) are sorted with respect to `comp` and `proj1` or `proj2`,
|
| 6164 |
+
respectively. The resulting range does not overlap with either of the
|
| 6165 |
original ranges.
|
| 6166 |
|
| 6167 |
*Effects:* Constructs a sorted union of the elements from the two
|
| 6168 |
ranges; that is, the set of elements that are present in one or both of
|
| 6169 |
the ranges.
|
| 6170 |
|
| 6171 |
+
*Returns:* Let `result_last` be the end of the constructed range.
|
| 6172 |
+
Returns
|
| 6173 |
+
|
| 6174 |
+
- `result_last` for the overloads in namespace `std`.
|
| 6175 |
+
- `{last1, last2, result_last}` for the overloads in namespace `ranges`.
|
| 6176 |
|
| 6177 |
*Complexity:* At most `2 * ((last1 - first1) + (last2 - first2)) - 1`
|
| 6178 |
+
comparisons and applications of each projection.
|
| 6179 |
|
| 6180 |
+
*Remarks:* Stable [[algorithm.stable]]. If \[`first1`, `last1`) contains
|
| 6181 |
+
m elements that are equivalent to each other and \[`first2`, `last2`)
|
| 6182 |
+
contains n elements that are equivalent to them, then all m elements
|
| 6183 |
+
from the first range are copied to the output range, in order, and then
|
| 6184 |
+
the final max(n - m, 0) elements from the second range are copied to the
|
| 6185 |
+
output range, in order.
|
| 6186 |
|
| 6187 |
#### `set_intersection` <a id="set.intersection">[[set.intersection]]</a>
|
| 6188 |
|
| 6189 |
``` cpp
|
| 6190 |
template<class InputIterator1, class InputIterator2,
|
| 6191 |
class OutputIterator>
|
| 6192 |
+
constexpr OutputIterator
|
| 6193 |
set_intersection(InputIterator1 first1, InputIterator1 last1,
|
| 6194 |
InputIterator2 first2, InputIterator2 last2,
|
| 6195 |
OutputIterator result);
|
| 6196 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 6197 |
class ForwardIterator>
|
|
|
|
| 6201 |
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 6202 |
ForwardIterator result);
|
| 6203 |
|
| 6204 |
template<class InputIterator1, class InputIterator2,
|
| 6205 |
class OutputIterator, class Compare>
|
| 6206 |
+
constexpr OutputIterator
|
| 6207 |
set_intersection(InputIterator1 first1, InputIterator1 last1,
|
| 6208 |
InputIterator2 first2, InputIterator2 last2,
|
| 6209 |
OutputIterator result, Compare comp);
|
| 6210 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 6211 |
class ForwardIterator, class Compare>
|
| 6212 |
ForwardIterator
|
| 6213 |
set_intersection(ExecutionPolicy&& exec,
|
| 6214 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 6215 |
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 6216 |
ForwardIterator result, Compare comp);
|
| 6217 |
+
|
| 6218 |
+
template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2,
|
| 6219 |
+
weakly_incrementable O, class Comp = ranges::less,
|
| 6220 |
+
class Proj1 = identity, class Proj2 = identity>
|
| 6221 |
+
requires mergeable<I1, I2, O, Comp, Proj1, Proj2>
|
| 6222 |
+
constexpr ranges::set_intersection_result<I1, I2, O>
|
| 6223 |
+
ranges::set_intersection(I1 first1, S1 last1, I2 first2, S2 last2, O result,
|
| 6224 |
+
Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 6225 |
+
template<input_range R1, input_range R2, weakly_incrementable O,
|
| 6226 |
+
class Comp = ranges::less, class Proj1 = identity, class Proj2 = identity>
|
| 6227 |
+
requires mergeable<iterator_t<R1>, iterator_t<R2>, O, Comp, Proj1, Proj2>
|
| 6228 |
+
constexpr ranges::set_intersection_result<borrowed_iterator_t<R1>, borrowed_iterator_t<R2>, O>
|
| 6229 |
+
ranges::set_intersection(R1&& r1, R2&& r2, O result,
|
| 6230 |
+
Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 6231 |
```
|
| 6232 |
|
| 6233 |
+
Let `comp` be `less{}`, and `proj1` and `proj2` be `identity{}` for the
|
| 6234 |
+
overloads with no parameters by those names.
|
| 6235 |
+
|
| 6236 |
+
*Preconditions:* The ranges \[`first1`, `last1`) and \[`first2`,
|
| 6237 |
+
`last2`) are sorted with respect to `comp` and `proj1` or `proj2`,
|
| 6238 |
+
respectively. The resulting range does not overlap with either of the
|
| 6239 |
original ranges.
|
| 6240 |
|
| 6241 |
*Effects:* Constructs a sorted intersection of the elements from the two
|
| 6242 |
ranges; that is, the set of elements that are present in both of the
|
| 6243 |
ranges.
|
| 6244 |
|
| 6245 |
+
*Returns:* Let `result_last` be the end of the constructed range.
|
| 6246 |
+
Returns
|
| 6247 |
+
|
| 6248 |
+
- `result_last` for the overloads in namespace `std`.
|
| 6249 |
+
- `{last1, last2, result_last}` for the overloads in namespace `ranges`.
|
| 6250 |
|
| 6251 |
*Complexity:* At most `2 * ((last1 - first1) + (last2 - first2)) - 1`
|
| 6252 |
+
comparisons and applications of each projection.
|
| 6253 |
|
| 6254 |
+
*Remarks:* Stable [[algorithm.stable]]. If \[`first1`, `last1`) contains
|
| 6255 |
+
m elements that are equivalent to each other and \[`first2`, `last2`)
|
| 6256 |
+
contains n elements that are equivalent to them, the first min(m, n)
|
| 6257 |
+
elements are copied from the first range to the output range, in order.
|
| 6258 |
|
| 6259 |
#### `set_difference` <a id="set.difference">[[set.difference]]</a>
|
| 6260 |
|
| 6261 |
``` cpp
|
| 6262 |
template<class InputIterator1, class InputIterator2,
|
| 6263 |
class OutputIterator>
|
| 6264 |
+
constexpr OutputIterator
|
| 6265 |
set_difference(InputIterator1 first1, InputIterator1 last1,
|
| 6266 |
InputIterator2 first2, InputIterator2 last2,
|
| 6267 |
OutputIterator result);
|
| 6268 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 6269 |
class ForwardIterator>
|
|
|
|
| 6273 |
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 6274 |
ForwardIterator result);
|
| 6275 |
|
| 6276 |
template<class InputIterator1, class InputIterator2,
|
| 6277 |
class OutputIterator, class Compare>
|
| 6278 |
+
constexpr OutputIterator
|
| 6279 |
set_difference(InputIterator1 first1, InputIterator1 last1,
|
| 6280 |
InputIterator2 first2, InputIterator2 last2,
|
| 6281 |
OutputIterator result, Compare comp);
|
| 6282 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 6283 |
class ForwardIterator, class Compare>
|
| 6284 |
ForwardIterator
|
| 6285 |
set_difference(ExecutionPolicy&& exec,
|
| 6286 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 6287 |
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 6288 |
ForwardIterator result, Compare comp);
|
| 6289 |
+
|
| 6290 |
+
template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2,
|
| 6291 |
+
weakly_incrementable O, class Comp = ranges::less,
|
| 6292 |
+
class Proj1 = identity, class Proj2 = identity>
|
| 6293 |
+
requires mergeable<I1, I2, O, Comp, Proj1, Proj2>
|
| 6294 |
+
constexpr ranges::set_difference_result<I1, O>
|
| 6295 |
+
ranges::set_difference(I1 first1, S1 last1, I2 first2, S2 last2, O result,
|
| 6296 |
+
Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 6297 |
+
template<input_range R1, input_range R2, weakly_incrementable O,
|
| 6298 |
+
class Comp = ranges::less, class Proj1 = identity, class Proj2 = identity>
|
| 6299 |
+
requires mergeable<iterator_t<R1>, iterator_t<R2>, O, Comp, Proj1, Proj2>
|
| 6300 |
+
constexpr ranges::set_difference_result<borrowed_iterator_t<R1>, O>
|
| 6301 |
+
ranges::set_difference(R1&& r1, R2&& r2, O result,
|
| 6302 |
+
Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 6303 |
```
|
| 6304 |
|
| 6305 |
+
Let `comp` be `less{}`, and `proj1` and `proj2` be `identity{}` for the
|
| 6306 |
+
overloads with no parameters by those names.
|
| 6307 |
+
|
| 6308 |
+
*Preconditions:* The ranges \[`first1`, `last1`) and \[`first2`,
|
| 6309 |
+
`last2`) are sorted with respect to `comp` and `proj1` or `proj2`,
|
| 6310 |
+
respectively. The resulting range does not overlap with either of the
|
| 6311 |
original ranges.
|
| 6312 |
|
| 6313 |
*Effects:* Copies the elements of the range \[`first1`, `last1`) which
|
| 6314 |
are not present in the range \[`first2`, `last2`) to the range beginning
|
| 6315 |
at `result`. The elements in the constructed range are sorted.
|
| 6316 |
|
| 6317 |
+
*Returns:* Let `result_last` be the end of the constructed range.
|
| 6318 |
+
Returns
|
| 6319 |
+
|
| 6320 |
+
- `result_last` for the overloads in namespace `std`.
|
| 6321 |
+
- `{last1, result_last}` for the overloads in namespace `ranges`.
|
| 6322 |
|
| 6323 |
*Complexity:* At most `2 * ((last1 - first1) + (last2 - first2)) - 1`
|
| 6324 |
+
comparisons and applications of each projection.
|
| 6325 |
|
| 6326 |
*Remarks:* If \[`first1`, `last1`) contains m elements that are
|
| 6327 |
equivalent to each other and \[`first2`, `last2`) contains n elements
|
| 6328 |
that are equivalent to them, the last max(m - n, 0) elements from
|
| 6329 |
+
\[`first1`, `last1`) is copied to the output range, in order.
|
| 6330 |
|
| 6331 |
#### `set_symmetric_difference` <a id="set.symmetric.difference">[[set.symmetric.difference]]</a>
|
| 6332 |
|
| 6333 |
``` cpp
|
| 6334 |
template<class InputIterator1, class InputIterator2,
|
| 6335 |
class OutputIterator>
|
| 6336 |
+
constexpr OutputIterator
|
| 6337 |
set_symmetric_difference(InputIterator1 first1, InputIterator1 last1,
|
| 6338 |
InputIterator2 first2, InputIterator2 last2,
|
| 6339 |
OutputIterator result);
|
| 6340 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 6341 |
class ForwardIterator>
|
|
|
|
| 6345 |
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 6346 |
ForwardIterator result);
|
| 6347 |
|
| 6348 |
template<class InputIterator1, class InputIterator2,
|
| 6349 |
class OutputIterator, class Compare>
|
| 6350 |
+
constexpr OutputIterator
|
| 6351 |
set_symmetric_difference(InputIterator1 first1, InputIterator1 last1,
|
| 6352 |
InputIterator2 first2, InputIterator2 last2,
|
| 6353 |
OutputIterator result, Compare comp);
|
| 6354 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 6355 |
class ForwardIterator, class Compare>
|
| 6356 |
ForwardIterator
|
| 6357 |
set_symmetric_difference(ExecutionPolicy&& exec,
|
| 6358 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 6359 |
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 6360 |
ForwardIterator result, Compare comp);
|
| 6361 |
+
|
| 6362 |
+
template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2,
|
| 6363 |
+
weakly_incrementable O, class Comp = ranges::less,
|
| 6364 |
+
class Proj1 = identity, class Proj2 = identity>
|
| 6365 |
+
requires mergeable<I1, I2, O, Comp, Proj1, Proj2>
|
| 6366 |
+
constexpr ranges::set_symmetric_difference_result<I1, I2, O>
|
| 6367 |
+
ranges::set_symmetric_difference(I1 first1, S1 last1, I2 first2, S2 last2, O result,
|
| 6368 |
+
Comp comp = {}, Proj1 proj1 = {},
|
| 6369 |
+
Proj2 proj2 = {});
|
| 6370 |
+
template<input_range R1, input_range R2, weakly_incrementable O,
|
| 6371 |
+
class Comp = ranges::less, class Proj1 = identity, class Proj2 = identity>
|
| 6372 |
+
requires mergeable<iterator_t<R1>, iterator_t<R2>, O, Comp, Proj1, Proj2>
|
| 6373 |
+
constexpr ranges::set_symmetric_difference_result<borrowed_iterator_t<R1>,
|
| 6374 |
+
borrowed_iterator_t<R2>, O>
|
| 6375 |
+
ranges::set_symmetric_difference(R1&& r1, R2&& r2, O result, Comp comp = {},
|
| 6376 |
+
Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 6377 |
```
|
| 6378 |
|
| 6379 |
+
Let `comp` be `less{}`, and `proj1` and `proj2` be `identity{}` for the
|
| 6380 |
+
overloads with no parameters by those names.
|
| 6381 |
+
|
| 6382 |
+
*Preconditions:* The ranges \[`first1`, `last1`) and \[`first2`,
|
| 6383 |
+
`last2`) are sorted with respect to `comp` and `proj1` or `proj2`,
|
| 6384 |
+
respectively. The resulting range does not overlap with either of the
|
| 6385 |
original ranges.
|
| 6386 |
|
| 6387 |
*Effects:* Copies the elements of the range \[`first1`, `last1`) that
|
| 6388 |
are not present in the range \[`first2`, `last2`), and the elements of
|
| 6389 |
the range \[`first2`, `last2`) that are not present in the range
|
| 6390 |
\[`first1`, `last1`) to the range beginning at `result`. The elements in
|
| 6391 |
the constructed range are sorted.
|
| 6392 |
|
| 6393 |
+
*Returns:* Let `result_last` be the end of the constructed range.
|
| 6394 |
+
Returns
|
| 6395 |
+
|
| 6396 |
+
- `result_last` for the overloads in namespace `std`.
|
| 6397 |
+
- `{last1, last2, result_last}` for the overloads in namespace `ranges`.
|
| 6398 |
|
| 6399 |
*Complexity:* At most `2 * ((last1 - first1) + (last2 - first2)) - 1`
|
| 6400 |
+
comparisons and applications of each projection.
|
| 6401 |
|
| 6402 |
+
*Remarks:* Stable [[algorithm.stable]]. If \[`first1`, `last1`) contains
|
| 6403 |
+
m elements that are equivalent to each other and \[`first2`, `last2`)
|
| 6404 |
+
contains n elements that are equivalent to them, then |m - n| of those
|
| 6405 |
+
elements shall be copied to the output range: the last m - n of these
|
| 6406 |
+
elements from \[`first1`, `last1`) if m > n, and the last n - m of these
|
| 6407 |
+
elements from \[`first2`, `last2`) if m < n. In either case, the
|
| 6408 |
+
elements are copied in order.
|
| 6409 |
|
| 6410 |
### Heap operations <a id="alg.heap.operations">[[alg.heap.operations]]</a>
|
| 6411 |
|
| 6412 |
+
A random access range \[`a`, `b`) is a *heap with respect to `comp` and
|
| 6413 |
+
`proj`* for a comparator and projection `comp` and `proj` if its
|
| 6414 |
+
elements are organized such that:
|
| 6415 |
|
| 6416 |
- With `N = b - a`, for all i, 0 < i < N,
|
| 6417 |
+
`bool(invoke(comp, invoke(proj, a[\left \lfloor{\frac{i - 1}{2}}\right \rfloor]), invoke({}proj, a[i])))`
|
| 6418 |
+
is `false`.
|
| 6419 |
+
- `*a` may be removed by `pop_heap`, or a new element added by
|
| 6420 |
+
`push_heap`, in 𝑂(log N) time.
|
| 6421 |
|
| 6422 |
These properties make heaps useful as priority queues.
|
| 6423 |
|
| 6424 |
+
`make_heap` converts a range into a heap and `sort_heap` turns a heap
|
| 6425 |
+
into a sorted sequence.
|
|
|
|
|
|
|
| 6426 |
|
| 6427 |
#### `push_heap` <a id="push.heap">[[push.heap]]</a>
|
| 6428 |
|
| 6429 |
``` cpp
|
| 6430 |
template<class RandomAccessIterator>
|
| 6431 |
+
constexpr void push_heap(RandomAccessIterator first, RandomAccessIterator last);
|
| 6432 |
|
| 6433 |
template<class RandomAccessIterator, class Compare>
|
| 6434 |
+
constexpr void push_heap(RandomAccessIterator first, RandomAccessIterator last,
|
| 6435 |
Compare comp);
|
| 6436 |
+
|
| 6437 |
+
template<random_access_iterator I, sentinel_for<I> S, class Comp = ranges::less,
|
| 6438 |
+
class Proj = identity>
|
| 6439 |
+
requires sortable<I, Comp, Proj>
|
| 6440 |
+
constexpr I
|
| 6441 |
+
ranges::push_heap(I first, S last, Comp comp = {}, Proj proj = {});
|
| 6442 |
+
template<random_access_range R, class Comp = ranges::less, class Proj = identity>
|
| 6443 |
+
requires sortable<iterator_t<R>, Comp, Proj>
|
| 6444 |
+
constexpr borrowed_iterator_t<R>
|
| 6445 |
+
ranges::push_heap(R&& r, Comp comp = {}, Proj proj = {});
|
| 6446 |
```
|
| 6447 |
|
| 6448 |
+
Let `comp` be `less{}` and `proj` be `identity{}` for the overloads with
|
| 6449 |
+
no parameters by those names.
|
| 6450 |
+
|
| 6451 |
+
*Preconditions:* The range \[`first`, `last - 1`) is a valid heap with
|
| 6452 |
+
respect to `comp` and `proj`. For the overloads in namespace `std`, the
|
| 6453 |
+
type of `*first` meets the *Cpp17MoveConstructible* requirements
|
| 6454 |
+
([[cpp17.moveconstructible]]) and the *Cpp17MoveAssignable*
|
| 6455 |
+
requirements ([[cpp17.moveassignable]]).
|
| 6456 |
|
| 6457 |
*Effects:* Places the value in the location `last - 1` into the
|
| 6458 |
resulting heap \[`first`, `last`).
|
| 6459 |
|
| 6460 |
+
*Returns:* `last` for the overloads in namespace `ranges`.
|
| 6461 |
+
|
| 6462 |
+
*Complexity:* At most log(`last - first`) comparisons and twice as many
|
| 6463 |
+
projections.
|
| 6464 |
|
| 6465 |
#### `pop_heap` <a id="pop.heap">[[pop.heap]]</a>
|
| 6466 |
|
| 6467 |
``` cpp
|
| 6468 |
template<class RandomAccessIterator>
|
| 6469 |
+
constexpr void pop_heap(RandomAccessIterator first, RandomAccessIterator last);
|
| 6470 |
|
| 6471 |
template<class RandomAccessIterator, class Compare>
|
| 6472 |
+
constexpr void pop_heap(RandomAccessIterator first, RandomAccessIterator last,
|
| 6473 |
Compare comp);
|
| 6474 |
+
|
| 6475 |
+
template<random_access_iterator I, sentinel_for<I> S, class Comp = ranges::less,
|
| 6476 |
+
class Proj = identity>
|
| 6477 |
+
requires sortable<I, Comp, Proj>
|
| 6478 |
+
constexpr I
|
| 6479 |
+
ranges::pop_heap(I first, S last, Comp comp = {}, Proj proj = {});
|
| 6480 |
+
template<random_access_range R, class Comp = ranges::less, class Proj = identity>
|
| 6481 |
+
requires sortable<iterator_t<R>, Comp, Proj>
|
| 6482 |
+
constexpr borrowed_iterator_t<R>
|
| 6483 |
+
ranges::pop_heap(R&& r, Comp comp = {}, Proj proj = {});
|
| 6484 |
```
|
| 6485 |
|
| 6486 |
+
Let `comp` be `less{}` and `proj` be `identity{}` for the overloads with
|
| 6487 |
+
no parameters by those names.
|
| 6488 |
+
|
| 6489 |
+
*Preconditions:* The range \[`first`, `last`) is a valid non-empty heap
|
| 6490 |
+
with respect to `comp` and `proj`. For the overloads in namespace `std`,
|
| 6491 |
+
`RandomAccessIterator` meets the *Cpp17ValueSwappable*
|
| 6492 |
+
requirements [[swappable.requirements]] and the type of `*first` meets
|
| 6493 |
+
the *Cpp17MoveConstructible* ([[cpp17.moveconstructible]]) and
|
| 6494 |
+
*Cpp17MoveAssignable* ([[cpp17.moveassignable]]) requirements.
|
| 6495 |
|
| 6496 |
*Effects:* Swaps the value in the location `first` with the value in the
|
| 6497 |
+
location `last - 1` and makes \[`first`, `last - 1`) into a heap with
|
| 6498 |
+
respect to `comp` and `proj`.
|
| 6499 |
|
| 6500 |
+
*Returns:* `last` for the overloads in namespace `ranges`.
|
| 6501 |
+
|
| 6502 |
+
*Complexity:* At most 2 log(`last - first`) comparisons and twice as
|
| 6503 |
+
many projections.
|
| 6504 |
|
| 6505 |
#### `make_heap` <a id="make.heap">[[make.heap]]</a>
|
| 6506 |
|
| 6507 |
``` cpp
|
| 6508 |
template<class RandomAccessIterator>
|
| 6509 |
+
constexpr void make_heap(RandomAccessIterator first, RandomAccessIterator last);
|
| 6510 |
|
| 6511 |
template<class RandomAccessIterator, class Compare>
|
| 6512 |
+
constexpr void make_heap(RandomAccessIterator first, RandomAccessIterator last,
|
| 6513 |
Compare comp);
|
| 6514 |
+
|
| 6515 |
+
template<random_access_iterator I, sentinel_for<I> S, class Comp = ranges::less,
|
| 6516 |
+
class Proj = identity>
|
| 6517 |
+
requires sortable<I, Comp, Proj>
|
| 6518 |
+
constexpr I
|
| 6519 |
+
ranges::make_heap(I first, S last, Comp comp = {}, Proj proj = {});
|
| 6520 |
+
template<random_access_range R, class Comp = ranges::less, class Proj = identity>
|
| 6521 |
+
requires sortable<iterator_t<R>, Comp, Proj>
|
| 6522 |
+
constexpr borrowed_iterator_t<R>
|
| 6523 |
+
ranges::make_heap(R&& r, Comp comp = {}, Proj proj = {});
|
| 6524 |
```
|
| 6525 |
|
| 6526 |
+
Let `comp` be `less{}` and `proj` be `identity{}` for the overloads with
|
| 6527 |
+
no parameters by those names.
|
|
|
|
| 6528 |
|
| 6529 |
+
*Preconditions:* For the overloads in namespace `std`, the type of
|
| 6530 |
+
`*first` meets the *Cpp17MoveConstructible*
|
| 6531 |
+
([[cpp17.moveconstructible]]) and *Cpp17MoveAssignable*
|
| 6532 |
+
([[cpp17.moveassignable]]) requirements.
|
| 6533 |
|
| 6534 |
+
*Effects:* Constructs a heap with respect to `comp` and `proj` out of
|
| 6535 |
+
the range \[`first`, `last`).
|
| 6536 |
+
|
| 6537 |
+
*Returns:* `last` for the overloads in namespace `ranges`.
|
| 6538 |
+
|
| 6539 |
+
*Complexity:* At most 3(`last - first`) comparisons and twice as many
|
| 6540 |
+
projections.
|
| 6541 |
|
| 6542 |
#### `sort_heap` <a id="sort.heap">[[sort.heap]]</a>
|
| 6543 |
|
| 6544 |
``` cpp
|
| 6545 |
template<class RandomAccessIterator>
|
| 6546 |
+
constexpr void sort_heap(RandomAccessIterator first, RandomAccessIterator last);
|
| 6547 |
|
| 6548 |
template<class RandomAccessIterator, class Compare>
|
| 6549 |
+
constexpr void sort_heap(RandomAccessIterator first, RandomAccessIterator last,
|
| 6550 |
Compare comp);
|
| 6551 |
+
|
| 6552 |
+
template<random_access_iterator I, sentinel_for<I> S, class Comp = ranges::less,
|
| 6553 |
+
class Proj = identity>
|
| 6554 |
+
requires sortable<I, Comp, Proj>
|
| 6555 |
+
constexpr I
|
| 6556 |
+
ranges::sort_heap(I first, S last, Comp comp = {}, Proj proj = {});
|
| 6557 |
+
template<random_access_range R, class Comp = ranges::less, class Proj = identity>
|
| 6558 |
+
requires sortable<iterator_t<R>, Comp, Proj>
|
| 6559 |
+
constexpr borrowed_iterator_t<R>
|
| 6560 |
+
ranges::sort_heap(R&& r, Comp comp = {}, Proj proj = {});
|
| 6561 |
```
|
| 6562 |
|
| 6563 |
+
Let `comp` be `less{}` and `proj` be `identity{}` for the overloads with
|
| 6564 |
+
no parameters by those names.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6565 |
|
| 6566 |
+
*Preconditions:* The range \[`first`, `last`) is a valid heap with
|
| 6567 |
+
respect to `comp` and `proj`. For the overloads in namespace `std`,
|
| 6568 |
+
`RandomAccessIterator` meets the *Cpp17ValueSwappable*
|
| 6569 |
+
requirements [[swappable.requirements]] and the type of `*first` meets
|
| 6570 |
+
the *Cpp17MoveConstructible* ([[cpp17.moveconstructible]]) and
|
| 6571 |
+
*Cpp17MoveAssignable* ([[cpp17.moveassignable]]) requirements.
|
| 6572 |
|
| 6573 |
+
*Effects:* Sorts elements in the heap \[`first`, `last`) with respect to
|
| 6574 |
+
`comp` and `proj`.
|
| 6575 |
+
|
| 6576 |
+
*Returns:* `last` for the overloads in namespace `ranges`.
|
| 6577 |
+
|
| 6578 |
+
*Complexity:* At most 2N log N comparisons, where N = `last - first`,
|
| 6579 |
+
and twice as many projections.
|
| 6580 |
|
| 6581 |
#### `is_heap` <a id="is.heap">[[is.heap]]</a>
|
| 6582 |
|
| 6583 |
``` cpp
|
| 6584 |
template<class RandomAccessIterator>
|
| 6585 |
+
constexpr bool is_heap(RandomAccessIterator first, RandomAccessIterator last);
|
| 6586 |
```
|
| 6587 |
|
| 6588 |
+
*Effects:* Equivalent to: `return is_heap_until(first, last) == last;`
|
| 6589 |
|
| 6590 |
``` cpp
|
| 6591 |
template<class ExecutionPolicy, class RandomAccessIterator>
|
| 6592 |
bool is_heap(ExecutionPolicy&& exec,
|
| 6593 |
RandomAccessIterator first, RandomAccessIterator last);
|
| 6594 |
```
|
| 6595 |
|
| 6596 |
+
*Effects:* Equivalent to:
|
| 6597 |
+
|
| 6598 |
+
``` cpp
|
| 6599 |
+
return is_heap_until(std::forward<ExecutionPolicy>(exec), first, last) == last;
|
| 6600 |
+
```
|
| 6601 |
|
| 6602 |
``` cpp
|
| 6603 |
template<class RandomAccessIterator, class Compare>
|
| 6604 |
+
constexpr bool is_heap(RandomAccessIterator first, RandomAccessIterator last,
|
| 6605 |
+
Compare comp);
|
| 6606 |
```
|
| 6607 |
|
| 6608 |
+
*Effects:* Equivalent to:
|
| 6609 |
+
`return is_heap_until(first, last, comp) == last;`
|
| 6610 |
|
| 6611 |
``` cpp
|
| 6612 |
template<class ExecutionPolicy, class RandomAccessIterator, class Compare>
|
| 6613 |
bool is_heap(ExecutionPolicy&& exec,
|
| 6614 |
+
RandomAccessIterator first, RandomAccessIterator last,
|
| 6615 |
+
Compare comp);
|
| 6616 |
```
|
| 6617 |
|
| 6618 |
+
*Effects:* Equivalent to:
|
| 6619 |
|
| 6620 |
``` cpp
|
| 6621 |
+
return is_heap_until(std::forward<ExecutionPolicy>(exec), first, last, comp) == last;
|
| 6622 |
```
|
| 6623 |
|
| 6624 |
+
``` cpp
|
| 6625 |
+
template<random_access_iterator I, sentinel_for<I> S, class Proj = identity,
|
| 6626 |
+
indirect_strict_weak_order<projected<I, Proj>> Comp = ranges::less>
|
| 6627 |
+
constexpr bool ranges::is_heap(I first, S last, Comp comp = {}, Proj proj = {});
|
| 6628 |
+
template<random_access_range R, class Proj = identity,
|
| 6629 |
+
indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less>
|
| 6630 |
+
constexpr bool ranges::is_heap(R&& r, Comp comp = {}, Proj proj = {});
|
| 6631 |
+
```
|
| 6632 |
+
|
| 6633 |
+
*Effects:* Equivalent to:
|
| 6634 |
+
`return ranges::is_heap_until(first, last, comp, proj) == last;`
|
| 6635 |
+
|
| 6636 |
``` cpp
|
| 6637 |
template<class RandomAccessIterator>
|
| 6638 |
+
constexpr RandomAccessIterator
|
| 6639 |
+
is_heap_until(RandomAccessIterator first, RandomAccessIterator last);
|
| 6640 |
template<class ExecutionPolicy, class RandomAccessIterator>
|
| 6641 |
+
RandomAccessIterator
|
| 6642 |
+
is_heap_until(ExecutionPolicy&& exec,
|
| 6643 |
RandomAccessIterator first, RandomAccessIterator last);
|
| 6644 |
|
| 6645 |
template<class RandomAccessIterator, class Compare>
|
| 6646 |
+
constexpr RandomAccessIterator
|
| 6647 |
+
is_heap_until(RandomAccessIterator first, RandomAccessIterator last,
|
| 6648 |
Compare comp);
|
| 6649 |
template<class ExecutionPolicy, class RandomAccessIterator, class Compare>
|
| 6650 |
+
RandomAccessIterator
|
| 6651 |
+
is_heap_until(ExecutionPolicy&& exec,
|
| 6652 |
RandomAccessIterator first, RandomAccessIterator last,
|
| 6653 |
Compare comp);
|
| 6654 |
+
|
| 6655 |
+
template<random_access_iterator I, sentinel_for<I> S, class Proj = identity,
|
| 6656 |
+
indirect_strict_weak_order<projected<I, Proj>> Comp = ranges::less>
|
| 6657 |
+
constexpr I ranges::is_heap_until(I first, S last, Comp comp = {}, Proj proj = {});
|
| 6658 |
+
template<random_access_range R, class Proj = identity,
|
| 6659 |
+
indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less>
|
| 6660 |
+
constexpr borrowed_iterator_t<R>
|
| 6661 |
+
ranges::is_heap_until(R&& r, Comp comp = {}, Proj proj = {});
|
| 6662 |
```
|
| 6663 |
|
| 6664 |
+
Let `comp` be `less{}` and `proj` be `identity{}` for the overloads with
|
| 6665 |
+
no parameters by those names.
|
| 6666 |
+
|
| 6667 |
+
*Returns:* The last iterator `i` in \[`first`, `last`\] for which the
|
| 6668 |
+
range \[`first`, `i`) is a heap with respect to `comp` and `proj`.
|
| 6669 |
|
| 6670 |
*Complexity:* Linear.
|
| 6671 |
|
| 6672 |
### Minimum and maximum <a id="alg.min.max">[[alg.min.max]]</a>
|
| 6673 |
|
| 6674 |
``` cpp
|
| 6675 |
+
template<class T>
|
| 6676 |
+
constexpr const T& min(const T& a, const T& b);
|
| 6677 |
template<class T, class Compare>
|
| 6678 |
constexpr const T& min(const T& a, const T& b, Compare comp);
|
| 6679 |
+
|
| 6680 |
+
template<class T, class Proj = identity,
|
| 6681 |
+
indirect_strict_weak_order<projected<const T*, Proj>> Comp = ranges::less>
|
| 6682 |
+
constexpr const T& ranges::min(const T& a, const T& b, Comp comp = {}, Proj proj = {});
|
| 6683 |
```
|
| 6684 |
|
| 6685 |
+
*Preconditions:* For the first form, `T` meets the
|
| 6686 |
+
*Cpp17LessThanComparable* requirements ([[cpp17.lessthancomparable]]).
|
| 6687 |
|
| 6688 |
*Returns:* The smaller value.
|
| 6689 |
|
| 6690 |
*Remarks:* Returns the first argument when the arguments are equivalent.
|
| 6691 |
+
An invocation may explicitly specify an argument for the template
|
| 6692 |
+
parameter `T` of the overloads in namespace `std`.
|
| 6693 |
|
| 6694 |
+
*Complexity:* Exactly one comparison and two applications of the
|
| 6695 |
+
projection, if any.
|
| 6696 |
|
| 6697 |
``` cpp
|
| 6698 |
template<class T>
|
| 6699 |
+
constexpr T min(initializer_list<T> r);
|
| 6700 |
template<class T, class Compare>
|
| 6701 |
+
constexpr T min(initializer_list<T> r, Compare comp);
|
| 6702 |
+
|
| 6703 |
+
template<copyable T, class Proj = identity,
|
| 6704 |
+
indirect_strict_weak_order<projected<const T*, Proj>> Comp = ranges::less>
|
| 6705 |
+
constexpr T ranges::min(initializer_list<T> r, Comp comp = {}, Proj proj = {});
|
| 6706 |
+
template<input_range R, class Proj = identity,
|
| 6707 |
+
indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less>
|
| 6708 |
+
requires indirectly_copyable_storable<iterator_t<R>, range_value_t<R>*>
|
| 6709 |
+
constexpr range_value_t<R>
|
| 6710 |
+
ranges::min(R&& r, Comp comp = {}, Proj proj = {});
|
| 6711 |
```
|
| 6712 |
|
| 6713 |
+
*Preconditions:* `ranges::distance(r) > 0`. For the overloads in
|
| 6714 |
+
namespace `std`, `T` meets the *Cpp17CopyConstructible* requirements.
|
| 6715 |
+
For the first form, `T` meets the *Cpp17LessThanComparable* requirements
|
| 6716 |
+
([[cpp17.lessthancomparable]]).
|
| 6717 |
|
| 6718 |
+
*Returns:* The smallest value in the input range.
|
| 6719 |
|
| 6720 |
+
*Remarks:* Returns a copy of the leftmost element when several elements
|
| 6721 |
+
are equivalent to the smallest. An invocation may explicitly specify an
|
| 6722 |
+
argument for the template parameter `T` of the overloads in namespace
|
| 6723 |
+
`std`.
|
| 6724 |
|
| 6725 |
+
*Complexity:* Exactly `ranges::distance(r) - 1` comparisons and twice as
|
| 6726 |
+
many applications of the projection, if any.
|
| 6727 |
|
| 6728 |
``` cpp
|
| 6729 |
+
template<class T>
|
| 6730 |
+
constexpr const T& max(const T& a, const T& b);
|
| 6731 |
template<class T, class Compare>
|
| 6732 |
constexpr const T& max(const T& a, const T& b, Compare comp);
|
| 6733 |
+
|
| 6734 |
+
template<class T, class Proj = identity,
|
| 6735 |
+
indirect_strict_weak_order<projected<const T*, Proj>> Comp = ranges::less>
|
| 6736 |
+
constexpr const T& ranges::max(const T& a, const T& b, Comp comp = {}, Proj proj = {});
|
| 6737 |
```
|
| 6738 |
|
| 6739 |
+
*Preconditions:* For the first form, `T` meets the
|
| 6740 |
+
*Cpp17LessThanComparable* requirements ([[cpp17.lessthancomparable]]).
|
| 6741 |
|
| 6742 |
*Returns:* The larger value.
|
| 6743 |
|
| 6744 |
*Remarks:* Returns the first argument when the arguments are equivalent.
|
| 6745 |
+
An invocation may explicitly specify an argument for the template
|
| 6746 |
+
parameter `T` of the overloads in namespace `std`.
|
| 6747 |
|
| 6748 |
+
*Complexity:* Exactly one comparison and two applications of the
|
| 6749 |
+
projection, if any.
|
| 6750 |
|
| 6751 |
``` cpp
|
| 6752 |
template<class T>
|
| 6753 |
+
constexpr T max(initializer_list<T> r);
|
| 6754 |
template<class T, class Compare>
|
| 6755 |
+
constexpr T max(initializer_list<T> r, Compare comp);
|
| 6756 |
+
|
| 6757 |
+
template<copyable T, class Proj = identity,
|
| 6758 |
+
indirect_strict_weak_order<projected<const T*, Proj>> Comp = ranges::less>
|
| 6759 |
+
constexpr T ranges::max(initializer_list<T> r, Comp comp = {}, Proj proj = {});
|
| 6760 |
+
template<input_range R, class Proj = identity,
|
| 6761 |
+
indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less>
|
| 6762 |
+
requires indirectly_copyable_storable<iterator_t<R>, range_value_t<R>*>
|
| 6763 |
+
constexpr range_value_t<R>
|
| 6764 |
+
ranges::max(R&& r, Comp comp = {}, Proj proj = {});
|
| 6765 |
```
|
| 6766 |
|
| 6767 |
+
*Preconditions:* `ranges::distance(r) > 0`. For the overloads in
|
| 6768 |
+
namespace `std`, `T` meets the *Cpp17CopyConstructible* requirements.
|
| 6769 |
+
For the first form, `T` meets the *Cpp17LessThanComparable* requirements
|
| 6770 |
+
([[cpp17.lessthancomparable]]).
|
| 6771 |
|
| 6772 |
+
*Returns:* The largest value in the input range.
|
| 6773 |
|
| 6774 |
+
*Remarks:* Returns a copy of the leftmost element when several elements
|
| 6775 |
+
are equivalent to the largest. An invocation may explicitly specify an
|
| 6776 |
+
argument for the template parameter `T` of the overloads in namespace
|
| 6777 |
+
`std`.
|
| 6778 |
|
| 6779 |
+
*Complexity:* Exactly `ranges::distance(r) - 1` comparisons and twice as
|
| 6780 |
+
many applications of the projection, if any.
|
| 6781 |
|
| 6782 |
``` cpp
|
| 6783 |
+
template<class T>
|
| 6784 |
+
constexpr pair<const T&, const T&> minmax(const T& a, const T& b);
|
| 6785 |
template<class T, class Compare>
|
| 6786 |
constexpr pair<const T&, const T&> minmax(const T& a, const T& b, Compare comp);
|
| 6787 |
+
|
| 6788 |
+
template<class T, class Proj = identity,
|
| 6789 |
+
indirect_strict_weak_order<projected<const T*, Proj>> Comp = ranges::less>
|
| 6790 |
+
constexpr ranges::minmax_result<const T&>
|
| 6791 |
+
ranges::minmax(const T& a, const T& b, Comp comp = {}, Proj proj = {});
|
| 6792 |
```
|
| 6793 |
|
| 6794 |
+
*Preconditions:* For the first form, `T` meets the
|
| 6795 |
+
*Cpp17LessThanComparable* requirements ([[cpp17.lessthancomparable]]).
|
| 6796 |
|
| 6797 |
+
*Returns:* `{b, a}` if `b` is smaller than `a`, and `{a, b}` otherwise.
|
|
|
|
| 6798 |
|
| 6799 |
+
*Remarks:* An invocation may explicitly specify an argument for the
|
| 6800 |
+
template parameter `T` of the overloads in namespace `std`.
|
| 6801 |
|
| 6802 |
+
*Complexity:* Exactly one comparison and two applications of the
|
| 6803 |
+
projection, if any.
|
| 6804 |
|
| 6805 |
``` cpp
|
| 6806 |
template<class T>
|
| 6807 |
constexpr pair<T, T> minmax(initializer_list<T> t);
|
| 6808 |
template<class T, class Compare>
|
| 6809 |
constexpr pair<T, T> minmax(initializer_list<T> t, Compare comp);
|
| 6810 |
+
|
| 6811 |
+
template<copyable T, class Proj = identity,
|
| 6812 |
+
indirect_strict_weak_order<projected<const T*, Proj>> Comp = ranges::less>
|
| 6813 |
+
constexpr ranges::minmax_result<T>
|
| 6814 |
+
ranges::minmax(initializer_list<T> r, Comp comp = {}, Proj proj = {});
|
| 6815 |
+
template<input_range R, class Proj = identity,
|
| 6816 |
+
indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less>
|
| 6817 |
+
requires indirectly_copyable_storable<iterator_t<R>, range_value_t<R>*>
|
| 6818 |
+
constexpr ranges::minmax_result<range_value_t<R>>
|
| 6819 |
+
ranges::minmax(R&& r, Comp comp = {}, Proj proj = {});
|
| 6820 |
```
|
| 6821 |
|
| 6822 |
+
*Preconditions:* `ranges::distance(r) > 0`. For the overloads in
|
| 6823 |
+
namespace `std`, `T` meets the *Cpp17CopyConstructible* requirements.
|
| 6824 |
+
For the first form, type `T` meets the *Cpp17LessThanComparable*
|
| 6825 |
+
requirements ([[cpp17.lessthancomparable]]).
|
| 6826 |
|
| 6827 |
+
*Returns:* Let `X` be the return type. Returns `X{x, y}`, where `x` is a
|
| 6828 |
+
copy of the leftmost element with the smallest value and `y` a copy of
|
| 6829 |
+
the rightmost element with the largest value in the input range.
|
| 6830 |
|
| 6831 |
+
*Remarks:* An invocation may explicitly specify an argument for the
|
| 6832 |
+
template parameter `T` of the overloads in namespace `std`.
|
|
|
|
| 6833 |
|
| 6834 |
+
*Complexity:* At most (3/2)`ranges::distance(r)` applications of the
|
| 6835 |
+
corresponding predicate and twice as many applications of the
|
| 6836 |
+
projection, if any.
|
| 6837 |
|
| 6838 |
``` cpp
|
| 6839 |
template<class ForwardIterator>
|
| 6840 |
constexpr ForwardIterator min_element(ForwardIterator first, ForwardIterator last);
|
| 6841 |
|
|
|
|
| 6848 |
Compare comp);
|
| 6849 |
template<class ExecutionPolicy, class ForwardIterator, class Compare>
|
| 6850 |
ForwardIterator min_element(ExecutionPolicy&& exec,
|
| 6851 |
ForwardIterator first, ForwardIterator last,
|
| 6852 |
Compare comp);
|
| 6853 |
+
|
| 6854 |
+
template<forward_iterator I, sentinel_for<I> S, class Proj = identity,
|
| 6855 |
+
indirect_strict_weak_order<projected<I, Proj>> Comp = ranges::less>
|
| 6856 |
+
constexpr I ranges::min_element(I first, S last, Comp comp = {}, Proj proj = {});
|
| 6857 |
+
template<forward_range R, class Proj = identity,
|
| 6858 |
+
indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less>
|
| 6859 |
+
constexpr borrowed_iterator_t<R>
|
| 6860 |
+
ranges::min_element(R&& r, Comp comp = {}, Proj proj = {});
|
| 6861 |
```
|
| 6862 |
|
| 6863 |
+
Let `comp` be `less{}` and `proj` be `identity{}` for the overloads with
|
| 6864 |
+
no parameters by those names.
|
| 6865 |
+
|
| 6866 |
*Returns:* The first iterator `i` in the range \[`first`, `last`) such
|
| 6867 |
+
that for every iterator `j` in the range \[`first`, `last`),
|
|
|
|
|
|
|
| 6868 |
|
| 6869 |
+
``` cpp
|
| 6870 |
+
bool(invoke(comp, invoke(proj, *j), invoke(proj, *i)))
|
| 6871 |
+
```
|
| 6872 |
+
|
| 6873 |
+
is `false`. Returns `last` if `first == last`.
|
| 6874 |
+
|
| 6875 |
+
*Complexity:* Exactly max(`last - first - 1`, 0) comparisons and twice
|
| 6876 |
+
as many projections.
|
| 6877 |
|
| 6878 |
``` cpp
|
| 6879 |
template<class ForwardIterator>
|
| 6880 |
constexpr ForwardIterator max_element(ForwardIterator first, ForwardIterator last);
|
| 6881 |
template<class ExecutionPolicy, class ForwardIterator>
|
|
|
|
| 6887 |
Compare comp);
|
| 6888 |
template<class ExecutionPolicy, class ForwardIterator, class Compare>
|
| 6889 |
ForwardIterator max_element(ExecutionPolicy&& exec,
|
| 6890 |
ForwardIterator first, ForwardIterator last,
|
| 6891 |
Compare comp);
|
| 6892 |
+
|
| 6893 |
+
template<forward_iterator I, sentinel_for<I> S, class Proj = identity,
|
| 6894 |
+
indirect_strict_weak_order<projected<I, Proj>> Comp = ranges::less>
|
| 6895 |
+
constexpr I ranges::max_element(I first, S last, Comp comp = {}, Proj proj = {});
|
| 6896 |
+
template<forward_range R, class Proj = identity,
|
| 6897 |
+
indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less>
|
| 6898 |
+
constexpr borrowed_iterator_t<R>
|
| 6899 |
+
ranges::max_element(R&& r, Comp comp = {}, Proj proj = {});
|
| 6900 |
```
|
| 6901 |
|
| 6902 |
+
Let `comp` be `less{}` and `proj` be `identity{}` for the overloads with
|
| 6903 |
+
no parameters by those names.
|
| 6904 |
+
|
| 6905 |
*Returns:* The first iterator `i` in the range \[`first`, `last`) such
|
| 6906 |
+
that for every iterator `j` in the range \[`first`, `last`),
|
|
|
|
|
|
|
| 6907 |
|
| 6908 |
+
``` cpp
|
| 6909 |
+
bool(invoke(comp, invoke(proj, *i), invoke(proj, *j)))
|
| 6910 |
+
```
|
| 6911 |
+
|
| 6912 |
+
is `false`. Returns `last` if `first == last`.
|
| 6913 |
+
|
| 6914 |
+
*Complexity:* Exactly max(`last - first - 1`, 0) comparisons and twice
|
| 6915 |
+
as many projections.
|
| 6916 |
|
| 6917 |
``` cpp
|
| 6918 |
template<class ForwardIterator>
|
| 6919 |
constexpr pair<ForwardIterator, ForwardIterator>
|
| 6920 |
minmax_element(ForwardIterator first, ForwardIterator last);
|
|
|
|
| 6928 |
minmax_element(ForwardIterator first, ForwardIterator last, Compare comp);
|
| 6929 |
template<class ExecutionPolicy, class ForwardIterator, class Compare>
|
| 6930 |
pair<ForwardIterator, ForwardIterator>
|
| 6931 |
minmax_element(ExecutionPolicy&& exec,
|
| 6932 |
ForwardIterator first, ForwardIterator last, Compare comp);
|
| 6933 |
+
|
| 6934 |
+
template<forward_iterator I, sentinel_for<I> S, class Proj = identity,
|
| 6935 |
+
indirect_strict_weak_order<projected<I, Proj>> Comp = ranges::less>
|
| 6936 |
+
constexpr ranges::minmax_result<I>
|
| 6937 |
+
ranges::minmax_element(I first, S last, Comp comp = {}, Proj proj = {});
|
| 6938 |
+
template<forward_range R, class Proj = identity,
|
| 6939 |
+
indirect_strict_weak_order<projected<iterator_t<R>, Proj>> Comp = ranges::less>
|
| 6940 |
+
constexpr ranges::minmax_result<borrowed_iterator_t<R>>
|
| 6941 |
+
ranges::minmax_element(R&& r, Comp comp = {}, Proj proj = {});
|
| 6942 |
```
|
| 6943 |
|
| 6944 |
+
*Returns:* `{first, first}` if \[`first`, `last`) is empty, otherwise
|
| 6945 |
+
`{m, M}`, where `m` is the first iterator in \[`first`, `last`) such
|
| 6946 |
+
that no iterator in the range refers to a smaller element, and where `M`
|
| 6947 |
+
is the last iterator[^5] in \[`first`, `last`) such that no iterator in
|
| 6948 |
+
the range refers to a larger element.
|
| 6949 |
|
| 6950 |
+
*Complexity:* Let N be `last - first`. At most
|
| 6951 |
+
$\max(\bigl\lfloor{\frac{3}{2}} (N-1)\bigr\rfloor, 0)$ comparisons and
|
| 6952 |
+
twice as many applications of the projection, if any.
|
| 6953 |
|
| 6954 |
### Bounded value <a id="alg.clamp">[[alg.clamp]]</a>
|
| 6955 |
|
| 6956 |
``` cpp
|
| 6957 |
template<class T>
|
| 6958 |
constexpr const T& clamp(const T& v, const T& lo, const T& hi);
|
| 6959 |
template<class T, class Compare>
|
| 6960 |
constexpr const T& clamp(const T& v, const T& lo, const T& hi, Compare comp);
|
| 6961 |
+
template<class T, class Proj = identity,
|
| 6962 |
+
indirect_strict_weak_order<projected<const T*, Proj>> Comp = ranges::less>
|
| 6963 |
+
constexpr const T&
|
| 6964 |
+
ranges::clamp(const T& v, const T& lo, const T& hi, Comp comp = {}, Proj proj = {});
|
| 6965 |
```
|
| 6966 |
|
| 6967 |
+
Let `comp` be `less{}` for the overloads with no parameter `comp`, and
|
| 6968 |
+
let `proj` be `identity{}` for the overloads with no parameter `proj`.
|
|
|
|
| 6969 |
|
| 6970 |
+
*Preconditions:* `bool(comp(proj(hi), proj(lo)))` is `false`. For the
|
| 6971 |
+
first form, type `T` meets the *Cpp17LessThanComparable* requirements
|
| 6972 |
+
([[cpp17.lessthancomparable]]).
|
| 6973 |
+
|
| 6974 |
+
*Returns:* `lo` if `bool(comp(proj(v), proj(lo)))` is `true`, `hi` if
|
| 6975 |
+
`bool(comp(proj(hi), proj(v)))` is `true`, otherwise `v`.
|
| 6976 |
|
| 6977 |
[*Note 1*: If NaN is avoided, `T` can be a floating-point
|
| 6978 |
type. — *end note*]
|
| 6979 |
|
| 6980 |
+
*Complexity:* At most two comparisons and three applications of the
|
| 6981 |
+
projection.
|
| 6982 |
|
| 6983 |
### Lexicographical comparison <a id="alg.lex.comparison">[[alg.lex.comparison]]</a>
|
| 6984 |
|
| 6985 |
``` cpp
|
| 6986 |
template<class InputIterator1, class InputIterator2>
|
| 6987 |
+
constexpr bool
|
| 6988 |
lexicographical_compare(InputIterator1 first1, InputIterator1 last1,
|
| 6989 |
InputIterator2 first2, InputIterator2 last2);
|
| 6990 |
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 6991 |
bool
|
| 6992 |
lexicographical_compare(ExecutionPolicy&& exec,
|
| 6993 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 6994 |
ForwardIterator2 first2, ForwardIterator2 last2);
|
| 6995 |
|
| 6996 |
template<class InputIterator1, class InputIterator2, class Compare>
|
| 6997 |
+
constexpr bool
|
| 6998 |
lexicographical_compare(InputIterator1 first1, InputIterator1 last1,
|
| 6999 |
InputIterator2 first2, InputIterator2 last2,
|
| 7000 |
Compare comp);
|
| 7001 |
+
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 7002 |
+
class Compare>
|
| 7003 |
bool
|
| 7004 |
lexicographical_compare(ExecutionPolicy&& exec,
|
| 7005 |
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 7006 |
ForwardIterator2 first2, ForwardIterator2 last2,
|
| 7007 |
Compare comp);
|
| 7008 |
+
|
| 7009 |
+
template<input_iterator I1, sentinel_for<I1> S1, input_iterator I2, sentinel_for<I2> S2,
|
| 7010 |
+
class Proj1 = identity, class Proj2 = identity,
|
| 7011 |
+
indirect_strict_weak_order<projected<I1, Proj1>,
|
| 7012 |
+
projected<I2, Proj2>> Comp = ranges::less>
|
| 7013 |
+
constexpr bool
|
| 7014 |
+
ranges::lexicographical_compare(I1 first1, S1 last1, I2 first2, S2 last2,
|
| 7015 |
+
Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 7016 |
+
template<input_range R1, input_range R2, class Proj1 = identity,
|
| 7017 |
+
class Proj2 = identity,
|
| 7018 |
+
indirect_strict_weak_order<projected<iterator_t<R1>, Proj1>,
|
| 7019 |
+
projected<iterator_t<R2>, Proj2>> Comp = ranges::less>
|
| 7020 |
+
constexpr bool
|
| 7021 |
+
ranges::lexicographical_compare(R1&& r1, R2&& r2, Comp comp = {},
|
| 7022 |
+
Proj1 proj1 = {}, Proj2 proj2 = {});
|
| 7023 |
```
|
| 7024 |
|
| 7025 |
+
*Returns:* `true` if and only if the sequence of elements defined by the
|
| 7026 |
+
range \[`first1`, `last1`) is lexicographically less than the sequence
|
| 7027 |
+
of elements defined by the range \[`first2`, `last2`).
|
|
|
|
| 7028 |
|
| 7029 |
*Complexity:* At most 2 min(`last1 - first1`, `last2 - first2`)
|
| 7030 |
+
applications of the corresponding comparison and each projection, if
|
| 7031 |
+
any.
|
| 7032 |
|
| 7033 |
*Remarks:* If two sequences have the same number of elements and their
|
| 7034 |
corresponding elements (if any) are equivalent, then neither sequence is
|
| 7035 |
+
lexicographically less than the other. If one sequence is a proper
|
| 7036 |
+
prefix of the other, then the shorter sequence is lexicographically less
|
| 7037 |
+
than the longer sequence. Otherwise, the lexicographical comparison of
|
| 7038 |
+
the sequences yields the same result as the comparison of the first
|
| 7039 |
corresponding pair of elements that are not equivalent.
|
| 7040 |
|
| 7041 |
[*Example 1*:
|
| 7042 |
|
| 7043 |
+
`ranges::lexicographical_compare(I1, S1, I2, S2, Comp, Proj1, Proj2)`
|
| 7044 |
+
could be implemented as:
|
| 7045 |
|
| 7046 |
``` cpp
|
| 7047 |
for ( ; first1 != last1 && first2 != last2 ; ++first1, (void) ++first2) {
|
| 7048 |
+
if (invoke(comp, invoke(proj1, *first1), invoke(proj2, *first2))) return true;
|
| 7049 |
+
if (invoke(comp, invoke(proj2, *first2), invoke(proj1, *first1))) return false;
|
| 7050 |
}
|
| 7051 |
return first1 == last1 && first2 != last2;
|
| 7052 |
```
|
| 7053 |
|
| 7054 |
— *end example*]
|
| 7055 |
|
| 7056 |
[*Note 1*: An empty sequence is lexicographically less than any
|
| 7057 |
non-empty sequence, but not less than any empty sequence. — *end note*]
|
| 7058 |
|
| 7059 |
+
### Three-way comparison algorithms <a id="alg.three.way">[[alg.three.way]]</a>
|
| 7060 |
+
|
| 7061 |
+
``` cpp
|
| 7062 |
+
template<class InputIterator1, class InputIterator2, class Cmp>
|
| 7063 |
+
constexpr auto
|
| 7064 |
+
lexicographical_compare_three_way(InputIterator1 b1, InputIterator1 e1,
|
| 7065 |
+
InputIterator2 b2, InputIterator2 e2,
|
| 7066 |
+
Cmp comp)
|
| 7067 |
+
-> decltype(comp(*b1, *b2));
|
| 7068 |
+
```
|
| 7069 |
+
|
| 7070 |
+
*Mandates:* `decltype(comp(*b1, *b2))` is a comparison category type.
|
| 7071 |
+
|
| 7072 |
+
*Effects:* Lexicographically compares two ranges and produces a result
|
| 7073 |
+
of the strongest applicable comparison category type. Equivalent to:
|
| 7074 |
+
|
| 7075 |
+
``` cpp
|
| 7076 |
+
for ( ; b1 != e1 && b2 != e2; void(++b1), void(++b2) )
|
| 7077 |
+
if (auto cmp = comp(*b1,*b2); cmp != 0)
|
| 7078 |
+
return cmp;
|
| 7079 |
+
return b1 != e1 ? strong_ordering::greater :
|
| 7080 |
+
b2 != e2 ? strong_ordering::less :
|
| 7081 |
+
strong_ordering::equal;
|
| 7082 |
+
```
|
| 7083 |
+
|
| 7084 |
+
``` cpp
|
| 7085 |
+
template<class InputIterator1, class InputIterator2>
|
| 7086 |
+
constexpr auto
|
| 7087 |
+
lexicographical_compare_three_way(InputIterator1 b1, InputIterator1 e1,
|
| 7088 |
+
InputIterator2 b2, InputIterator2 e2);
|
| 7089 |
+
```
|
| 7090 |
+
|
| 7091 |
+
*Effects:* Equivalent to:
|
| 7092 |
+
|
| 7093 |
+
``` cpp
|
| 7094 |
+
return lexicographical_compare_three_way(b1, e1, b2, e2, compare_three_way());
|
| 7095 |
+
```
|
| 7096 |
+
|
| 7097 |
### Permutation generators <a id="alg.permutation.generators">[[alg.permutation.generators]]</a>
|
| 7098 |
|
| 7099 |
``` cpp
|
| 7100 |
template<class BidirectionalIterator>
|
| 7101 |
+
constexpr bool next_permutation(BidirectionalIterator first,
|
| 7102 |
BidirectionalIterator last);
|
| 7103 |
|
| 7104 |
template<class BidirectionalIterator, class Compare>
|
| 7105 |
+
constexpr bool next_permutation(BidirectionalIterator first,
|
| 7106 |
BidirectionalIterator last, Compare comp);
|
| 7107 |
+
|
| 7108 |
+
template<bidirectional_iterator I, sentinel_for<I> S, class Comp = ranges::less,
|
| 7109 |
+
class Proj = identity>
|
| 7110 |
+
requires sortable<I, Comp, Proj>
|
| 7111 |
+
constexpr ranges::next_permutation_result<I>
|
| 7112 |
+
ranges::next_permutation(I first, S last, Comp comp = {}, Proj proj = {});
|
| 7113 |
+
template<bidirectional_range R, class Comp = ranges::less,
|
| 7114 |
+
class Proj = identity>
|
| 7115 |
+
requires sortable<iterator_t<R>, Comp, Proj>
|
| 7116 |
+
constexpr ranges::next_permutation_result<borrowed_iterator_t<R>>
|
| 7117 |
+
ranges::next_permutation(R&& r, Comp comp = {}, Proj proj = {});
|
| 7118 |
```
|
| 7119 |
|
| 7120 |
+
Let `comp` be `less{}` and `proj` be `identity{}` for overloads with no
|
| 7121 |
+
parameters by those names.
|
| 7122 |
+
|
| 7123 |
+
*Preconditions:* For the overloads in namespace `std`,
|
| 7124 |
+
`BidirectionalIterator` meets the *Cpp17ValueSwappable*
|
| 7125 |
+
requirements [[swappable.requirements]].
|
| 7126 |
|
| 7127 |
*Effects:* Takes a sequence defined by the range \[`first`, `last`) and
|
| 7128 |
transforms it into the next permutation. The next permutation is found
|
| 7129 |
by assuming that the set of all permutations is lexicographically sorted
|
| 7130 |
+
with respect to `comp` and `proj`. If no such permutation exists,
|
| 7131 |
+
transforms the sequence into the first permutation; that is, the
|
| 7132 |
+
ascendingly-sorted one.
|
| 7133 |
|
| 7134 |
+
*Returns:* Let `B` be `true` if a next permutation was found and
|
| 7135 |
+
otherwise `false`. Returns:
|
| 7136 |
+
|
| 7137 |
+
- `B` for the overloads in namespace `std`.
|
| 7138 |
+
- `{ last, B }` for the overloads in namespace `ranges`.
|
| 7139 |
|
| 7140 |
*Complexity:* At most `(last - first) / 2` swaps.
|
| 7141 |
|
| 7142 |
``` cpp
|
| 7143 |
template<class BidirectionalIterator>
|
| 7144 |
+
constexpr bool prev_permutation(BidirectionalIterator first,
|
| 7145 |
BidirectionalIterator last);
|
| 7146 |
|
| 7147 |
template<class BidirectionalIterator, class Compare>
|
| 7148 |
+
constexpr bool prev_permutation(BidirectionalIterator first,
|
| 7149 |
BidirectionalIterator last, Compare comp);
|
| 7150 |
+
|
| 7151 |
+
template<bidirectional_iterator I, sentinel_for<I> S, class Comp = ranges::less,
|
| 7152 |
+
class Proj = identity>
|
| 7153 |
+
requires sortable<I, Comp, Proj>
|
| 7154 |
+
constexpr ranges::prev_permutation_result<I>
|
| 7155 |
+
ranges::prev_permutation(I first, S last, Comp comp = {}, Proj proj = {});
|
| 7156 |
+
template<bidirectional_range R, class Comp = ranges::less,
|
| 7157 |
+
class Proj = identity>
|
| 7158 |
+
requires sortable<iterator_t<R>, Comp, Proj>
|
| 7159 |
+
constexpr ranges::prev_permutation_result<borrowed_iterator_t<R>>
|
| 7160 |
+
ranges::prev_permutation(R&& r, Comp comp = {}, Proj proj = {});
|
| 7161 |
```
|
| 7162 |
|
| 7163 |
+
Let `comp` be `less{}` and `proj` be `identity{}` for overloads with no
|
| 7164 |
+
parameters by those names.
|
| 7165 |
+
|
| 7166 |
+
*Preconditions:* For the overloads in namespace `std`,
|
| 7167 |
+
`BidirectionalIterator` meets the *Cpp17ValueSwappable*
|
| 7168 |
+
requirements [[swappable.requirements]].
|
| 7169 |
|
| 7170 |
*Effects:* Takes a sequence defined by the range \[`first`, `last`) and
|
| 7171 |
transforms it into the previous permutation. The previous permutation is
|
| 7172 |
found by assuming that the set of all permutations is lexicographically
|
| 7173 |
+
sorted with respect to `comp` and `proj`. If no such permutation exists,
|
| 7174 |
+
transforms the sequence into the last permutation; that is, the
|
| 7175 |
+
descendingly-sorted one.
|
| 7176 |
|
| 7177 |
+
*Returns:* Let `B` be `true` if a previous permutation was found and
|
| 7178 |
+
otherwise `false`. Returns:
|
| 7179 |
+
|
| 7180 |
+
- `B` for the overloads in namespace `std`.
|
| 7181 |
+
- `{ last, B }` for the overloads in namespace `ranges`.
|
| 7182 |
|
| 7183 |
*Complexity:* At most `(last - first) / 2` swaps.
|
| 7184 |
|
| 7185 |
+
## Header `<numeric>` synopsis <a id="numeric.ops.overview">[[numeric.ops.overview]]</a>
|
| 7186 |
+
|
| 7187 |
+
``` cpp
|
| 7188 |
+
namespace std {
|
| 7189 |
+
// [accumulate], accumulate
|
| 7190 |
+
template<class InputIterator, class T>
|
| 7191 |
+
constexpr T accumulate(InputIterator first, InputIterator last, T init);
|
| 7192 |
+
template<class InputIterator, class T, class BinaryOperation>
|
| 7193 |
+
constexpr T accumulate(InputIterator first, InputIterator last, T init,
|
| 7194 |
+
BinaryOperation binary_op);
|
| 7195 |
+
|
| 7196 |
+
// [reduce], reduce
|
| 7197 |
+
template<class InputIterator>
|
| 7198 |
+
constexpr typename iterator_traits<InputIterator>::value_type
|
| 7199 |
+
reduce(InputIterator first, InputIterator last);
|
| 7200 |
+
template<class InputIterator, class T>
|
| 7201 |
+
constexpr T reduce(InputIterator first, InputIterator last, T init);
|
| 7202 |
+
template<class InputIterator, class T, class BinaryOperation>
|
| 7203 |
+
constexpr T reduce(InputIterator first, InputIterator last, T init,
|
| 7204 |
+
BinaryOperation binary_op);
|
| 7205 |
+
template<class ExecutionPolicy, class ForwardIterator>
|
| 7206 |
+
typename iterator_traits<ForwardIterator>::value_type
|
| 7207 |
+
reduce(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 7208 |
+
ForwardIterator first, ForwardIterator last);
|
| 7209 |
+
template<class ExecutionPolicy, class ForwardIterator, class T>
|
| 7210 |
+
T reduce(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 7211 |
+
ForwardIterator first, ForwardIterator last, T init);
|
| 7212 |
+
template<class ExecutionPolicy, class ForwardIterator, class T, class BinaryOperation>
|
| 7213 |
+
T reduce(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 7214 |
+
ForwardIterator first, ForwardIterator last, T init, BinaryOperation binary_op);
|
| 7215 |
+
|
| 7216 |
+
// [inner.product], inner product
|
| 7217 |
+
template<class InputIterator1, class InputIterator2, class T>
|
| 7218 |
+
constexpr T inner_product(InputIterator1 first1, InputIterator1 last1,
|
| 7219 |
+
InputIterator2 first2, T init);
|
| 7220 |
+
template<class InputIterator1, class InputIterator2, class T,
|
| 7221 |
+
class BinaryOperation1, class BinaryOperation2>
|
| 7222 |
+
constexpr T inner_product(InputIterator1 first1, InputIterator1 last1,
|
| 7223 |
+
InputIterator2 first2, T init,
|
| 7224 |
+
BinaryOperation1 binary_op1, BinaryOperation2 binary_op2);
|
| 7225 |
+
|
| 7226 |
+
// [transform.reduce], transform reduce
|
| 7227 |
+
template<class InputIterator1, class InputIterator2, class T>
|
| 7228 |
+
constexpr T transform_reduce(InputIterator1 first1, InputIterator1 last1,
|
| 7229 |
+
InputIterator2 first2, T init);
|
| 7230 |
+
template<class InputIterator1, class InputIterator2, class T,
|
| 7231 |
+
class BinaryOperation1, class BinaryOperation2>
|
| 7232 |
+
constexpr T transform_reduce(InputIterator1 first1, InputIterator1 last1,
|
| 7233 |
+
InputIterator2 first2, T init,
|
| 7234 |
+
BinaryOperation1 binary_op1, BinaryOperation2 binary_op2);
|
| 7235 |
+
template<class InputIterator, class T,
|
| 7236 |
+
class BinaryOperation, class UnaryOperation>
|
| 7237 |
+
constexpr T transform_reduce(InputIterator first, InputIterator last, T init,
|
| 7238 |
+
BinaryOperation binary_op, UnaryOperation unary_op);
|
| 7239 |
+
template<class ExecutionPolicy,
|
| 7240 |
+
class ForwardIterator1, class ForwardIterator2, class T>
|
| 7241 |
+
T transform_reduce(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 7242 |
+
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 7243 |
+
ForwardIterator2 first2, T init);
|
| 7244 |
+
template<class ExecutionPolicy,
|
| 7245 |
+
class ForwardIterator1, class ForwardIterator2, class T,
|
| 7246 |
+
class BinaryOperation1, class BinaryOperation2>
|
| 7247 |
+
T transform_reduce(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 7248 |
+
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 7249 |
+
ForwardIterator2 first2, T init,
|
| 7250 |
+
BinaryOperation1 binary_op1, BinaryOperation2 binary_op2);
|
| 7251 |
+
template<class ExecutionPolicy, class ForwardIterator, class T,
|
| 7252 |
+
class BinaryOperation, class UnaryOperation>
|
| 7253 |
+
T transform_reduce(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 7254 |
+
ForwardIterator first, ForwardIterator last, T init,
|
| 7255 |
+
BinaryOperation binary_op, UnaryOperation unary_op);
|
| 7256 |
+
|
| 7257 |
+
// [partial.sum], partial sum
|
| 7258 |
+
template<class InputIterator, class OutputIterator>
|
| 7259 |
+
constexpr OutputIterator
|
| 7260 |
+
partial_sum(InputIterator first, InputIterator last,
|
| 7261 |
+
OutputIterator result);
|
| 7262 |
+
template<class InputIterator, class OutputIterator, class BinaryOperation>
|
| 7263 |
+
constexpr OutputIterator
|
| 7264 |
+
partial_sum(InputIterator first, InputIterator last,
|
| 7265 |
+
OutputIterator result, BinaryOperation binary_op);
|
| 7266 |
+
|
| 7267 |
+
// [exclusive.scan], exclusive scan
|
| 7268 |
+
template<class InputIterator, class OutputIterator, class T>
|
| 7269 |
+
constexpr OutputIterator
|
| 7270 |
+
exclusive_scan(InputIterator first, InputIterator last,
|
| 7271 |
+
OutputIterator result, T init);
|
| 7272 |
+
template<class InputIterator, class OutputIterator, class T, class BinaryOperation>
|
| 7273 |
+
constexpr OutputIterator
|
| 7274 |
+
exclusive_scan(InputIterator first, InputIterator last,
|
| 7275 |
+
OutputIterator result, T init, BinaryOperation binary_op);
|
| 7276 |
+
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class T>
|
| 7277 |
+
ForwardIterator2
|
| 7278 |
+
exclusive_scan(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 7279 |
+
ForwardIterator1 first, ForwardIterator1 last,
|
| 7280 |
+
ForwardIterator2 result, T init);
|
| 7281 |
+
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class T,
|
| 7282 |
+
class BinaryOperation>
|
| 7283 |
+
ForwardIterator2
|
| 7284 |
+
exclusive_scan(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 7285 |
+
ForwardIterator1 first, ForwardIterator1 last,
|
| 7286 |
+
ForwardIterator2 result, T init, BinaryOperation binary_op);
|
| 7287 |
+
|
| 7288 |
+
// [inclusive.scan], inclusive scan
|
| 7289 |
+
template<class InputIterator, class OutputIterator>
|
| 7290 |
+
constexpr OutputIterator
|
| 7291 |
+
inclusive_scan(InputIterator first, InputIterator last,
|
| 7292 |
+
OutputIterator result);
|
| 7293 |
+
template<class InputIterator, class OutputIterator, class BinaryOperation>
|
| 7294 |
+
constexpr OutputIterator
|
| 7295 |
+
inclusive_scan(InputIterator first, InputIterator last,
|
| 7296 |
+
OutputIterator result, BinaryOperation binary_op);
|
| 7297 |
+
template<class InputIterator, class OutputIterator, class BinaryOperation, class T>
|
| 7298 |
+
constexpr OutputIterator
|
| 7299 |
+
inclusive_scan(InputIterator first, InputIterator last,
|
| 7300 |
+
OutputIterator result, BinaryOperation binary_op, T init);
|
| 7301 |
+
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 7302 |
+
ForwardIterator2
|
| 7303 |
+
inclusive_scan(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 7304 |
+
ForwardIterator1 first, ForwardIterator1 last,
|
| 7305 |
+
ForwardIterator2 result);
|
| 7306 |
+
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 7307 |
+
class BinaryOperation>
|
| 7308 |
+
ForwardIterator2
|
| 7309 |
+
inclusive_scan(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 7310 |
+
ForwardIterator1 first, ForwardIterator1 last,
|
| 7311 |
+
ForwardIterator2 result, BinaryOperation binary_op);
|
| 7312 |
+
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 7313 |
+
class BinaryOperation, class T>
|
| 7314 |
+
ForwardIterator2
|
| 7315 |
+
inclusive_scan(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 7316 |
+
ForwardIterator1 first, ForwardIterator1 last,
|
| 7317 |
+
ForwardIterator2 result, BinaryOperation binary_op, T init);
|
| 7318 |
+
|
| 7319 |
+
// [transform.exclusive.scan], transform exclusive scan
|
| 7320 |
+
template<class InputIterator, class OutputIterator, class T,
|
| 7321 |
+
class BinaryOperation, class UnaryOperation>
|
| 7322 |
+
constexpr OutputIterator
|
| 7323 |
+
transform_exclusive_scan(InputIterator first, InputIterator last,
|
| 7324 |
+
OutputIterator result, T init,
|
| 7325 |
+
BinaryOperation binary_op, UnaryOperation unary_op);
|
| 7326 |
+
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class T,
|
| 7327 |
+
class BinaryOperation, class UnaryOperation>
|
| 7328 |
+
ForwardIterator2
|
| 7329 |
+
transform_exclusive_scan(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 7330 |
+
ForwardIterator1 first, ForwardIterator1 last,
|
| 7331 |
+
ForwardIterator2 result, T init,
|
| 7332 |
+
BinaryOperation binary_op, UnaryOperation unary_op);
|
| 7333 |
+
|
| 7334 |
+
// [transform.inclusive.scan], transform inclusive scan
|
| 7335 |
+
template<class InputIterator, class OutputIterator,
|
| 7336 |
+
class BinaryOperation, class UnaryOperation>
|
| 7337 |
+
constexpr OutputIterator
|
| 7338 |
+
transform_inclusive_scan(InputIterator first, InputIterator last,
|
| 7339 |
+
OutputIterator result,
|
| 7340 |
+
BinaryOperation binary_op, UnaryOperation unary_op);
|
| 7341 |
+
template<class InputIterator, class OutputIterator,
|
| 7342 |
+
class BinaryOperation, class UnaryOperation, class T>
|
| 7343 |
+
constexpr OutputIterator
|
| 7344 |
+
transform_inclusive_scan(InputIterator first, InputIterator last,
|
| 7345 |
+
OutputIterator result,
|
| 7346 |
+
BinaryOperation binary_op, UnaryOperation unary_op, T init);
|
| 7347 |
+
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 7348 |
+
class BinaryOperation, class UnaryOperation>
|
| 7349 |
+
ForwardIterator2
|
| 7350 |
+
transform_inclusive_scan(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 7351 |
+
ForwardIterator1 first, ForwardIterator1 last,
|
| 7352 |
+
ForwardIterator2 result, BinaryOperation binary_op,
|
| 7353 |
+
UnaryOperation unary_op);
|
| 7354 |
+
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 7355 |
+
class BinaryOperation, class UnaryOperation, class T>
|
| 7356 |
+
ForwardIterator2
|
| 7357 |
+
transform_inclusive_scan(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 7358 |
+
ForwardIterator1 first, ForwardIterator1 last,
|
| 7359 |
+
ForwardIterator2 result,
|
| 7360 |
+
BinaryOperation binary_op, UnaryOperation unary_op, T init);
|
| 7361 |
+
|
| 7362 |
+
// [adjacent.difference], adjacent difference
|
| 7363 |
+
template<class InputIterator, class OutputIterator>
|
| 7364 |
+
constexpr OutputIterator
|
| 7365 |
+
adjacent_difference(InputIterator first, InputIterator last,
|
| 7366 |
+
OutputIterator result);
|
| 7367 |
+
template<class InputIterator, class OutputIterator, class BinaryOperation>
|
| 7368 |
+
constexpr OutputIterator
|
| 7369 |
+
adjacent_difference(InputIterator first, InputIterator last,
|
| 7370 |
+
OutputIterator result, BinaryOperation binary_op);
|
| 7371 |
+
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 7372 |
+
ForwardIterator2
|
| 7373 |
+
adjacent_difference(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 7374 |
+
ForwardIterator1 first, ForwardIterator1 last,
|
| 7375 |
+
ForwardIterator2 result);
|
| 7376 |
+
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 7377 |
+
class BinaryOperation>
|
| 7378 |
+
ForwardIterator2
|
| 7379 |
+
adjacent_difference(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
|
| 7380 |
+
ForwardIterator1 first, ForwardIterator1 last,
|
| 7381 |
+
ForwardIterator2 result, BinaryOperation binary_op);
|
| 7382 |
+
|
| 7383 |
+
// [numeric.iota], iota
|
| 7384 |
+
template<class ForwardIterator, class T>
|
| 7385 |
+
constexpr void iota(ForwardIterator first, ForwardIterator last, T value);
|
| 7386 |
+
|
| 7387 |
+
// [numeric.ops.gcd], greatest common divisor
|
| 7388 |
+
template<class M, class N>
|
| 7389 |
+
constexpr common_type_t<M,N> gcd(M m, N n);
|
| 7390 |
+
|
| 7391 |
+
// [numeric.ops.lcm], least common multiple
|
| 7392 |
+
template<class M, class N>
|
| 7393 |
+
constexpr common_type_t<M,N> lcm(M m, N n);
|
| 7394 |
+
|
| 7395 |
+
// [numeric.ops.midpoint], midpoint
|
| 7396 |
+
template<class T>
|
| 7397 |
+
constexpr T midpoint(T a, T b) noexcept;
|
| 7398 |
+
template<class T>
|
| 7399 |
+
constexpr T* midpoint(T* a, T* b);
|
| 7400 |
+
}
|
| 7401 |
+
```
|
| 7402 |
+
|
| 7403 |
+
## Generalized numeric operations <a id="numeric.ops">[[numeric.ops]]</a>
|
| 7404 |
+
|
| 7405 |
+
[*Note 1*: The use of closed ranges as well as semi-open ranges to
|
| 7406 |
+
specify requirements throughout this subclause is
|
| 7407 |
+
intentional. — *end note*]
|
| 7408 |
+
|
| 7409 |
+
### Definitions <a id="numerics.defns">[[numerics.defns]]</a>
|
| 7410 |
+
|
| 7411 |
+
Define `GENERALIZED_NONCOMMUTATIVE_SUM(op, a1, ..., aN)` as follows:
|
| 7412 |
+
|
| 7413 |
+
- `a1` when `N` is `1`, otherwise
|
| 7414 |
+
- `op(GENERALIZED_NONCOMMUTATIVE_SUM(op, a1, ..., aK),`
|
| 7415 |
+
`\phantom{op(}GENERALIZED_NONCOMMUTATIVE_SUM(op, aM, ..., aN))` for
|
| 7416 |
+
any `K` where 1 < K+1 = M ≤ N.
|
| 7417 |
+
|
| 7418 |
+
Define `GENERALIZED_SUM(op, a1, ..., aN)` as
|
| 7419 |
+
`GENERALIZED_NONCOMMUTATIVE_SUM(op, b1, ..., bN)`, where `b1, ..., bN`
|
| 7420 |
+
may be any permutation of `a1, ..., aN`.
|
| 7421 |
+
|
| 7422 |
+
### Accumulate <a id="accumulate">[[accumulate]]</a>
|
| 7423 |
+
|
| 7424 |
+
``` cpp
|
| 7425 |
+
template<class InputIterator, class T>
|
| 7426 |
+
constexpr T accumulate(InputIterator first, InputIterator last, T init);
|
| 7427 |
+
template<class InputIterator, class T, class BinaryOperation>
|
| 7428 |
+
constexpr T accumulate(InputIterator first, InputIterator last, T init,
|
| 7429 |
+
BinaryOperation binary_op);
|
| 7430 |
+
```
|
| 7431 |
+
|
| 7432 |
+
*Preconditions:* `T` meets the *Cpp17CopyConstructible*
|
| 7433 |
+
([[cpp17.copyconstructible]]) and *Cpp17CopyAssignable*
|
| 7434 |
+
([[cpp17.copyassignable]]) requirements. In the range \[`first`,
|
| 7435 |
+
`last`\], `binary_op` neither modifies elements nor invalidates
|
| 7436 |
+
iterators or subranges. [^6]
|
| 7437 |
+
|
| 7438 |
+
*Effects:* Computes its result by initializing the accumulator `acc`
|
| 7439 |
+
with the initial value `init` and then modifies it with
|
| 7440 |
+
`acc = std::move(acc) + *i` or `acc = binary_op(std::move(acc), *i)` for
|
| 7441 |
+
every iterator `i` in the range \[`first`, `last`) in order. [^7]
|
| 7442 |
+
|
| 7443 |
+
### Reduce <a id="reduce">[[reduce]]</a>
|
| 7444 |
+
|
| 7445 |
+
``` cpp
|
| 7446 |
+
template<class InputIterator>
|
| 7447 |
+
constexpr typename iterator_traits<InputIterator>::value_type
|
| 7448 |
+
reduce(InputIterator first, InputIterator last);
|
| 7449 |
+
```
|
| 7450 |
+
|
| 7451 |
+
*Effects:* Equivalent to:
|
| 7452 |
+
|
| 7453 |
+
``` cpp
|
| 7454 |
+
return reduce(first, last,
|
| 7455 |
+
typename iterator_traits<InputIterator>::value_type{});
|
| 7456 |
+
```
|
| 7457 |
+
|
| 7458 |
+
``` cpp
|
| 7459 |
+
template<class ExecutionPolicy, class ForwardIterator>
|
| 7460 |
+
typename iterator_traits<ForwardIterator>::value_type
|
| 7461 |
+
reduce(ExecutionPolicy&& exec,
|
| 7462 |
+
ForwardIterator first, ForwardIterator last);
|
| 7463 |
+
```
|
| 7464 |
+
|
| 7465 |
+
*Effects:* Equivalent to:
|
| 7466 |
+
|
| 7467 |
+
``` cpp
|
| 7468 |
+
return reduce(std::forward<ExecutionPolicy>(exec), first, last,
|
| 7469 |
+
typename iterator_traits<ForwardIterator>::value_type{});
|
| 7470 |
+
```
|
| 7471 |
+
|
| 7472 |
+
``` cpp
|
| 7473 |
+
template<class InputIterator, class T>
|
| 7474 |
+
constexpr T reduce(InputIterator first, InputIterator last, T init);
|
| 7475 |
+
```
|
| 7476 |
+
|
| 7477 |
+
*Effects:* Equivalent to:
|
| 7478 |
+
|
| 7479 |
+
``` cpp
|
| 7480 |
+
return reduce(first, last, init, plus<>());
|
| 7481 |
+
```
|
| 7482 |
+
|
| 7483 |
+
``` cpp
|
| 7484 |
+
template<class ExecutionPolicy, class ForwardIterator, class T>
|
| 7485 |
+
T reduce(ExecutionPolicy&& exec,
|
| 7486 |
+
ForwardIterator first, ForwardIterator last, T init);
|
| 7487 |
+
```
|
| 7488 |
+
|
| 7489 |
+
*Effects:* Equivalent to:
|
| 7490 |
+
|
| 7491 |
+
``` cpp
|
| 7492 |
+
return reduce(std::forward<ExecutionPolicy>(exec), first, last, init, plus<>());
|
| 7493 |
+
```
|
| 7494 |
+
|
| 7495 |
+
``` cpp
|
| 7496 |
+
template<class InputIterator, class T, class BinaryOperation>
|
| 7497 |
+
constexpr T reduce(InputIterator first, InputIterator last, T init,
|
| 7498 |
+
BinaryOperation binary_op);
|
| 7499 |
+
template<class ExecutionPolicy, class ForwardIterator, class T, class BinaryOperation>
|
| 7500 |
+
T reduce(ExecutionPolicy&& exec,
|
| 7501 |
+
ForwardIterator first, ForwardIterator last, T init,
|
| 7502 |
+
BinaryOperation binary_op);
|
| 7503 |
+
```
|
| 7504 |
+
|
| 7505 |
+
*Mandates:* All of
|
| 7506 |
+
|
| 7507 |
+
- `binary_op(init, *first)`,
|
| 7508 |
+
- `binary_op(*first, init)`,
|
| 7509 |
+
- `binary_op(init, init)`, and
|
| 7510 |
+
- `binary_op(*first, *first)`
|
| 7511 |
+
|
| 7512 |
+
are convertible to `T`.
|
| 7513 |
+
|
| 7514 |
+
*Preconditions:*
|
| 7515 |
+
|
| 7516 |
+
- `T` meets the *Cpp17MoveConstructible* ([[cpp17.moveconstructible]])
|
| 7517 |
+
requirements.
|
| 7518 |
+
- `binary_op` neither invalidates iterators or subranges, nor modifies
|
| 7519 |
+
elements in the range \[`first`, `last`\].
|
| 7520 |
+
|
| 7521 |
+
*Returns:* *GENERALIZED_SUM*(binary_op, init, \*i, ...) for every `i` in
|
| 7522 |
+
\[`first`, `last`).
|
| 7523 |
+
|
| 7524 |
+
*Complexity:* 𝑂(`last - first`) applications of `binary_op`.
|
| 7525 |
+
|
| 7526 |
+
[*Note 1*: The difference between `reduce` and `accumulate` is that
|
| 7527 |
+
`reduce` applies `binary_op` in an unspecified order, which yields a
|
| 7528 |
+
nondeterministic result for non-associative or non-commutative
|
| 7529 |
+
`binary_op` such as floating-point addition. — *end note*]
|
| 7530 |
+
|
| 7531 |
+
### Inner product <a id="inner.product">[[inner.product]]</a>
|
| 7532 |
+
|
| 7533 |
+
``` cpp
|
| 7534 |
+
template<class InputIterator1, class InputIterator2, class T>
|
| 7535 |
+
constexpr T inner_product(InputIterator1 first1, InputIterator1 last1,
|
| 7536 |
+
InputIterator2 first2, T init);
|
| 7537 |
+
template<class InputIterator1, class InputIterator2, class T,
|
| 7538 |
+
class BinaryOperation1, class BinaryOperation2>
|
| 7539 |
+
constexpr T inner_product(InputIterator1 first1, InputIterator1 last1,
|
| 7540 |
+
InputIterator2 first2, T init,
|
| 7541 |
+
BinaryOperation1 binary_op1,
|
| 7542 |
+
BinaryOperation2 binary_op2);
|
| 7543 |
+
```
|
| 7544 |
+
|
| 7545 |
+
*Preconditions:* `T` meets the *Cpp17CopyConstructible*
|
| 7546 |
+
([[cpp17.copyconstructible]]) and *Cpp17CopyAssignable*
|
| 7547 |
+
([[cpp17.copyassignable]]) requirements. In the ranges \[`first1`,
|
| 7548 |
+
`last1`\] and \[`first2`, `first2 + (last1 - first1)`\] `binary_op1` and
|
| 7549 |
+
`binary_op2` neither modifies elements nor invalidates iterators or
|
| 7550 |
+
subranges. [^8]
|
| 7551 |
+
|
| 7552 |
+
*Effects:* Computes its result by initializing the accumulator `acc`
|
| 7553 |
+
with the initial value `init` and then modifying it with
|
| 7554 |
+
`acc = std::move(acc) + (*i1) * (*i2)` or
|
| 7555 |
+
`acc = binary_op1(std::move(acc), binary_op2(*i1, *i2))` for every
|
| 7556 |
+
iterator `i1` in the range \[`first1`, `last1`) and iterator `i2` in the
|
| 7557 |
+
range \[`first2`, `first2 + (last1 - first1)`) in order.
|
| 7558 |
+
|
| 7559 |
+
### Transform reduce <a id="transform.reduce">[[transform.reduce]]</a>
|
| 7560 |
+
|
| 7561 |
+
``` cpp
|
| 7562 |
+
template<class InputIterator1, class InputIterator2, class T>
|
| 7563 |
+
constexpr T transform_reduce(InputIterator1 first1, InputIterator1 last1,
|
| 7564 |
+
InputIterator2 first2,
|
| 7565 |
+
T init);
|
| 7566 |
+
```
|
| 7567 |
+
|
| 7568 |
+
*Effects:* Equivalent to:
|
| 7569 |
+
|
| 7570 |
+
``` cpp
|
| 7571 |
+
return transform_reduce(first1, last1, first2, init, plus<>(), multiplies<>());
|
| 7572 |
+
```
|
| 7573 |
+
|
| 7574 |
+
``` cpp
|
| 7575 |
+
template<class ExecutionPolicy,
|
| 7576 |
+
class ForwardIterator1, class ForwardIterator2, class T>
|
| 7577 |
+
T transform_reduce(ExecutionPolicy&& exec,
|
| 7578 |
+
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 7579 |
+
ForwardIterator2 first2,
|
| 7580 |
+
T init);
|
| 7581 |
+
```
|
| 7582 |
+
|
| 7583 |
+
*Effects:* Equivalent to:
|
| 7584 |
+
|
| 7585 |
+
``` cpp
|
| 7586 |
+
return transform_reduce(std::forward<ExecutionPolicy>(exec),
|
| 7587 |
+
first1, last1, first2, init, plus<>(), multiplies<>());
|
| 7588 |
+
```
|
| 7589 |
+
|
| 7590 |
+
``` cpp
|
| 7591 |
+
template<class InputIterator1, class InputIterator2, class T,
|
| 7592 |
+
class BinaryOperation1, class BinaryOperation2>
|
| 7593 |
+
constexpr T transform_reduce(InputIterator1 first1, InputIterator1 last1,
|
| 7594 |
+
InputIterator2 first2,
|
| 7595 |
+
T init,
|
| 7596 |
+
BinaryOperation1 binary_op1,
|
| 7597 |
+
BinaryOperation2 binary_op2);
|
| 7598 |
+
template<class ExecutionPolicy,
|
| 7599 |
+
class ForwardIterator1, class ForwardIterator2, class T,
|
| 7600 |
+
class BinaryOperation1, class BinaryOperation2>
|
| 7601 |
+
T transform_reduce(ExecutionPolicy&& exec,
|
| 7602 |
+
ForwardIterator1 first1, ForwardIterator1 last1,
|
| 7603 |
+
ForwardIterator2 first2,
|
| 7604 |
+
T init,
|
| 7605 |
+
BinaryOperation1 binary_op1,
|
| 7606 |
+
BinaryOperation2 binary_op2);
|
| 7607 |
+
```
|
| 7608 |
+
|
| 7609 |
+
*Mandates:* All of
|
| 7610 |
+
|
| 7611 |
+
- `binary_op1(init, init)`,
|
| 7612 |
+
- `binary_op1(init, binary_op2(*first1, *first2))`,
|
| 7613 |
+
- `binary_op1(binary_op2(*first1, *first2), init)`, and
|
| 7614 |
+
- `binary_op1(binary_op2(*first1, *first2), binary_op2(*first1, *first2))`
|
| 7615 |
+
|
| 7616 |
+
are convertible to `T`.
|
| 7617 |
+
|
| 7618 |
+
*Preconditions:*
|
| 7619 |
+
|
| 7620 |
+
- `T` meets the *Cpp17MoveConstructible* ([[cpp17.moveconstructible]])
|
| 7621 |
+
requirements.
|
| 7622 |
+
- Neither `binary_op1` nor `binary_op2` invalidates subranges, nor
|
| 7623 |
+
modifies elements in the ranges \[`first1`, `last1`\] and \[`first2`,
|
| 7624 |
+
`first2 + (last1 - first1)`\].
|
| 7625 |
+
|
| 7626 |
+
*Returns:*
|
| 7627 |
+
|
| 7628 |
+
``` cpp
|
| 7629 |
+
GENERALIZED_SUM(binary_op1, init, binary_op2(*i, *(first2 + (i - first1))), ...)
|
| 7630 |
+
```
|
| 7631 |
+
|
| 7632 |
+
for every iterator `i` in \[`first1`, `last1`).
|
| 7633 |
+
|
| 7634 |
+
*Complexity:* 𝑂(`last1 - first1`) applications each of `binary_op1` and
|
| 7635 |
+
`binary_op2`.
|
| 7636 |
+
|
| 7637 |
+
``` cpp
|
| 7638 |
+
template<class InputIterator, class T,
|
| 7639 |
+
class BinaryOperation, class UnaryOperation>
|
| 7640 |
+
constexpr T transform_reduce(InputIterator first, InputIterator last, T init,
|
| 7641 |
+
BinaryOperation binary_op, UnaryOperation unary_op);
|
| 7642 |
+
template<class ExecutionPolicy,
|
| 7643 |
+
class ForwardIterator, class T,
|
| 7644 |
+
class BinaryOperation, class UnaryOperation>
|
| 7645 |
+
T transform_reduce(ExecutionPolicy&& exec,
|
| 7646 |
+
ForwardIterator first, ForwardIterator last,
|
| 7647 |
+
T init, BinaryOperation binary_op, UnaryOperation unary_op);
|
| 7648 |
+
```
|
| 7649 |
+
|
| 7650 |
+
*Mandates:* All of
|
| 7651 |
+
|
| 7652 |
+
- `binary_op(init, init)`,
|
| 7653 |
+
- `binary_op(init, unary_op(*first))`,
|
| 7654 |
+
- `binary_op(unary_op(*first), init)`, and
|
| 7655 |
+
- `binary_op(unary_op(*first), unary_op(*first))`
|
| 7656 |
+
|
| 7657 |
+
are convertible to `T`.
|
| 7658 |
+
|
| 7659 |
+
*Preconditions:*
|
| 7660 |
+
|
| 7661 |
+
- `T` meets the *Cpp17MoveConstructible* ([[cpp17.moveconstructible]])
|
| 7662 |
+
requirements.
|
| 7663 |
+
- Neither `unary_op` nor `binary_op` invalidates subranges, nor modifies
|
| 7664 |
+
elements in the range \[`first`, `last`\].
|
| 7665 |
+
|
| 7666 |
+
*Returns:*
|
| 7667 |
+
|
| 7668 |
+
``` cpp
|
| 7669 |
+
GENERALIZED_SUM(binary_op, init, unary_op(*i), ...)
|
| 7670 |
+
```
|
| 7671 |
+
|
| 7672 |
+
for every iterator `i` in \[`first`, `last`).
|
| 7673 |
+
|
| 7674 |
+
*Complexity:* 𝑂(`last - first`) applications each of `unary_op` and
|
| 7675 |
+
`binary_op`.
|
| 7676 |
+
|
| 7677 |
+
[*Note 1*: `transform_reduce` does not apply `unary_op` to
|
| 7678 |
+
`init`. — *end note*]
|
| 7679 |
+
|
| 7680 |
+
### Partial sum <a id="partial.sum">[[partial.sum]]</a>
|
| 7681 |
+
|
| 7682 |
+
``` cpp
|
| 7683 |
+
template<class InputIterator, class OutputIterator>
|
| 7684 |
+
constexpr OutputIterator
|
| 7685 |
+
partial_sum(InputIterator first, InputIterator last,
|
| 7686 |
+
OutputIterator result);
|
| 7687 |
+
template<class InputIterator, class OutputIterator, class BinaryOperation>
|
| 7688 |
+
constexpr OutputIterator
|
| 7689 |
+
partial_sum(InputIterator first, InputIterator last,
|
| 7690 |
+
OutputIterator result, BinaryOperation binary_op);
|
| 7691 |
+
```
|
| 7692 |
+
|
| 7693 |
+
*Mandates:* `InputIterator`’s value type is constructible from `*first`.
|
| 7694 |
+
The result of the expression `std::move(acc) + *i` or
|
| 7695 |
+
`binary_op(std::move(acc), *i)` is implicitly convertible to
|
| 7696 |
+
`InputIterator`’s value type. `acc` is
|
| 7697 |
+
writable [[iterator.requirements.general]] to `result`.
|
| 7698 |
+
|
| 7699 |
+
*Preconditions:* In the ranges \[`first`, `last`\] and \[`result`,
|
| 7700 |
+
`result + (last - first)`\] `binary_op` neither modifies elements nor
|
| 7701 |
+
invalidates iterators or subranges. [^9]
|
| 7702 |
+
|
| 7703 |
+
*Effects:* For a non-empty range, the function creates an accumulator
|
| 7704 |
+
`acc` whose type is `InputIterator`’s value type, initializes it with
|
| 7705 |
+
`*first`, and assigns the result to `*result`. For every iterator `i` in
|
| 7706 |
+
\[`first + 1`, `last`) in order, `acc` is then modified by
|
| 7707 |
+
`acc = std::move(acc) + *i` or `acc = binary_op(std::move(acc), *i)` and
|
| 7708 |
+
the result is assigned to `*(result + (i - first))`.
|
| 7709 |
+
|
| 7710 |
+
*Returns:* `result + (last - first)`.
|
| 7711 |
+
|
| 7712 |
+
*Complexity:* Exactly `(last - first) - 1` applications of the binary
|
| 7713 |
+
operation.
|
| 7714 |
+
|
| 7715 |
+
*Remarks:* `result` may be equal to `first`.
|
| 7716 |
+
|
| 7717 |
+
### Exclusive scan <a id="exclusive.scan">[[exclusive.scan]]</a>
|
| 7718 |
+
|
| 7719 |
+
``` cpp
|
| 7720 |
+
template<class InputIterator, class OutputIterator, class T>
|
| 7721 |
+
constexpr OutputIterator
|
| 7722 |
+
exclusive_scan(InputIterator first, InputIterator last,
|
| 7723 |
+
OutputIterator result, T init);
|
| 7724 |
+
```
|
| 7725 |
+
|
| 7726 |
+
*Effects:* Equivalent to:
|
| 7727 |
+
|
| 7728 |
+
``` cpp
|
| 7729 |
+
return exclusive_scan(first, last, result, init, plus<>());
|
| 7730 |
+
```
|
| 7731 |
+
|
| 7732 |
+
``` cpp
|
| 7733 |
+
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class T>
|
| 7734 |
+
ForwardIterator2
|
| 7735 |
+
exclusive_scan(ExecutionPolicy&& exec,
|
| 7736 |
+
ForwardIterator1 first, ForwardIterator1 last,
|
| 7737 |
+
ForwardIterator2 result, T init);
|
| 7738 |
+
```
|
| 7739 |
+
|
| 7740 |
+
*Effects:* Equivalent to:
|
| 7741 |
+
|
| 7742 |
+
``` cpp
|
| 7743 |
+
return exclusive_scan(std::forward<ExecutionPolicy>(exec),
|
| 7744 |
+
first, last, result, init, plus<>());
|
| 7745 |
+
```
|
| 7746 |
+
|
| 7747 |
+
``` cpp
|
| 7748 |
+
template<class InputIterator, class OutputIterator, class T, class BinaryOperation>
|
| 7749 |
+
constexpr OutputIterator
|
| 7750 |
+
exclusive_scan(InputIterator first, InputIterator last,
|
| 7751 |
+
OutputIterator result, T init, BinaryOperation binary_op);
|
| 7752 |
+
template<class ExecutionPolicy,
|
| 7753 |
+
class ForwardIterator1, class ForwardIterator2, class T, class BinaryOperation>
|
| 7754 |
+
ForwardIterator2
|
| 7755 |
+
exclusive_scan(ExecutionPolicy&& exec,
|
| 7756 |
+
ForwardIterator1 first, ForwardIterator1 last,
|
| 7757 |
+
ForwardIterator2 result, T init, BinaryOperation binary_op);
|
| 7758 |
+
```
|
| 7759 |
+
|
| 7760 |
+
*Mandates:* All of
|
| 7761 |
+
|
| 7762 |
+
- `binary_op(init, init)`,
|
| 7763 |
+
- `binary_op(init, *first)`, and
|
| 7764 |
+
- `binary_op(*first, *first)`
|
| 7765 |
+
|
| 7766 |
+
are convertible to `T`.
|
| 7767 |
+
|
| 7768 |
+
*Preconditions:*
|
| 7769 |
+
|
| 7770 |
+
- `T` meets the *Cpp17MoveConstructible* ([[cpp17.moveconstructible]])
|
| 7771 |
+
requirements.
|
| 7772 |
+
- `binary_op` neither invalidates iterators or subranges, nor modifies
|
| 7773 |
+
elements in the ranges \[`first`, `last`\] or \[`result`,
|
| 7774 |
+
`result + (last - first)`\].
|
| 7775 |
+
|
| 7776 |
+
*Effects:* For each integer `K` in \[`0`, `last - first`) assigns
|
| 7777 |
+
through `result + K` the value of:
|
| 7778 |
+
|
| 7779 |
+
``` cpp
|
| 7780 |
+
GENERALIZED_NONCOMMUTATIVE_SUM(
|
| 7781 |
+
binary_op, init, *(first + 0), *(first + 1), ..., *(first + K - 1))
|
| 7782 |
+
```
|
| 7783 |
+
|
| 7784 |
+
*Returns:* The end of the resulting range beginning at `result`.
|
| 7785 |
+
|
| 7786 |
+
*Complexity:* 𝑂(`last - first`) applications of `binary_op`.
|
| 7787 |
+
|
| 7788 |
+
*Remarks:* `result` may be equal to `first`.
|
| 7789 |
+
|
| 7790 |
+
[*Note 1*: The difference between `exclusive_scan` and `inclusive_scan`
|
| 7791 |
+
is that `exclusive_scan` excludes the iᵗʰ input element from the iᵗʰ
|
| 7792 |
+
sum. If `binary_op` is not mathematically associative, the behavior of
|
| 7793 |
+
`exclusive_scan` may be nondeterministic. — *end note*]
|
| 7794 |
+
|
| 7795 |
+
### Inclusive scan <a id="inclusive.scan">[[inclusive.scan]]</a>
|
| 7796 |
+
|
| 7797 |
+
``` cpp
|
| 7798 |
+
template<class InputIterator, class OutputIterator>
|
| 7799 |
+
constexpr OutputIterator
|
| 7800 |
+
inclusive_scan(InputIterator first, InputIterator last,
|
| 7801 |
+
OutputIterator result);
|
| 7802 |
+
```
|
| 7803 |
+
|
| 7804 |
+
*Effects:* Equivalent to:
|
| 7805 |
+
|
| 7806 |
+
``` cpp
|
| 7807 |
+
return inclusive_scan(first, last, result, plus<>());
|
| 7808 |
+
```
|
| 7809 |
+
|
| 7810 |
+
``` cpp
|
| 7811 |
+
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 7812 |
+
ForwardIterator2
|
| 7813 |
+
inclusive_scan(ExecutionPolicy&& exec,
|
| 7814 |
+
ForwardIterator1 first, ForwardIterator1 last,
|
| 7815 |
+
ForwardIterator2 result);
|
| 7816 |
+
```
|
| 7817 |
+
|
| 7818 |
+
*Effects:* Equivalent to:
|
| 7819 |
+
|
| 7820 |
+
``` cpp
|
| 7821 |
+
return inclusive_scan(std::forward<ExecutionPolicy>(exec), first, last, result, plus<>());
|
| 7822 |
+
```
|
| 7823 |
+
|
| 7824 |
+
``` cpp
|
| 7825 |
+
template<class InputIterator, class OutputIterator, class BinaryOperation>
|
| 7826 |
+
constexpr OutputIterator
|
| 7827 |
+
inclusive_scan(InputIterator first, InputIterator last,
|
| 7828 |
+
OutputIterator result, BinaryOperation binary_op);
|
| 7829 |
+
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 7830 |
+
class BinaryOperation>
|
| 7831 |
+
ForwardIterator2
|
| 7832 |
+
inclusive_scan(ExecutionPolicy&& exec,
|
| 7833 |
+
ForwardIterator1 first, ForwardIterator1 last,
|
| 7834 |
+
ForwardIterator2 result, BinaryOperation binary_op);
|
| 7835 |
+
|
| 7836 |
+
template<class InputIterator, class OutputIterator, class BinaryOperation, class T>
|
| 7837 |
+
constexpr OutputIterator
|
| 7838 |
+
inclusive_scan(InputIterator first, InputIterator last,
|
| 7839 |
+
OutputIterator result, BinaryOperation binary_op, T init);
|
| 7840 |
+
template<class ExecutionPolicy,
|
| 7841 |
+
class ForwardIterator1, class ForwardIterator2, class BinaryOperation, class T>
|
| 7842 |
+
ForwardIterator2
|
| 7843 |
+
inclusive_scan(ExecutionPolicy&& exec,
|
| 7844 |
+
ForwardIterator1 first, ForwardIterator1 last,
|
| 7845 |
+
ForwardIterator2 result, BinaryOperation binary_op, T init);
|
| 7846 |
+
```
|
| 7847 |
+
|
| 7848 |
+
Let `U` be the value type of `decltype(first)`.
|
| 7849 |
+
|
| 7850 |
+
*Mandates:* If `init` is provided, all of
|
| 7851 |
+
|
| 7852 |
+
- `binary_op(init, init)`,
|
| 7853 |
+
- `binary_op(init, *first)`, and
|
| 7854 |
+
- `binary_op(*first, *first)`
|
| 7855 |
+
|
| 7856 |
+
are convertible to `T`; otherwise, `binary_op(*first, *first)` is
|
| 7857 |
+
convertible to `U`.
|
| 7858 |
+
|
| 7859 |
+
*Preconditions:*
|
| 7860 |
+
|
| 7861 |
+
- If `init` is provided, `T` meets the *Cpp17MoveConstructible*
|
| 7862 |
+
([[cpp17.moveconstructible]]) requirements; otherwise, `U` meets the
|
| 7863 |
+
*Cpp17MoveConstructible* requirements.
|
| 7864 |
+
- `binary_op` neither invalidates iterators or subranges, nor modifies
|
| 7865 |
+
elements in the ranges \[`first`, `last`\] or \[`result`,
|
| 7866 |
+
`result + (last - first)`\].
|
| 7867 |
+
|
| 7868 |
+
*Effects:* For each integer `K` in \[`0`, `last - first`) assigns
|
| 7869 |
+
through `result + K` the value of
|
| 7870 |
+
|
| 7871 |
+
- *GENERALIZED_NONCOMMUTATIVE_SUM*(
|
| 7872 |
+
binary_op, init, \*(first + 0), \*(first + 1), ..., \*(first +
|
| 7873 |
+
K))
|
| 7874 |
+
if `init` is provided, or
|
| 7875 |
+
- *GENERALIZED_NONCOMMUTATIVE_SUM*(
|
| 7876 |
+
binary_op, \*(first + 0), \*(first + 1), ..., \*(first + K))
|
| 7877 |
+
otherwise.
|
| 7878 |
+
|
| 7879 |
+
*Returns:* The end of the resulting range beginning at `result`.
|
| 7880 |
+
|
| 7881 |
+
*Complexity:* 𝑂(`last - first`) applications of `binary_op`.
|
| 7882 |
+
|
| 7883 |
+
*Remarks:* `result` may be equal to `first`.
|
| 7884 |
+
|
| 7885 |
+
[*Note 1*: The difference between `exclusive_scan` and `inclusive_scan`
|
| 7886 |
+
is that `inclusive_scan` includes the iᵗʰ input element in the iᵗʰ sum.
|
| 7887 |
+
If `binary_op` is not mathematically associative, the behavior of
|
| 7888 |
+
`inclusive_scan` may be nondeterministic. — *end note*]
|
| 7889 |
+
|
| 7890 |
+
### Transform exclusive scan <a id="transform.exclusive.scan">[[transform.exclusive.scan]]</a>
|
| 7891 |
+
|
| 7892 |
+
``` cpp
|
| 7893 |
+
template<class InputIterator, class OutputIterator, class T,
|
| 7894 |
+
class BinaryOperation, class UnaryOperation>
|
| 7895 |
+
constexpr OutputIterator
|
| 7896 |
+
transform_exclusive_scan(InputIterator first, InputIterator last,
|
| 7897 |
+
OutputIterator result, T init,
|
| 7898 |
+
BinaryOperation binary_op, UnaryOperation unary_op);
|
| 7899 |
+
template<class ExecutionPolicy,
|
| 7900 |
+
class ForwardIterator1, class ForwardIterator2, class T,
|
| 7901 |
+
class BinaryOperation, class UnaryOperation>
|
| 7902 |
+
ForwardIterator2
|
| 7903 |
+
transform_exclusive_scan(ExecutionPolicy&& exec,
|
| 7904 |
+
ForwardIterator1 first, ForwardIterator1 last,
|
| 7905 |
+
ForwardIterator2 result, T init,
|
| 7906 |
+
BinaryOperation binary_op, UnaryOperation unary_op);
|
| 7907 |
+
```
|
| 7908 |
+
|
| 7909 |
+
*Mandates:* All of
|
| 7910 |
+
|
| 7911 |
+
- `binary_op(init, init)`,
|
| 7912 |
+
- `binary_op(init, unary_op(*first))`, and
|
| 7913 |
+
- `binary_op(unary_op(*first), unary_op(*first))`
|
| 7914 |
+
|
| 7915 |
+
are convertible to `T`.
|
| 7916 |
+
|
| 7917 |
+
*Preconditions:*
|
| 7918 |
+
|
| 7919 |
+
- `T` meets the *Cpp17MoveConstructible* ([[cpp17.moveconstructible]])
|
| 7920 |
+
requirements.
|
| 7921 |
+
- Neither `unary_op` nor `binary_op` invalidates iterators or subranges,
|
| 7922 |
+
nor modifies elements in the ranges \[`first`, `last`\] or \[`result`,
|
| 7923 |
+
`result + (last - first)`\].
|
| 7924 |
+
|
| 7925 |
+
*Effects:* For each integer `K` in \[`0`, `last - first`) assigns
|
| 7926 |
+
through `result + K` the value of:
|
| 7927 |
+
|
| 7928 |
+
``` cpp
|
| 7929 |
+
GENERALIZED_NONCOMMUTATIVE_SUM(
|
| 7930 |
+
binary_op, init,
|
| 7931 |
+
unary_op(*(first + 0)), unary_op(*(first + 1)), ..., unary_op(*(first + K - 1)))
|
| 7932 |
+
```
|
| 7933 |
+
|
| 7934 |
+
*Returns:* The end of the resulting range beginning at `result`.
|
| 7935 |
+
|
| 7936 |
+
*Complexity:* 𝑂(`last - first`) applications each of `unary_op` and
|
| 7937 |
+
`binary_op`.
|
| 7938 |
+
|
| 7939 |
+
*Remarks:* `result` may be equal to `first`.
|
| 7940 |
+
|
| 7941 |
+
[*Note 1*: The difference between `transform_exclusive_scan` and
|
| 7942 |
+
`transform_inclusive_scan` is that `transform_exclusive_scan` excludes
|
| 7943 |
+
the iᵗʰ input element from the iᵗʰ sum. If `binary_op` is not
|
| 7944 |
+
mathematically associative, the behavior of `transform_exclusive_scan`
|
| 7945 |
+
may be nondeterministic. `transform_exclusive_scan` does not apply
|
| 7946 |
+
`unary_op` to `init`. — *end note*]
|
| 7947 |
+
|
| 7948 |
+
### Transform inclusive scan <a id="transform.inclusive.scan">[[transform.inclusive.scan]]</a>
|
| 7949 |
+
|
| 7950 |
+
``` cpp
|
| 7951 |
+
template<class InputIterator, class OutputIterator,
|
| 7952 |
+
class BinaryOperation, class UnaryOperation>
|
| 7953 |
+
constexpr OutputIterator
|
| 7954 |
+
transform_inclusive_scan(InputIterator first, InputIterator last,
|
| 7955 |
+
OutputIterator result,
|
| 7956 |
+
BinaryOperation binary_op, UnaryOperation unary_op);
|
| 7957 |
+
template<class ExecutionPolicy,
|
| 7958 |
+
class ForwardIterator1, class ForwardIterator2,
|
| 7959 |
+
class BinaryOperation, class UnaryOperation>
|
| 7960 |
+
ForwardIterator2
|
| 7961 |
+
transform_inclusive_scan(ExecutionPolicy&& exec,
|
| 7962 |
+
ForwardIterator1 first, ForwardIterator1 last,
|
| 7963 |
+
ForwardIterator2 result,
|
| 7964 |
+
BinaryOperation binary_op, UnaryOperation unary_op);
|
| 7965 |
+
template<class InputIterator, class OutputIterator,
|
| 7966 |
+
class BinaryOperation, class UnaryOperation, class T>
|
| 7967 |
+
constexpr OutputIterator
|
| 7968 |
+
transform_inclusive_scan(InputIterator first, InputIterator last,
|
| 7969 |
+
OutputIterator result,
|
| 7970 |
+
BinaryOperation binary_op, UnaryOperation unary_op,
|
| 7971 |
+
T init);
|
| 7972 |
+
template<class ExecutionPolicy,
|
| 7973 |
+
class ForwardIterator1, class ForwardIterator2,
|
| 7974 |
+
class BinaryOperation, class UnaryOperation, class T>
|
| 7975 |
+
ForwardIterator2
|
| 7976 |
+
transform_inclusive_scan(ExecutionPolicy&& exec,
|
| 7977 |
+
ForwardIterator1 first, ForwardIterator1 last,
|
| 7978 |
+
ForwardIterator2 result,
|
| 7979 |
+
BinaryOperation binary_op, UnaryOperation unary_op,
|
| 7980 |
+
T init);
|
| 7981 |
+
```
|
| 7982 |
+
|
| 7983 |
+
Let `U` be the value type of `decltype(first)`.
|
| 7984 |
+
|
| 7985 |
+
*Mandates:* If `init` is provided, all of
|
| 7986 |
+
|
| 7987 |
+
- `binary_op(init, init)`,
|
| 7988 |
+
- `binary_op(init, unary_op(*first))`, and
|
| 7989 |
+
- `binary_op(unary_op(*first), unary_op(*first))`
|
| 7990 |
+
|
| 7991 |
+
are convertible to `T`; otherwise,
|
| 7992 |
+
`binary_op(unary_op(*first), unary_op(*first))` is convertible to `U`.
|
| 7993 |
+
|
| 7994 |
+
*Preconditions:*
|
| 7995 |
+
|
| 7996 |
+
- If `init` is provided, `T` meets the *Cpp17MoveConstructible*
|
| 7997 |
+
([[cpp17.moveconstructible]]) requirements; otherwise, `U` meets the
|
| 7998 |
+
*Cpp17MoveConstructible* requirements.
|
| 7999 |
+
- Neither `unary_op` nor `binary_op` invalidates iterators or subranges,
|
| 8000 |
+
nor modifies elements in the ranges \[`first`, `last`\] or \[`result`,
|
| 8001 |
+
`result + (last - first)`\].
|
| 8002 |
+
|
| 8003 |
+
*Effects:* For each integer `K` in \[`0`, `last - first`) assigns
|
| 8004 |
+
through `result + K` the value of
|
| 8005 |
+
|
| 8006 |
+
- *GENERALIZED_NONCOMMUTATIVE_SUM*(
|
| 8007 |
+
binary_op, init,
|
| 8008 |
+
unary_op(\*(first + 0)), unary_op(\*(first + 1)), ...,
|
| 8009 |
+
unary_op(\*(first + K)))
|
| 8010 |
+
if `init` is provided, or
|
| 8011 |
+
- *GENERALIZED_NONCOMMUTATIVE_SUM*(
|
| 8012 |
+
binary_op,
|
| 8013 |
+
unary_op(\*(first + 0)), unary_op(\*(first + 1)), ...,
|
| 8014 |
+
unary_op(\*(first + K)))
|
| 8015 |
+
otherwise.
|
| 8016 |
+
|
| 8017 |
+
*Returns:* The end of the resulting range beginning at `result`.
|
| 8018 |
+
|
| 8019 |
+
*Complexity:* 𝑂(`last - first`) applications each of `unary_op` and
|
| 8020 |
+
`binary_op`.
|
| 8021 |
+
|
| 8022 |
+
*Remarks:* `result` may be equal to `first`.
|
| 8023 |
+
|
| 8024 |
+
[*Note 1*: The difference between `transform_exclusive_scan` and
|
| 8025 |
+
`transform_inclusive_scan` is that `transform_inclusive_scan` includes
|
| 8026 |
+
the iᵗʰ input element in the iᵗʰ sum. If `binary_op` is not
|
| 8027 |
+
mathematically associative, the behavior of `transform_inclusive_scan`
|
| 8028 |
+
may be nondeterministic. `transform_inclusive_scan` does not apply
|
| 8029 |
+
`unary_op` to `init`. — *end note*]
|
| 8030 |
+
|
| 8031 |
+
### Adjacent difference <a id="adjacent.difference">[[adjacent.difference]]</a>
|
| 8032 |
+
|
| 8033 |
+
``` cpp
|
| 8034 |
+
template<class InputIterator, class OutputIterator>
|
| 8035 |
+
constexpr OutputIterator
|
| 8036 |
+
adjacent_difference(InputIterator first, InputIterator last,
|
| 8037 |
+
OutputIterator result);
|
| 8038 |
+
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
|
| 8039 |
+
ForwardIterator2
|
| 8040 |
+
adjacent_difference(ExecutionPolicy&& exec,
|
| 8041 |
+
ForwardIterator1 first, ForwardIterator1 last, ForwardIterator2 result);
|
| 8042 |
+
|
| 8043 |
+
template<class InputIterator, class OutputIterator, class BinaryOperation>
|
| 8044 |
+
constexpr OutputIterator
|
| 8045 |
+
adjacent_difference(InputIterator first, InputIterator last,
|
| 8046 |
+
OutputIterator result, BinaryOperation binary_op);
|
| 8047 |
+
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
|
| 8048 |
+
class BinaryOperation>
|
| 8049 |
+
ForwardIterator2
|
| 8050 |
+
adjacent_difference(ExecutionPolicy&& exec,
|
| 8051 |
+
ForwardIterator1 first, ForwardIterator1 last,
|
| 8052 |
+
ForwardIterator2 result, BinaryOperation binary_op);
|
| 8053 |
+
```
|
| 8054 |
+
|
| 8055 |
+
Let `T` be the value type of `decltype(first)`. For the overloads that
|
| 8056 |
+
do not take an argument `binary_op`, let `binary_op` be an lvalue that
|
| 8057 |
+
denotes an object of type `minus<>`.
|
| 8058 |
+
|
| 8059 |
+
*Mandates:*
|
| 8060 |
+
|
| 8061 |
+
- For the overloads with no `ExecutionPolicy`, `T` is constructible from
|
| 8062 |
+
`*first`. `acc` (defined below) is
|
| 8063 |
+
writable [[iterator.requirements.general]] to the `result` output
|
| 8064 |
+
iterator. The result of the expression
|
| 8065 |
+
`binary_op(val, std::move(acc))` is writable to `result`.
|
| 8066 |
+
- For the overloads with an `ExecutionPolicy`, the result of the
|
| 8067 |
+
expressions `binary_op(*first, *first)` and `*first` are writable to
|
| 8068 |
+
`result`.
|
| 8069 |
+
|
| 8070 |
+
*Preconditions:*
|
| 8071 |
+
|
| 8072 |
+
- For the overloads with no `ExecutionPolicy`, `T` meets the
|
| 8073 |
+
*Cpp17MoveAssignable* ([[cpp17.moveassignable]]) requirements.
|
| 8074 |
+
- For all overloads, in the ranges \[`first`, `last`\] and \[`result`,
|
| 8075 |
+
`result + (last - first)`\], `binary_op` neither modifies elements nor
|
| 8076 |
+
invalidate iterators or subranges. [^10]
|
| 8077 |
+
|
| 8078 |
+
*Effects:* For the overloads with no `ExecutionPolicy` and a non-empty
|
| 8079 |
+
range, the function creates an accumulator `acc` of type `T`,
|
| 8080 |
+
initializes it with `*first`, and assigns the result to `*result`. For
|
| 8081 |
+
every iterator `i` in \[`first + 1`, `last`) in order, creates an object
|
| 8082 |
+
`val` whose type is `T`, initializes it with `*i`, computes
|
| 8083 |
+
`binary_op(val, std::move(acc))`, assigns the result to
|
| 8084 |
+
`*(result + (i - first))`, and move assigns from `val` to `acc`.
|
| 8085 |
+
|
| 8086 |
+
For the overloads with an `ExecutionPolicy` and a non-empty range,
|
| 8087 |
+
performs `*result = *first`. Then, for every `d` in
|
| 8088 |
+
`[1, last - first - 1]`, performs
|
| 8089 |
+
`*(result + d) = binary_op(*(first + d), *(first + (d - 1)))`.
|
| 8090 |
+
|
| 8091 |
+
*Returns:* `result + (last - first)`.
|
| 8092 |
+
|
| 8093 |
+
*Complexity:* Exactly `(last - first) - 1` applications of the binary
|
| 8094 |
+
operation.
|
| 8095 |
+
|
| 8096 |
+
*Remarks:* For the overloads with no `ExecutionPolicy`, `result` may be
|
| 8097 |
+
equal to `first`. For the overloads with an `ExecutionPolicy`, the
|
| 8098 |
+
ranges \[`first`, `last`) and \[`result`, `result + (last - first)`)
|
| 8099 |
+
shall not overlap.
|
| 8100 |
+
|
| 8101 |
+
### Iota <a id="numeric.iota">[[numeric.iota]]</a>
|
| 8102 |
+
|
| 8103 |
+
``` cpp
|
| 8104 |
+
template<class ForwardIterator, class T>
|
| 8105 |
+
constexpr void iota(ForwardIterator first, ForwardIterator last, T value);
|
| 8106 |
+
```
|
| 8107 |
+
|
| 8108 |
+
*Mandates:* `T` is convertible to `ForwardIterator`’s value type. The
|
| 8109 |
+
expression `++val`, where `val` has type `T`, is well-formed.
|
| 8110 |
+
|
| 8111 |
+
*Effects:* For each element referred to by the iterator `i` in the range
|
| 8112 |
+
\[`first`, `last`), assigns `*i = value` and increments `value` as if by
|
| 8113 |
+
`++value`.
|
| 8114 |
+
|
| 8115 |
+
*Complexity:* Exactly `last - first` increments and assignments.
|
| 8116 |
+
|
| 8117 |
+
### Greatest common divisor <a id="numeric.ops.gcd">[[numeric.ops.gcd]]</a>
|
| 8118 |
+
|
| 8119 |
+
``` cpp
|
| 8120 |
+
template<class M, class N>
|
| 8121 |
+
constexpr common_type_t<M,N> gcd(M m, N n);
|
| 8122 |
+
```
|
| 8123 |
+
|
| 8124 |
+
*Mandates:* `M` and `N` both are integer types and not cv `bool`.
|
| 8125 |
+
|
| 8126 |
+
*Preconditions:* |`m`| and |`n`| are representable as a value of
|
| 8127 |
+
`common_type_t<M, N>`.
|
| 8128 |
+
|
| 8129 |
+
[*Note 1*: These requirements ensure, for example, that
|
| 8130 |
+
`gcd(m, m)` = |`m`| is representable as a value of type
|
| 8131 |
+
`M`. — *end note*]
|
| 8132 |
+
|
| 8133 |
+
*Returns:* Zero when `m` and `n` are both zero. Otherwise, returns the
|
| 8134 |
+
greatest common divisor of |`m`| and |`n`|.
|
| 8135 |
+
|
| 8136 |
+
*Throws:* Nothing.
|
| 8137 |
+
|
| 8138 |
+
### Least common multiple <a id="numeric.ops.lcm">[[numeric.ops.lcm]]</a>
|
| 8139 |
+
|
| 8140 |
+
``` cpp
|
| 8141 |
+
template<class M, class N>
|
| 8142 |
+
constexpr common_type_t<M,N> lcm(M m, N n);
|
| 8143 |
+
```
|
| 8144 |
+
|
| 8145 |
+
*Mandates:* `M` and `N` both are integer types and not cv `bool`.
|
| 8146 |
+
|
| 8147 |
+
*Preconditions:* |`m`| and |`n`| are representable as a value of
|
| 8148 |
+
`common_type_t<M, N>`. The least common multiple of |`m`| and |`n`| is
|
| 8149 |
+
representable as a value of type `common_type_t<M,N>`.
|
| 8150 |
+
|
| 8151 |
+
*Returns:* Zero when either `m` or `n` is zero. Otherwise, returns the
|
| 8152 |
+
least common multiple of |`m`| and |`n`|.
|
| 8153 |
+
|
| 8154 |
+
*Throws:* Nothing.
|
| 8155 |
+
|
| 8156 |
+
### Midpoint <a id="numeric.ops.midpoint">[[numeric.ops.midpoint]]</a>
|
| 8157 |
+
|
| 8158 |
+
``` cpp
|
| 8159 |
+
template<class T>
|
| 8160 |
+
constexpr T midpoint(T a, T b) noexcept;
|
| 8161 |
+
```
|
| 8162 |
+
|
| 8163 |
+
*Constraints:* `T` is an arithmetic type other than `bool`.
|
| 8164 |
+
|
| 8165 |
+
*Returns:* Half the sum of `a` and `b`. If `T` is an integer type and
|
| 8166 |
+
the sum is odd, the result is rounded towards `a`.
|
| 8167 |
+
|
| 8168 |
+
*Remarks:* No overflow occurs. If `T` is a floating-point type, at most
|
| 8169 |
+
one inexact operation occurs.
|
| 8170 |
+
|
| 8171 |
+
``` cpp
|
| 8172 |
+
template<class T>
|
| 8173 |
+
constexpr T* midpoint(T* a, T* b);
|
| 8174 |
+
```
|
| 8175 |
+
|
| 8176 |
+
*Constraints:* `T` is an object type.
|
| 8177 |
+
|
| 8178 |
+
*Mandates:* `T` is a complete type.
|
| 8179 |
+
|
| 8180 |
+
*Preconditions:* `a` and `b` point to, respectively, elements i and j of
|
| 8181 |
+
the same array object `x`.
|
| 8182 |
+
|
| 8183 |
+
[*Note 1*: As specified in [[basic.compound]], an object that is not an
|
| 8184 |
+
array element is considered to belong to a single-element array for this
|
| 8185 |
+
purpose and a pointer past the last element of an array of n elements is
|
| 8186 |
+
considered to be equivalent to a pointer to a hypothetical array element
|
| 8187 |
+
n for this purpose. — *end note*]
|
| 8188 |
+
|
| 8189 |
+
*Returns:* A pointer to array element $i+\frac{j-i}{2}$ of `x`, where
|
| 8190 |
+
the result of the division is truncated towards zero.
|
| 8191 |
+
|
| 8192 |
+
## Specialized `<memory>` algorithms <a id="specialized.algorithms">[[specialized.algorithms]]</a>
|
| 8193 |
+
|
| 8194 |
+
The contents specified in this subclause [[specialized.algorithms]] are
|
| 8195 |
+
declared in the header `<memory>`.
|
| 8196 |
+
|
| 8197 |
+
Unless otherwise specified, if an exception is thrown in the following
|
| 8198 |
+
algorithms, objects constructed by a placement *new-expression*
|
| 8199 |
+
[[expr.new]] are destroyed in an unspecified order before allowing the
|
| 8200 |
+
exception to propagate.
|
| 8201 |
+
|
| 8202 |
+
[*Note 1*: When invoked on ranges of potentially-overlapping subobjects
|
| 8203 |
+
[[intro.object]], the algorithms specified in this subclause
|
| 8204 |
+
[[specialized.algorithms]] result in undefined behavior. — *end note*]
|
| 8205 |
+
|
| 8206 |
+
Some algorithms specified in this clause make use of the exposition-only
|
| 8207 |
+
function `voidify`:
|
| 8208 |
+
|
| 8209 |
+
``` cpp
|
| 8210 |
+
template<class T>
|
| 8211 |
+
constexpr void* voidify(T& obj) noexcept {
|
| 8212 |
+
return const_cast<void*>(static_cast<const volatile void*>(addressof(obj)));
|
| 8213 |
+
}
|
| 8214 |
+
```
|
| 8215 |
+
|
| 8216 |
+
### Special memory concepts <a id="special.mem.concepts">[[special.mem.concepts]]</a>
|
| 8217 |
+
|
| 8218 |
+
Some algorithms in this subclause are constrained with the following
|
| 8219 |
+
exposition-only concepts:
|
| 8220 |
+
|
| 8221 |
+
``` cpp
|
| 8222 |
+
template<class I>
|
| 8223 |
+
concept no-throw-input-iterator = // exposition only
|
| 8224 |
+
input_iterator<I> &&
|
| 8225 |
+
is_lvalue_reference_v<iter_reference_t<I>> &&
|
| 8226 |
+
same_as<remove_cvref_t<iter_reference_t<I>>, iter_value_t<I>>;
|
| 8227 |
+
```
|
| 8228 |
+
|
| 8229 |
+
A type `I` models *`no-throw-input-iterator`* only if no exceptions are
|
| 8230 |
+
thrown from increment, copy construction, move construction, copy
|
| 8231 |
+
assignment, move assignment, or indirection through valid iterators.
|
| 8232 |
+
|
| 8233 |
+
[*Note 1*: This concept allows some `input_iterator`
|
| 8234 |
+
[[iterator.concept.input]] operations to throw
|
| 8235 |
+
exceptions. — *end note*]
|
| 8236 |
+
|
| 8237 |
+
``` cpp
|
| 8238 |
+
template<class S, class I>
|
| 8239 |
+
concept no-throw-sentinel = sentinel_for<S, I>; // exposition only
|
| 8240 |
+
```
|
| 8241 |
+
|
| 8242 |
+
Types `S` and `I` model *`no-throw-sentinel`* only if no exceptions are
|
| 8243 |
+
thrown from copy construction, move construction, copy assignment, move
|
| 8244 |
+
assignment, or comparisons between valid values of type `I` and `S`.
|
| 8245 |
+
|
| 8246 |
+
[*Note 2*: This concept allows some `sentinel_for`
|
| 8247 |
+
[[iterator.concept.sentinel]] operations to throw
|
| 8248 |
+
exceptions. — *end note*]
|
| 8249 |
+
|
| 8250 |
+
``` cpp
|
| 8251 |
+
template<class R>
|
| 8252 |
+
concept no-throw-input-range = // exposition only
|
| 8253 |
+
range<R> &&
|
| 8254 |
+
no-throw-input-iterator<iterator_t<R>> &&
|
| 8255 |
+
no-throw-sentinel<sentinel_t<R>, iterator_t<R>>;
|
| 8256 |
+
```
|
| 8257 |
+
|
| 8258 |
+
A type `R` models *`no-throw-input-range`* only if no exceptions are
|
| 8259 |
+
thrown from calls to `ranges::begin` and `ranges::end` on an object of
|
| 8260 |
+
type `R`.
|
| 8261 |
+
|
| 8262 |
+
``` cpp
|
| 8263 |
+
template<class I>
|
| 8264 |
+
concept no-throw-forward-iterator = // exposition only
|
| 8265 |
+
no-throw-input-iterator<I> &&
|
| 8266 |
+
forward_iterator<I> &&
|
| 8267 |
+
no-throw-sentinel<I, I>;
|
| 8268 |
+
```
|
| 8269 |
+
|
| 8270 |
+
[*Note 3*: This concept allows some `forward_iterator`
|
| 8271 |
+
[[iterator.concept.forward]] operations to throw
|
| 8272 |
+
exceptions. — *end note*]
|
| 8273 |
+
|
| 8274 |
+
``` cpp
|
| 8275 |
+
template<class R>
|
| 8276 |
+
concept no-throw-forward-range = // exposition only
|
| 8277 |
+
no-throw-input-range<R> &&
|
| 8278 |
+
no-throw-forward-iterator<iterator_t<R>>;
|
| 8279 |
+
```
|
| 8280 |
+
|
| 8281 |
+
### `uninitialized_default_construct` <a id="uninitialized.construct.default">[[uninitialized.construct.default]]</a>
|
| 8282 |
+
|
| 8283 |
+
``` cpp
|
| 8284 |
+
template<class NoThrowForwardIterator>
|
| 8285 |
+
void uninitialized_default_construct(NoThrowForwardIterator first, NoThrowForwardIterator last);
|
| 8286 |
+
```
|
| 8287 |
+
|
| 8288 |
+
*Effects:* Equivalent to:
|
| 8289 |
+
|
| 8290 |
+
``` cpp
|
| 8291 |
+
for (; first != last; ++first)
|
| 8292 |
+
::new (voidify(*first))
|
| 8293 |
+
typename iterator_traits<NoThrowForwardIterator>::value_type;
|
| 8294 |
+
```
|
| 8295 |
+
|
| 8296 |
+
``` cpp
|
| 8297 |
+
namespace ranges {
|
| 8298 |
+
template<no-throw-forward-iterator I, no-throw-sentinel<I> S>
|
| 8299 |
+
requires default_initializable<iter_value_t<I>>
|
| 8300 |
+
I uninitialized_default_construct(I first, S last);
|
| 8301 |
+
template<no-throw-forward-range R>
|
| 8302 |
+
requires default_initializable<range_value_t<R>>
|
| 8303 |
+
borrowed_iterator_t<R> uninitialized_default_construct(R&& r);
|
| 8304 |
+
}
|
| 8305 |
+
```
|
| 8306 |
+
|
| 8307 |
+
*Effects:* Equivalent to:
|
| 8308 |
+
|
| 8309 |
+
``` cpp
|
| 8310 |
+
for (; first != last; ++first)
|
| 8311 |
+
::new (voidify(*first)) remove_reference_t<iter_reference_t<I>>;
|
| 8312 |
+
return first;
|
| 8313 |
+
```
|
| 8314 |
+
|
| 8315 |
+
``` cpp
|
| 8316 |
+
template<class NoThrowForwardIterator, class Size>
|
| 8317 |
+
NoThrowForwardIterator uninitialized_default_construct_n(NoThrowForwardIterator first, Size n);
|
| 8318 |
+
```
|
| 8319 |
+
|
| 8320 |
+
*Effects:* Equivalent to:
|
| 8321 |
+
|
| 8322 |
+
``` cpp
|
| 8323 |
+
for (; n > 0; (void)++first, --n)
|
| 8324 |
+
::new (voidify(*first))
|
| 8325 |
+
typename iterator_traits<NoThrowForwardIterator>::value_type;
|
| 8326 |
+
return first;
|
| 8327 |
+
```
|
| 8328 |
+
|
| 8329 |
+
``` cpp
|
| 8330 |
+
namespace ranges {
|
| 8331 |
+
template<no-throw-forward-iterator I>
|
| 8332 |
+
requires default_initializable<iter_value_t<I>>
|
| 8333 |
+
I uninitialized_default_construct_n(I first, iter_difference_t<I> n);
|
| 8334 |
+
}
|
| 8335 |
+
```
|
| 8336 |
+
|
| 8337 |
+
*Effects:* Equivalent to:
|
| 8338 |
+
|
| 8339 |
+
``` cpp
|
| 8340 |
+
return uninitialized_default_construct(counted_iterator(first, n),
|
| 8341 |
+
default_sentinel).base();
|
| 8342 |
+
```
|
| 8343 |
+
|
| 8344 |
+
### `uninitialized_value_construct` <a id="uninitialized.construct.value">[[uninitialized.construct.value]]</a>
|
| 8345 |
+
|
| 8346 |
+
``` cpp
|
| 8347 |
+
template<class NoThrowForwardIterator>
|
| 8348 |
+
void uninitialized_value_construct(NoThrowForwardIterator first, NoThrowForwardIterator last);
|
| 8349 |
+
```
|
| 8350 |
+
|
| 8351 |
+
*Effects:* Equivalent to:
|
| 8352 |
+
|
| 8353 |
+
``` cpp
|
| 8354 |
+
for (; first != last; ++first)
|
| 8355 |
+
::new (voidify(*first))
|
| 8356 |
+
typename iterator_traits<NoThrowForwardIterator>::value_type();
|
| 8357 |
+
```
|
| 8358 |
+
|
| 8359 |
+
``` cpp
|
| 8360 |
+
namespace ranges {
|
| 8361 |
+
template<no-throw-forward-iterator I, no-throw-sentinel<I> S>
|
| 8362 |
+
requires default_initializable<iter_value_t<I>>
|
| 8363 |
+
I uninitialized_value_construct(I first, S last);
|
| 8364 |
+
template<no-throw-forward-range R>
|
| 8365 |
+
requires default_initializable<range_value_t<R>>
|
| 8366 |
+
borrowed_iterator_t<R> uninitialized_value_construct(R&& r);
|
| 8367 |
+
}
|
| 8368 |
+
```
|
| 8369 |
+
|
| 8370 |
+
*Effects:* Equivalent to:
|
| 8371 |
+
|
| 8372 |
+
``` cpp
|
| 8373 |
+
for (; first != last; ++first)
|
| 8374 |
+
::new (voidify(*first)) remove_reference_t<iter_reference_t<I>>();
|
| 8375 |
+
return first;
|
| 8376 |
+
```
|
| 8377 |
+
|
| 8378 |
+
``` cpp
|
| 8379 |
+
template<class NoThrowForwardIterator, class Size>
|
| 8380 |
+
NoThrowForwardIterator uninitialized_value_construct_n(NoThrowForwardIterator first, Size n);
|
| 8381 |
+
```
|
| 8382 |
+
|
| 8383 |
+
*Effects:* Equivalent to:
|
| 8384 |
+
|
| 8385 |
+
``` cpp
|
| 8386 |
+
for (; n > 0; (void)++first, --n)
|
| 8387 |
+
::new (voidify(*first))
|
| 8388 |
+
typename iterator_traits<NoThrowForwardIterator>::value_type();
|
| 8389 |
+
return first;
|
| 8390 |
+
```
|
| 8391 |
+
|
| 8392 |
+
``` cpp
|
| 8393 |
+
namespace ranges {
|
| 8394 |
+
template<no-throw-forward-iterator I>
|
| 8395 |
+
requires default_initializable<iter_value_t<I>>
|
| 8396 |
+
I uninitialized_value_construct_n(I first, iter_difference_t<I> n);
|
| 8397 |
+
}
|
| 8398 |
+
```
|
| 8399 |
+
|
| 8400 |
+
*Effects:* Equivalent to:
|
| 8401 |
+
|
| 8402 |
+
``` cpp
|
| 8403 |
+
return uninitialized_value_construct(counted_iterator(first, n),
|
| 8404 |
+
default_sentinel).base();
|
| 8405 |
+
```
|
| 8406 |
+
|
| 8407 |
+
### `uninitialized_copy` <a id="uninitialized.copy">[[uninitialized.copy]]</a>
|
| 8408 |
+
|
| 8409 |
+
``` cpp
|
| 8410 |
+
template<class InputIterator, class NoThrowForwardIterator>
|
| 8411 |
+
NoThrowForwardIterator uninitialized_copy(InputIterator first, InputIterator last,
|
| 8412 |
+
NoThrowForwardIterator result);
|
| 8413 |
+
```
|
| 8414 |
+
|
| 8415 |
+
*Preconditions:* `result`+\[0, `(last - first)`) does not overlap with
|
| 8416 |
+
\[`first`, `last`).
|
| 8417 |
+
|
| 8418 |
+
*Effects:* Equivalent to:
|
| 8419 |
+
|
| 8420 |
+
``` cpp
|
| 8421 |
+
for (; first != last; ++result, (void) ++first)
|
| 8422 |
+
::new (voidify(*result))
|
| 8423 |
+
typename iterator_traits<NoThrowForwardIterator>::value_type(*first);
|
| 8424 |
+
```
|
| 8425 |
+
|
| 8426 |
+
*Returns:* `result`.
|
| 8427 |
+
|
| 8428 |
+
``` cpp
|
| 8429 |
+
namespace ranges {
|
| 8430 |
+
template<input_iterator I, sentinel_for<I> S1,
|
| 8431 |
+
no-throw-forward-iterator O, no-throw-sentinel<O> S2>
|
| 8432 |
+
requires constructible_from<iter_value_t<O>, iter_reference_t<I>>
|
| 8433 |
+
uninitialized_copy_result<I, O>
|
| 8434 |
+
uninitialized_copy(I ifirst, S1 ilast, O ofirst, S2 olast);
|
| 8435 |
+
template<input_range IR, no-throw-forward-range OR>
|
| 8436 |
+
requires constructible_from<range_value_t<OR>, range_reference_t<IR>>
|
| 8437 |
+
uninitialized_copy_result<borrowed_iterator_t<IR>, borrowed_iterator_t<OR>>
|
| 8438 |
+
uninitialized_copy(IR&& in_range, OR&& out_range);
|
| 8439 |
+
}
|
| 8440 |
+
```
|
| 8441 |
+
|
| 8442 |
+
*Preconditions:* \[`ofirst`, `olast`) does not overlap with \[`ifirst`,
|
| 8443 |
+
`ilast`).
|
| 8444 |
+
|
| 8445 |
+
*Effects:* Equivalent to:
|
| 8446 |
+
|
| 8447 |
+
``` cpp
|
| 8448 |
+
for (; ifirst != ilast && ofirst != olast; ++ofirst, (void)++ifirst) {
|
| 8449 |
+
::new (voidify(*ofirst)) remove_reference_t<iter_reference_t<O>>(*ifirst);
|
| 8450 |
+
}
|
| 8451 |
+
return {std::move(ifirst), ofirst};
|
| 8452 |
+
```
|
| 8453 |
+
|
| 8454 |
+
``` cpp
|
| 8455 |
+
template<class InputIterator, class Size, class NoThrowForwardIterator>
|
| 8456 |
+
NoThrowForwardIterator uninitialized_copy_n(InputIterator first, Size n,
|
| 8457 |
+
NoThrowForwardIterator result);
|
| 8458 |
+
```
|
| 8459 |
+
|
| 8460 |
+
*Preconditions:* `result`+\[0, `n`) does not overlap with `first`+\[0,
|
| 8461 |
+
`n`).
|
| 8462 |
+
|
| 8463 |
+
*Effects:* Equivalent to:
|
| 8464 |
+
|
| 8465 |
+
``` cpp
|
| 8466 |
+
for ( ; n > 0; ++result, (void) ++first, --n) {
|
| 8467 |
+
::new (voidify(*result))
|
| 8468 |
+
typename iterator_traits<NoThrowForwardIterator>::value_type(*first);
|
| 8469 |
+
}
|
| 8470 |
+
```
|
| 8471 |
+
|
| 8472 |
+
*Returns:* `result`.
|
| 8473 |
+
|
| 8474 |
+
``` cpp
|
| 8475 |
+
namespace ranges {
|
| 8476 |
+
template<input_iterator I, no-throw-forward-iterator O, no-throw-sentinel<O> S>
|
| 8477 |
+
requires constructible_from<iter_value_t<O>, iter_reference_t<I>>
|
| 8478 |
+
uninitialized_copy_n_result<I, O>
|
| 8479 |
+
uninitialized_copy_n(I ifirst, iter_difference_t<I> n, O ofirst, S olast);
|
| 8480 |
+
}
|
| 8481 |
+
```
|
| 8482 |
+
|
| 8483 |
+
*Preconditions:* \[`ofirst`, `olast`) does not overlap with
|
| 8484 |
+
`ifirst`+\[0, `n`).
|
| 8485 |
+
|
| 8486 |
+
*Effects:* Equivalent to:
|
| 8487 |
+
|
| 8488 |
+
``` cpp
|
| 8489 |
+
auto t = uninitialized_copy(counted_iterator(ifirst, n),
|
| 8490 |
+
default_sentinel, ofirst, olast);
|
| 8491 |
+
return {std::move(t.in).base(), t.out};
|
| 8492 |
+
```
|
| 8493 |
+
|
| 8494 |
+
### `uninitialized_move` <a id="uninitialized.move">[[uninitialized.move]]</a>
|
| 8495 |
+
|
| 8496 |
+
``` cpp
|
| 8497 |
+
template<class InputIterator, class NoThrowForwardIterator>
|
| 8498 |
+
NoThrowForwardIterator uninitialized_move(InputIterator first, InputIterator last,
|
| 8499 |
+
NoThrowForwardIterator result);
|
| 8500 |
+
```
|
| 8501 |
+
|
| 8502 |
+
*Preconditions:* `result`+\[0, `(last - first)`) does not overlap with
|
| 8503 |
+
\[`first`, `last`).
|
| 8504 |
+
|
| 8505 |
+
*Effects:* Equivalent to:
|
| 8506 |
+
|
| 8507 |
+
``` cpp
|
| 8508 |
+
for (; first != last; (void)++result, ++first)
|
| 8509 |
+
::new (voidify(*result))
|
| 8510 |
+
typename iterator_traits<NoThrowForwardIterator>::value_type(std::move(*first));
|
| 8511 |
+
return result;
|
| 8512 |
+
```
|
| 8513 |
+
|
| 8514 |
+
``` cpp
|
| 8515 |
+
namespace ranges {
|
| 8516 |
+
template<input_iterator I, sentinel_for<I> S1,
|
| 8517 |
+
no-throw-forward-iterator O, no-throw-sentinel<O> S2>
|
| 8518 |
+
requires constructible_from<iter_value_t<O>, iter_rvalue_reference_t<I>>
|
| 8519 |
+
uninitialized_move_result<I, O>
|
| 8520 |
+
uninitialized_move(I ifirst, S1 ilast, O ofirst, S2 olast);
|
| 8521 |
+
template<input_range IR, no-throw-forward-range OR>
|
| 8522 |
+
requires constructible_from<range_value_t<OR>, range_rvalue_reference_t<IR>>
|
| 8523 |
+
uninitialized_move_result<borrowed_iterator_t<IR>, borrowed_iterator_t<OR>>
|
| 8524 |
+
uninitialized_move(IR&& in_range, OR&& out_range);
|
| 8525 |
+
}
|
| 8526 |
+
```
|
| 8527 |
+
|
| 8528 |
+
*Preconditions:* \[`ofirst`, `olast`) does not overlap with \[`ifirst`,
|
| 8529 |
+
`ilast`).
|
| 8530 |
+
|
| 8531 |
+
*Effects:* Equivalent to:
|
| 8532 |
+
|
| 8533 |
+
``` cpp
|
| 8534 |
+
for (; ifirst != ilast && ofirst != olast; ++ofirst, (void)++ifirst) {
|
| 8535 |
+
::new (voidify(*ofirst))
|
| 8536 |
+
remove_reference_t<iter_reference_t<O>>(ranges::iter_move(ifirst));
|
| 8537 |
+
}
|
| 8538 |
+
return {std::move(ifirst), ofirst};
|
| 8539 |
+
```
|
| 8540 |
+
|
| 8541 |
+
[*Note 1*: If an exception is thrown, some objects in the range
|
| 8542 |
+
\[`first`, `last`) are left in a valid, but unspecified
|
| 8543 |
+
state. — *end note*]
|
| 8544 |
+
|
| 8545 |
+
``` cpp
|
| 8546 |
+
template<class InputIterator, class Size, class NoThrowForwardIterator>
|
| 8547 |
+
pair<InputIterator, NoThrowForwardIterator>
|
| 8548 |
+
uninitialized_move_n(InputIterator first, Size n, NoThrowForwardIterator result);
|
| 8549 |
+
```
|
| 8550 |
+
|
| 8551 |
+
*Preconditions:* `result`+\[0, `n`) does not overlap with `first`+\[0,
|
| 8552 |
+
`n`).
|
| 8553 |
+
|
| 8554 |
+
*Effects:* Equivalent to:
|
| 8555 |
+
|
| 8556 |
+
``` cpp
|
| 8557 |
+
for (; n > 0; ++result, (void) ++first, --n)
|
| 8558 |
+
::new (voidify(*result))
|
| 8559 |
+
typename iterator_traits<NoThrowForwardIterator>::value_type(std::move(*first));
|
| 8560 |
+
return {first, result};
|
| 8561 |
+
```
|
| 8562 |
+
|
| 8563 |
+
``` cpp
|
| 8564 |
+
namespace ranges {
|
| 8565 |
+
template<input_iterator I, no-throw-forward-iterator O, no-throw-sentinel<O> S>
|
| 8566 |
+
requires constructible_from<iter_value_t<O>, iter_rvalue_reference_t<I>>
|
| 8567 |
+
uninitialized_move_n_result<I, O>
|
| 8568 |
+
uninitialized_move_n(I ifirst, iter_difference_t<I> n, O ofirst, S olast);
|
| 8569 |
+
}
|
| 8570 |
+
```
|
| 8571 |
+
|
| 8572 |
+
*Preconditions:* \[`ofirst`, `olast`) does not overlap with
|
| 8573 |
+
`ifirst`+\[0, `n`).
|
| 8574 |
+
|
| 8575 |
+
*Effects:* Equivalent to:
|
| 8576 |
+
|
| 8577 |
+
``` cpp
|
| 8578 |
+
auto t = uninitialized_move(counted_iterator(ifirst, n),
|
| 8579 |
+
default_sentinel, ofirst, olast);
|
| 8580 |
+
return {std::move(t.in).base(), t.out};
|
| 8581 |
+
```
|
| 8582 |
+
|
| 8583 |
+
[*Note 2*: If an exception is thrown, some objects in the range
|
| 8584 |
+
`first`+\[0, `n`) are left in a valid but unspecified
|
| 8585 |
+
state. — *end note*]
|
| 8586 |
+
|
| 8587 |
+
### `uninitialized_fill` <a id="uninitialized.fill">[[uninitialized.fill]]</a>
|
| 8588 |
+
|
| 8589 |
+
``` cpp
|
| 8590 |
+
template<class NoThrowForwardIterator, class T>
|
| 8591 |
+
void uninitialized_fill(NoThrowForwardIterator first, NoThrowForwardIterator last, const T& x);
|
| 8592 |
+
```
|
| 8593 |
+
|
| 8594 |
+
*Effects:* Equivalent to:
|
| 8595 |
+
|
| 8596 |
+
``` cpp
|
| 8597 |
+
for (; first != last; ++first)
|
| 8598 |
+
::new (voidify(*first))
|
| 8599 |
+
typename iterator_traits<NoThrowForwardIterator>::value_type(x);
|
| 8600 |
+
```
|
| 8601 |
+
|
| 8602 |
+
``` cpp
|
| 8603 |
+
namespace ranges {
|
| 8604 |
+
template<no-throw-forward-iterator I, no-throw-sentinel<I> S, class T>
|
| 8605 |
+
requires constructible_from<iter_value_t<I>, const T&>
|
| 8606 |
+
I uninitialized_fill(I first, S last, const T& x);
|
| 8607 |
+
template<no-throw-forward-range R, class T>
|
| 8608 |
+
requires constructible_from<range_value_t<R>, const T&>
|
| 8609 |
+
borrowed_iterator_t<R> uninitialized_fill(R&& r, const T& x);
|
| 8610 |
+
}
|
| 8611 |
+
```
|
| 8612 |
+
|
| 8613 |
+
*Effects:* Equivalent to:
|
| 8614 |
+
|
| 8615 |
+
``` cpp
|
| 8616 |
+
for (; first != last; ++first) {
|
| 8617 |
+
::new (voidify(*first)) remove_reference_t<iter_reference_t<I>>(x);
|
| 8618 |
+
}
|
| 8619 |
+
return first;
|
| 8620 |
+
```
|
| 8621 |
+
|
| 8622 |
+
``` cpp
|
| 8623 |
+
template<class NoThrowForwardIterator, class Size, class T>
|
| 8624 |
+
NoThrowForwardIterator uninitialized_fill_n(NoThrowForwardIterator first, Size n, const T& x);
|
| 8625 |
+
```
|
| 8626 |
+
|
| 8627 |
+
*Effects:* Equivalent to:
|
| 8628 |
+
|
| 8629 |
+
``` cpp
|
| 8630 |
+
for (; n--; ++first)
|
| 8631 |
+
::new (voidify(*first))
|
| 8632 |
+
typename iterator_traits<NoThrowForwardIterator>::value_type(x);
|
| 8633 |
+
return first;
|
| 8634 |
+
```
|
| 8635 |
+
|
| 8636 |
+
``` cpp
|
| 8637 |
+
namespace ranges {
|
| 8638 |
+
template<no-throw-forward-iterator I, class T>
|
| 8639 |
+
requires constructible_from<iter_value_t<I>, const T&>
|
| 8640 |
+
I uninitialized_fill_n(I first, iter_difference_t<I> n, const T& x);
|
| 8641 |
+
}
|
| 8642 |
+
```
|
| 8643 |
+
|
| 8644 |
+
*Effects:* Equivalent to:
|
| 8645 |
+
|
| 8646 |
+
``` cpp
|
| 8647 |
+
return uninitialized_fill(counted_iterator(first, n), default_sentinel, x).base();
|
| 8648 |
+
```
|
| 8649 |
+
|
| 8650 |
+
### `construct_at` <a id="specialized.construct">[[specialized.construct]]</a>
|
| 8651 |
+
|
| 8652 |
+
``` cpp
|
| 8653 |
+
template<class T, class... Args>
|
| 8654 |
+
constexpr T* construct_at(T* location, Args&&... args);
|
| 8655 |
+
|
| 8656 |
+
namespace ranges {
|
| 8657 |
+
template<class T, class... Args>
|
| 8658 |
+
constexpr T* construct_at(T* location, Args&&... args);
|
| 8659 |
+
}
|
| 8660 |
+
```
|
| 8661 |
+
|
| 8662 |
+
*Constraints:* The expression
|
| 8663 |
+
`::new (declval<void*>()) T(declval<Args>()...)` is well-formed when
|
| 8664 |
+
treated as an unevaluated operand.
|
| 8665 |
+
|
| 8666 |
+
*Effects:* Equivalent to:
|
| 8667 |
+
|
| 8668 |
+
``` cpp
|
| 8669 |
+
return ::new (voidify(*location)) T(std::forward<Args>(args)...);
|
| 8670 |
+
```
|
| 8671 |
+
|
| 8672 |
+
### `destroy` <a id="specialized.destroy">[[specialized.destroy]]</a>
|
| 8673 |
+
|
| 8674 |
+
``` cpp
|
| 8675 |
+
template<class T>
|
| 8676 |
+
constexpr void destroy_at(T* location);
|
| 8677 |
+
namespace ranges {
|
| 8678 |
+
template<destructible T>
|
| 8679 |
+
constexpr void destroy_at(T* location) noexcept;
|
| 8680 |
+
}
|
| 8681 |
+
```
|
| 8682 |
+
|
| 8683 |
+
*Effects:*
|
| 8684 |
+
|
| 8685 |
+
- If `T` is an array type, equivalent to
|
| 8686 |
+
`destroy(begin(*location), end(*location))`.
|
| 8687 |
+
- Otherwise, equivalent to `location->T̃()`.
|
| 8688 |
+
|
| 8689 |
+
``` cpp
|
| 8690 |
+
template<class NoThrowForwardIterator>
|
| 8691 |
+
constexpr void destroy(NoThrowForwardIterator first, NoThrowForwardIterator last);
|
| 8692 |
+
```
|
| 8693 |
+
|
| 8694 |
+
*Effects:* Equivalent to:
|
| 8695 |
+
|
| 8696 |
+
``` cpp
|
| 8697 |
+
for (; first != last; ++first)
|
| 8698 |
+
destroy_at(addressof(*first));
|
| 8699 |
+
```
|
| 8700 |
+
|
| 8701 |
+
``` cpp
|
| 8702 |
+
namespace ranges {
|
| 8703 |
+
template<no-throw-input-iterator I, no-throw-sentinel<I> S>
|
| 8704 |
+
requires destructible<iter_value_t<I>>
|
| 8705 |
+
constexpr I destroy(I first, S last) noexcept;
|
| 8706 |
+
template<no-throw-input-range R>
|
| 8707 |
+
requires destructible<range_value_t<R>>
|
| 8708 |
+
constexpr borrowed_iterator_t<R> destroy(R&& r) noexcept;
|
| 8709 |
+
}
|
| 8710 |
+
```
|
| 8711 |
+
|
| 8712 |
+
*Effects:* Equivalent to:
|
| 8713 |
+
|
| 8714 |
+
``` cpp
|
| 8715 |
+
for (; first != last; ++first)
|
| 8716 |
+
destroy_at(addressof(*first));
|
| 8717 |
+
return first;
|
| 8718 |
+
```
|
| 8719 |
+
|
| 8720 |
+
``` cpp
|
| 8721 |
+
template<class NoThrowForwardIterator, class Size>
|
| 8722 |
+
constexpr NoThrowForwardIterator destroy_n(NoThrowForwardIterator first, Size n);
|
| 8723 |
+
```
|
| 8724 |
+
|
| 8725 |
+
*Effects:* Equivalent to:
|
| 8726 |
+
|
| 8727 |
+
``` cpp
|
| 8728 |
+
for (; n > 0; (void)++first, --n)
|
| 8729 |
+
destroy_at(addressof(*first));
|
| 8730 |
+
return first;
|
| 8731 |
+
```
|
| 8732 |
+
|
| 8733 |
+
``` cpp
|
| 8734 |
+
namespace ranges {
|
| 8735 |
+
template<no-throw-input-iterator I>
|
| 8736 |
+
requires destructible<iter_value_t<I>>
|
| 8737 |
+
constexpr I destroy_n(I first, iter_difference_t<I> n) noexcept;
|
| 8738 |
+
}
|
| 8739 |
+
```
|
| 8740 |
+
|
| 8741 |
+
*Effects:* Equivalent to:
|
| 8742 |
+
|
| 8743 |
+
``` cpp
|
| 8744 |
+
return destroy(counted_iterator(first, n), default_sentinel).base();
|
| 8745 |
+
```
|
| 8746 |
+
|
| 8747 |
## C library algorithms <a id="alg.c.library">[[alg.c.library]]</a>
|
| 8748 |
|
| 8749 |
+
[*Note 1*: The header `<cstdlib>` declares the functions described in
|
| 8750 |
+
this subclause. — *end note*]
|
| 8751 |
|
| 8752 |
``` cpp
|
| 8753 |
void* bsearch(const void* key, const void* base, size_t nmemb, size_t size,
|
| 8754 |
c-compare-pred* compar);
|
| 8755 |
void* bsearch(const void* key, const void* base, size_t nmemb, size_t size,
|
|
|
|
| 8759 |
```
|
| 8760 |
|
| 8761 |
*Effects:* These functions have the semantics specified in the C
|
| 8762 |
standard library.
|
| 8763 |
|
| 8764 |
+
*Preconditions:* The objects in the array pointed to by `base` are of
|
| 8765 |
+
trivial type.
|
| 8766 |
|
| 8767 |
+
*Throws:* Any exception thrown by `compar`
|
| 8768 |
+
[[res.on.exception.handling]].
|
| 8769 |
|
| 8770 |
ISO C 7.22.5.
|
| 8771 |
|
| 8772 |
<!-- Link reference definitions -->
|
| 8773 |
+
[accumulate]: #accumulate
|
| 8774 |
+
[adjacent.difference]: #adjacent.difference
|
| 8775 |
[alg.adjacent.find]: #alg.adjacent.find
|
| 8776 |
+
[alg.all.of]: #alg.all.of
|
| 8777 |
+
[alg.any.of]: #alg.any.of
|
| 8778 |
[alg.binary.search]: #alg.binary.search
|
| 8779 |
[alg.c.library]: #alg.c.library
|
| 8780 |
[alg.clamp]: #alg.clamp
|
| 8781 |
[alg.copy]: #alg.copy
|
| 8782 |
[alg.count]: #alg.count
|
|
|
|
| 8786 |
[alg.find.end]: #alg.find.end
|
| 8787 |
[alg.find.first.of]: #alg.find.first.of
|
| 8788 |
[alg.foreach]: #alg.foreach
|
| 8789 |
[alg.generate]: #alg.generate
|
| 8790 |
[alg.heap.operations]: #alg.heap.operations
|
| 8791 |
+
[alg.is.permutation]: #alg.is.permutation
|
| 8792 |
[alg.lex.comparison]: #alg.lex.comparison
|
| 8793 |
[alg.merge]: #alg.merge
|
| 8794 |
[alg.min.max]: #alg.min.max
|
| 8795 |
[alg.modifying.operations]: #alg.modifying.operations
|
| 8796 |
[alg.move]: #alg.move
|
| 8797 |
+
[alg.none.of]: #alg.none.of
|
| 8798 |
[alg.nonmodifying]: #alg.nonmodifying
|
| 8799 |
[alg.nth.element]: #alg.nth.element
|
| 8800 |
[alg.partitions]: #alg.partitions
|
| 8801 |
[alg.permutation.generators]: #alg.permutation.generators
|
| 8802 |
[alg.random.sample]: #alg.random.sample
|
|
|
|
| 8805 |
[alg.replace]: #alg.replace
|
| 8806 |
[alg.reverse]: #alg.reverse
|
| 8807 |
[alg.rotate]: #alg.rotate
|
| 8808 |
[alg.search]: #alg.search
|
| 8809 |
[alg.set.operations]: #alg.set.operations
|
| 8810 |
+
[alg.shift]: #alg.shift
|
| 8811 |
[alg.sort]: #alg.sort
|
| 8812 |
[alg.sorting]: #alg.sorting
|
| 8813 |
[alg.swap]: #alg.swap
|
| 8814 |
+
[alg.three.way]: #alg.three.way
|
| 8815 |
[alg.transform]: #alg.transform
|
| 8816 |
[alg.unique]: #alg.unique
|
| 8817 |
[algorithm.stable]: library.md#algorithm.stable
|
| 8818 |
[algorithm.syn]: #algorithm.syn
|
| 8819 |
[algorithms]: #algorithms
|
|
|
|
| 8823 |
[algorithms.parallel.exceptions]: #algorithms.parallel.exceptions
|
| 8824 |
[algorithms.parallel.exec]: #algorithms.parallel.exec
|
| 8825 |
[algorithms.parallel.overloads]: #algorithms.parallel.overloads
|
| 8826 |
[algorithms.parallel.user]: #algorithms.parallel.user
|
| 8827 |
[algorithms.requirements]: #algorithms.requirements
|
| 8828 |
+
[algorithms.results]: #algorithms.results
|
| 8829 |
+
[algorithms.summary]: #algorithms.summary
|
| 8830 |
+
[basic.compound]: basic.md#basic.compound
|
| 8831 |
+
[basic.lookup.argdep]: basic.md#basic.lookup.argdep
|
| 8832 |
+
[basic.lookup.unqual]: basic.md#basic.lookup.unqual
|
| 8833 |
[bidirectional.iterators]: iterators.md#bidirectional.iterators
|
| 8834 |
[binary.search]: #binary.search
|
| 8835 |
+
[class.conv]: class.md#class.conv
|
| 8836 |
[containers]: containers.md#containers
|
| 8837 |
+
[conv]: expr.md#conv
|
| 8838 |
+
[conv.integral]: expr.md#conv.integral
|
| 8839 |
+
[cpp17.copyassignable]: #cpp17.copyassignable
|
| 8840 |
+
[cpp17.copyconstructible]: #cpp17.copyconstructible
|
| 8841 |
+
[cpp17.lessthancomparable]: #cpp17.lessthancomparable
|
| 8842 |
+
[cpp17.moveassignable]: #cpp17.moveassignable
|
| 8843 |
+
[cpp17.moveconstructible]: #cpp17.moveconstructible
|
| 8844 |
[equal.range]: #equal.range
|
| 8845 |
+
[exclusive.scan]: #exclusive.scan
|
| 8846 |
[execpol]: utilities.md#execpol
|
| 8847 |
+
[expr.call]: expr.md#expr.call
|
| 8848 |
+
[expr.new]: expr.md#expr.new
|
| 8849 |
[forward.iterators]: iterators.md#forward.iterators
|
| 8850 |
[function.objects]: utilities.md#function.objects
|
| 8851 |
[includes]: #includes
|
| 8852 |
+
[inclusive.scan]: #inclusive.scan
|
| 8853 |
+
[inner.product]: #inner.product
|
| 8854 |
[input.iterators]: iterators.md#input.iterators
|
| 8855 |
+
[intro.execution]: basic.md#intro.execution
|
| 8856 |
+
[intro.object]: basic.md#intro.object
|
| 8857 |
+
[intro.progress]: basic.md#intro.progress
|
| 8858 |
[is.heap]: #is.heap
|
| 8859 |
[is.sorted]: #is.sorted
|
| 8860 |
+
[iterator.concept.forward]: iterators.md#iterator.concept.forward
|
| 8861 |
+
[iterator.concept.input]: iterators.md#iterator.concept.input
|
| 8862 |
+
[iterator.concept.sentinel]: iterators.md#iterator.concept.sentinel
|
| 8863 |
+
[iterator.concept.sizedsentinel]: iterators.md#iterator.concept.sizedsentinel
|
| 8864 |
[iterator.requirements]: iterators.md#iterator.requirements
|
| 8865 |
[iterator.requirements.general]: iterators.md#iterator.requirements.general
|
| 8866 |
[lower.bound]: #lower.bound
|
| 8867 |
[make.heap]: #make.heap
|
| 8868 |
[mismatch]: #mismatch
|
| 8869 |
[multiset]: containers.md#multiset
|
| 8870 |
+
[numeric.iota]: #numeric.iota
|
| 8871 |
+
[numeric.ops]: #numeric.ops
|
| 8872 |
+
[numeric.ops.gcd]: #numeric.ops.gcd
|
| 8873 |
+
[numeric.ops.lcm]: #numeric.ops.lcm
|
| 8874 |
+
[numeric.ops.midpoint]: #numeric.ops.midpoint
|
| 8875 |
+
[numeric.ops.overview]: #numeric.ops.overview
|
| 8876 |
+
[numerics.defns]: #numerics.defns
|
| 8877 |
[output.iterators]: iterators.md#output.iterators
|
| 8878 |
[partial.sort]: #partial.sort
|
| 8879 |
[partial.sort.copy]: #partial.sort.copy
|
| 8880 |
+
[partial.sum]: #partial.sum
|
| 8881 |
[pop.heap]: #pop.heap
|
| 8882 |
[push.heap]: #push.heap
|
| 8883 |
[rand.req.urng]: numerics.md#rand.req.urng
|
| 8884 |
[random.access.iterators]: iterators.md#random.access.iterators
|
| 8885 |
+
[range.range]: ranges.md#range.range
|
| 8886 |
+
[reduce]: #reduce
|
| 8887 |
[refwrap]: utilities.md#refwrap
|
| 8888 |
[res.on.exception.handling]: library.md#res.on.exception.handling
|
| 8889 |
[set.difference]: #set.difference
|
| 8890 |
[set.intersection]: #set.intersection
|
| 8891 |
[set.symmetric.difference]: #set.symmetric.difference
|
| 8892 |
[set.union]: #set.union
|
| 8893 |
[sort]: #sort
|
| 8894 |
[sort.heap]: #sort.heap
|
| 8895 |
+
[special.mem.concepts]: #special.mem.concepts
|
| 8896 |
+
[specialized.algorithms]: #specialized.algorithms
|
| 8897 |
+
[specialized.construct]: #specialized.construct
|
| 8898 |
+
[specialized.destroy]: #specialized.destroy
|
| 8899 |
[stable.sort]: #stable.sort
|
| 8900 |
[swappable.requirements]: library.md#swappable.requirements
|
| 8901 |
+
[temp.func.order]: temp.md#temp.func.order
|
| 8902 |
+
[thread.jthread.class]: thread.md#thread.jthread.class
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8903 |
[thread.thread.class]: thread.md#thread.thread.class
|
| 8904 |
+
[transform.exclusive.scan]: #transform.exclusive.scan
|
| 8905 |
+
[transform.inclusive.scan]: #transform.inclusive.scan
|
| 8906 |
+
[transform.reduce]: #transform.reduce
|
| 8907 |
+
[uninitialized.construct.default]: #uninitialized.construct.default
|
| 8908 |
+
[uninitialized.construct.value]: #uninitialized.construct.value
|
| 8909 |
+
[uninitialized.copy]: #uninitialized.copy
|
| 8910 |
+
[uninitialized.fill]: #uninitialized.fill
|
| 8911 |
+
[uninitialized.move]: #uninitialized.move
|
| 8912 |
[upper.bound]: #upper.bound
|
| 8913 |
|
| 8914 |
[^1]: The decision whether to include a copying version was usually
|
| 8915 |
based on complexity considerations. When the cost of doing the
|
| 8916 |
operation dominates the cost of copy, the copying version is not
|
| 8917 |
included. For example, `sort_copy` is not included because the cost
|
| 8918 |
of sorting is much more significant, and users might as well do
|
| 8919 |
`copy` followed by `sort`.
|
| 8920 |
|
| 8921 |
[^2]: `copy_backward` should be used instead of copy when `last` is in
|
| 8922 |
+
the range \[`result - `N, `result`).
|
| 8923 |
|
| 8924 |
+
[^3]: `move_backward` should be used instead of move when `last` is in
|
| 8925 |
+
the range \[`result - `N, `result`).
|
| 8926 |
|
| 8927 |
[^4]: The use of fully closed ranges is intentional.
|
| 8928 |
|
| 8929 |
+
[^5]: This behavior intentionally differs from `max_element`.
|
| 8930 |
+
|
| 8931 |
+
[^6]: The use of fully closed ranges is intentional.
|
| 8932 |
+
|
| 8933 |
+
[^7]: `accumulate` is similar to the APL reduction operator and Common
|
| 8934 |
+
Lisp reduce function, but it avoids the difficulty of defining the
|
| 8935 |
+
result of reduction on an empty sequence by always requiring an
|
| 8936 |
+
initial value.
|
| 8937 |
+
|
| 8938 |
+
[^8]: The use of fully closed ranges is intentional.
|
| 8939 |
+
|
| 8940 |
+
[^9]: The use of fully closed ranges is intentional.
|
| 8941 |
+
|
| 8942 |
+
[^10]: The use of fully closed ranges is intentional.
|