| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | // Qt-Security score:significant reason:default |
| 4 | |
| 5 | #ifndef QTCONCURRENT_FILTER_H |
| 6 | #define QTCONCURRENT_FILTER_H |
| 7 | |
| 8 | #if 0 |
| 9 | #pragma qt_class(QtConcurrentFilter) |
| 10 | #endif |
| 11 | |
| 12 | #include <QtConcurrent/qtconcurrent_global.h> |
| 13 | |
| 14 | #if !defined(QT_NO_CONCURRENT) || defined(Q_QDOC) |
| 15 | |
| 16 | #include <QtConcurrent/qtconcurrentfilterkernel.h> |
| 17 | #include <QtConcurrent/qtconcurrentfunctionwrappers.h> |
| 18 | |
| 19 | QT_BEGIN_NAMESPACE |
| 20 | |
| 21 | namespace QtConcurrent { |
| 22 | |
| 23 | //! [QtConcurrent-1] |
| 24 | template <typename Sequence, typename KeepFunctor, typename ReduceFunctor> |
| 25 | ThreadEngineStarter<void> filterInternal(QThreadPool *pool, Sequence &sequence, |
| 26 | KeepFunctor &&keep, ReduceFunctor &&reduce) |
| 27 | { |
| 28 | typedef FilterKernel<Sequence, std::decay_t<KeepFunctor>, std::decay_t<ReduceFunctor>> |
| 29 | KernelType; |
| 30 | return startThreadEngine(new KernelType(pool, sequence, std::forward<KeepFunctor>(keep), |
| 31 | std::forward<ReduceFunctor>(reduce))); |
| 32 | } |
| 33 | |
| 34 | // filter() on sequences |
| 35 | template <typename Sequence, typename KeepFunctor> |
| 36 | QFuture<void> filter(QThreadPool *pool, Sequence &sequence, KeepFunctor &&keep) |
| 37 | { |
| 38 | return filterInternal(pool, sequence, std::forward<KeepFunctor>(keep), |
| 39 | QtPrivate::PushBackWrapper()); |
| 40 | } |
| 41 | |
| 42 | template <typename Sequence, typename KeepFunctor> |
| 43 | QFuture<void> filter(Sequence &sequence, KeepFunctor &&keep) |
| 44 | { |
| 45 | return filterInternal(QThreadPool::globalInstance(), |
| 46 | sequence, std::forward<KeepFunctor>(keep), QtPrivate::PushBackWrapper()); |
| 47 | } |
| 48 | |
| 49 | // filteredReduced() on sequences |
| 50 | template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor> |
| 51 | QFuture<ResultType> filteredReduced(QThreadPool *pool, |
| 52 | Sequence &&sequence, |
| 53 | KeepFunctor &&keep, |
| 54 | ReduceFunctor &&reduce, |
| 55 | ReduceOptions options = ReduceOptions(UnorderedReduce |
| 56 | | SequentialReduce)) |
| 57 | { |
| 58 | return startFilteredReduced<ResultType>(pool, std::forward<Sequence>(sequence), |
| 59 | std::forward<KeepFunctor>(keep), |
| 60 | std::forward<ReduceFunctor>(reduce), options); |
| 61 | } |
| 62 | |
| 63 | template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor> |
| 64 | QFuture<ResultType> filteredReduced(Sequence &&sequence, |
| 65 | KeepFunctor &&keep, |
| 66 | ReduceFunctor &&reduce, |
| 67 | ReduceOptions options = ReduceOptions(UnorderedReduce |
| 68 | | SequentialReduce)) |
| 69 | { |
| 70 | return startFilteredReduced<ResultType>( |
| 71 | QThreadPool::globalInstance(), std::forward<Sequence>(sequence), |
| 72 | std::forward<KeepFunctor>(keep), std::forward<ReduceFunctor>(reduce), options); |
| 73 | } |
| 74 | |
| 75 | #ifdef Q_QDOC |
| 76 | template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor, |
| 77 | typename InitialValueType> |
| 78 | #else |
| 79 | template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor, |
| 80 | typename InitialValueType, |
| 81 | std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, |
| 82 | int> = 0> |
| 83 | #endif |
| 84 | QFuture<ResultType> filteredReduced(QThreadPool *pool, |
| 85 | Sequence &&sequence, |
| 86 | KeepFunctor &&keep, |
| 87 | ReduceFunctor &&reduce, |
| 88 | InitialValueType &&initialValue, |
| 89 | ReduceOptions options = ReduceOptions(UnorderedReduce |
| 90 | | SequentialReduce)) |
| 91 | { |
| 92 | return startFilteredReduced<ResultType>( |
| 93 | pool, std::forward<Sequence>(sequence), std::forward<KeepFunctor>(keep), |
| 94 | std::forward<ReduceFunctor>(reduce), |
| 95 | ResultType(std::forward<InitialValueType>(initialValue)), options); |
| 96 | } |
| 97 | |
| 98 | #ifdef Q_QDOC |
| 99 | template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor, |
| 100 | typename InitialValueType> |
| 101 | #else |
| 102 | template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor, |
| 103 | typename InitialValueType, |
| 104 | std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, |
| 105 | int> = 0> |
| 106 | #endif |
| 107 | QFuture<ResultType> filteredReduced(Sequence &&sequence, |
| 108 | KeepFunctor &&keep, |
| 109 | ReduceFunctor &&reduce, |
| 110 | InitialValueType &&initialValue, |
| 111 | ReduceOptions options = ReduceOptions(UnorderedReduce |
| 112 | | SequentialReduce)) |
| 113 | { |
| 114 | return startFilteredReduced<ResultType>( |
| 115 | QThreadPool::globalInstance(), std::forward<Sequence>(sequence), |
| 116 | std::forward<KeepFunctor>(keep), std::forward<ReduceFunctor>(reduce), |
| 117 | ResultType(std::forward<InitialValueType>(initialValue)), options); |
| 118 | } |
| 119 | |
| 120 | #ifndef Q_QDOC |
| 121 | template <typename Sequence, typename KeepFunctor, typename ReduceFunctor, |
| 122 | std::enable_if_t<QtPrivate::isInvocable<KeepFunctor, Sequence>::value, int> = 0, |
| 123 | typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type> |
| 124 | QFuture<ResultType> filteredReduced(QThreadPool *pool, |
| 125 | Sequence &&sequence, |
| 126 | KeepFunctor &&keep, |
| 127 | ReduceFunctor &&reduce, |
| 128 | ReduceOptions options = ReduceOptions(UnorderedReduce |
| 129 | | SequentialReduce)) |
| 130 | { |
| 131 | return startFilteredReduced<ResultType>(pool, std::forward<Sequence>(sequence), |
| 132 | std::forward<KeepFunctor>(keep), |
| 133 | std::forward<ReduceFunctor>(reduce), options); |
| 134 | } |
| 135 | |
| 136 | template <typename Sequence, typename KeepFunctor, typename ReduceFunctor, |
| 137 | std::enable_if_t<QtPrivate::isInvocable<KeepFunctor, Sequence>::value, int> = 0, |
| 138 | typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type> |
| 139 | QFuture<ResultType> filteredReduced(Sequence &&sequence, |
| 140 | KeepFunctor &&keep, |
| 141 | ReduceFunctor &&reduce, |
| 142 | ReduceOptions options = ReduceOptions(UnorderedReduce |
| 143 | | SequentialReduce)) |
| 144 | { |
| 145 | return startFilteredReduced<ResultType>( |
| 146 | QThreadPool::globalInstance(), std::forward<Sequence>(sequence), |
| 147 | std::forward<KeepFunctor>(keep), std::forward<ReduceFunctor>(reduce), options); |
| 148 | } |
| 149 | |
| 150 | template <typename Sequence, typename KeepFunctor, typename ReduceFunctor, |
| 151 | typename InitialValueType, |
| 152 | std::enable_if_t<QtPrivate::isInvocable<KeepFunctor, Sequence>::value, int> = 0, |
| 153 | typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type, |
| 154 | std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, |
| 155 | int> = 0> |
| 156 | QFuture<ResultType> filteredReduced(QThreadPool *pool, |
| 157 | Sequence &&sequence, |
| 158 | KeepFunctor &&keep, |
| 159 | ReduceFunctor &&reduce, |
| 160 | InitialValueType &&initialValue, |
| 161 | ReduceOptions options = ReduceOptions(UnorderedReduce |
| 162 | | SequentialReduce)) |
| 163 | { |
| 164 | return startFilteredReduced<ResultType>( |
| 165 | pool, std::forward<Sequence>(sequence), std::forward<KeepFunctor>(keep), |
| 166 | std::forward<ReduceFunctor>(reduce), |
| 167 | ResultType(std::forward<InitialValueType>(initialValue)), options); |
| 168 | } |
| 169 | |
| 170 | template <typename Sequence, typename KeepFunctor, typename ReduceFunctor, |
| 171 | typename InitialValueType, |
| 172 | std::enable_if_t<QtPrivate::isInvocable<KeepFunctor, Sequence>::value, int> = 0, |
| 173 | typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type, |
| 174 | std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, |
| 175 | int> = 0> |
| 176 | QFuture<ResultType> filteredReduced(Sequence &&sequence, |
| 177 | KeepFunctor &&keep, |
| 178 | ReduceFunctor &&reduce, |
| 179 | InitialValueType &&initialValue, |
| 180 | ReduceOptions options = ReduceOptions(UnorderedReduce |
| 181 | | SequentialReduce)) |
| 182 | { |
| 183 | return startFilteredReduced<ResultType>( |
| 184 | QThreadPool::globalInstance(), std::forward<Sequence>(sequence), |
| 185 | std::forward<KeepFunctor>(keep), std::forward<ReduceFunctor>(reduce), |
| 186 | ResultType(std::forward<InitialValueType>(initialValue)), options); |
| 187 | } |
| 188 | #endif |
| 189 | |
| 190 | // filteredReduced() on iterators |
| 191 | template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor> |
| 192 | QFuture<ResultType> filteredReduced(QThreadPool *pool, |
| 193 | Iterator begin, |
| 194 | Iterator end, |
| 195 | KeepFunctor &&keep, |
| 196 | ReduceFunctor &&reduce, |
| 197 | ReduceOptions options = ReduceOptions(UnorderedReduce |
| 198 | | SequentialReduce)) |
| 199 | { |
| 200 | return startFilteredReduced<ResultType>(pool, begin, end, std::forward<KeepFunctor>(keep), |
| 201 | std::forward<ReduceFunctor>(reduce), options); |
| 202 | } |
| 203 | |
| 204 | template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor> |
| 205 | QFuture<ResultType> filteredReduced(Iterator begin, |
| 206 | Iterator end, |
| 207 | KeepFunctor &&keep, |
| 208 | ReduceFunctor &&reduce, |
| 209 | ReduceOptions options = ReduceOptions(UnorderedReduce |
| 210 | | SequentialReduce)) |
| 211 | { |
| 212 | return startFilteredReduced<ResultType>(QThreadPool::globalInstance(), begin, end, |
| 213 | std::forward<KeepFunctor>(keep), |
| 214 | std::forward<ReduceFunctor>(reduce), options); |
| 215 | } |
| 216 | |
| 217 | #ifdef Q_QDOC |
| 218 | template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor, |
| 219 | typename InitialValueType> |
| 220 | #else |
| 221 | template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor, |
| 222 | typename InitialValueType, |
| 223 | std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, |
| 224 | int> = 0> |
| 225 | #endif |
| 226 | QFuture<ResultType> filteredReduced(QThreadPool *pool, |
| 227 | Iterator begin, |
| 228 | Iterator end, |
| 229 | KeepFunctor &&keep, |
| 230 | ReduceFunctor &&reduce, |
| 231 | InitialValueType &&initialValue, |
| 232 | ReduceOptions options = ReduceOptions(UnorderedReduce |
| 233 | | SequentialReduce)) |
| 234 | { |
| 235 | return startFilteredReduced<ResultType>( |
| 236 | pool, begin, end, std::forward<KeepFunctor>(keep), std::forward<ReduceFunctor>(reduce), |
| 237 | ResultType(std::forward<InitialValueType>(initialValue)), options); |
| 238 | } |
| 239 | |
| 240 | #ifdef Q_QDOC |
| 241 | template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor, |
| 242 | typename InitialValueType> |
| 243 | #else |
| 244 | template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor, |
| 245 | typename InitialValueType, |
| 246 | std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, |
| 247 | int> = 0> |
| 248 | #endif |
| 249 | QFuture<ResultType> filteredReduced(Iterator begin, |
| 250 | Iterator end, |
| 251 | KeepFunctor &&keep, |
| 252 | ReduceFunctor &&reduce, |
| 253 | InitialValueType &&initialValue, |
| 254 | ReduceOptions options = ReduceOptions(UnorderedReduce |
| 255 | | SequentialReduce)) |
| 256 | { |
| 257 | return startFilteredReduced<ResultType>( |
| 258 | QThreadPool::globalInstance(), begin, end, std::forward<KeepFunctor>(keep), |
| 259 | std::forward<ReduceFunctor>(reduce), |
| 260 | ResultType(std::forward<InitialValueType>(initialValue)), options); |
| 261 | } |
| 262 | |
| 263 | #ifndef Q_QDOC |
| 264 | template <typename Iterator, typename KeepFunctor, typename ReduceFunctor, |
| 265 | typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type> |
| 266 | QFuture<ResultType> filteredReduced(QThreadPool *pool, |
| 267 | Iterator begin, |
| 268 | Iterator end, |
| 269 | KeepFunctor &&keep, |
| 270 | ReduceFunctor &&reduce, |
| 271 | ReduceOptions options = ReduceOptions(UnorderedReduce |
| 272 | | SequentialReduce)) |
| 273 | { |
| 274 | return startFilteredReduced<ResultType>(pool, begin, end, std::forward<KeepFunctor>(keep), |
| 275 | std::forward<ReduceFunctor>(reduce), options); |
| 276 | } |
| 277 | |
| 278 | template <typename Iterator, typename KeepFunctor, typename ReduceFunctor, |
| 279 | typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type> |
| 280 | QFuture<ResultType> filteredReduced(Iterator begin, |
| 281 | Iterator end, |
| 282 | KeepFunctor &&keep, |
| 283 | ReduceFunctor &&reduce, |
| 284 | ReduceOptions options = ReduceOptions(UnorderedReduce |
| 285 | | SequentialReduce)) |
| 286 | { |
| 287 | return startFilteredReduced<ResultType>(QThreadPool::globalInstance(), begin, end, |
| 288 | std::forward<KeepFunctor>(keep), |
| 289 | std::forward<ReduceFunctor>(reduce), options); |
| 290 | } |
| 291 | |
| 292 | template <typename Iterator, typename KeepFunctor, typename ReduceFunctor, |
| 293 | typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type, |
| 294 | typename InitialValueType, |
| 295 | std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, |
| 296 | int> = 0> |
| 297 | QFuture<ResultType> filteredReduced(QThreadPool *pool, |
| 298 | Iterator begin, |
| 299 | Iterator end, |
| 300 | KeepFunctor &&keep, |
| 301 | ReduceFunctor &&reduce, |
| 302 | InitialValueType &&initialValue, |
| 303 | ReduceOptions options = ReduceOptions(UnorderedReduce |
| 304 | | SequentialReduce)) |
| 305 | { |
| 306 | return startFilteredReduced<ResultType>( |
| 307 | pool, begin, end, std::forward<KeepFunctor>(keep), std::forward<ReduceFunctor>(reduce), |
| 308 | ResultType(std::forward<InitialValueType>(initialValue)), options); |
| 309 | } |
| 310 | |
| 311 | template <typename Iterator, typename KeepFunctor, typename ReduceFunctor, |
| 312 | std::enable_if_t<QtPrivate::isIterator_v<Iterator>, int> = 0, |
| 313 | typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type, |
| 314 | typename InitialValueType, |
| 315 | std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, |
| 316 | int> = 0> |
| 317 | QFuture<ResultType> filteredReduced(Iterator begin, |
| 318 | Iterator end, |
| 319 | KeepFunctor &&keep, |
| 320 | ReduceFunctor &&reduce, |
| 321 | InitialValueType &&initialValue, |
| 322 | ReduceOptions options = ReduceOptions(UnorderedReduce |
| 323 | | SequentialReduce)) |
| 324 | { |
| 325 | return startFilteredReduced<ResultType>( |
| 326 | QThreadPool::globalInstance(), begin, end, std::forward<KeepFunctor>(keep), |
| 327 | std::forward<ReduceFunctor>(reduce), |
| 328 | ResultType(std::forward<InitialValueType>(initialValue)), options); |
| 329 | } |
| 330 | #endif |
| 331 | |
| 332 | // filtered() on sequences |
| 333 | template <typename Sequence, typename KeepFunctor> |
| 334 | QFuture<typename std::decay_t<Sequence>::value_type> filtered(QThreadPool *pool,Sequence &&sequence, |
| 335 | KeepFunctor &&keep) |
| 336 | { |
| 337 | return startFiltered(pool, std::forward<Sequence>(sequence), std::forward<KeepFunctor>(keep)); |
| 338 | } |
| 339 | |
| 340 | template <typename Sequence, typename KeepFunctor> |
| 341 | QFuture<typename std::decay_t<Sequence>::value_type> filtered(Sequence &&sequence, |
| 342 | KeepFunctor &&keep) |
| 343 | { |
| 344 | return startFiltered(QThreadPool::globalInstance(), std::forward<Sequence>(sequence), |
| 345 | std::forward<KeepFunctor>(keep)); |
| 346 | } |
| 347 | |
| 348 | // filtered() on iterators |
| 349 | template <typename Iterator, typename KeepFunctor> |
| 350 | QFuture<typename qValueType<Iterator>::value_type> filtered(QThreadPool *pool, |
| 351 | Iterator begin, |
| 352 | Iterator end, |
| 353 | KeepFunctor &&keep) |
| 354 | { |
| 355 | return startFiltered(pool, begin, end, std::forward<KeepFunctor>(keep)); |
| 356 | } |
| 357 | |
| 358 | template <typename Iterator, typename KeepFunctor> |
| 359 | QFuture<typename qValueType<Iterator>::value_type> filtered(Iterator begin, |
| 360 | Iterator end, |
| 361 | KeepFunctor &&keep) |
| 362 | { |
| 363 | return startFiltered(QThreadPool::globalInstance(), begin, end, |
| 364 | std::forward<KeepFunctor>(keep)); |
| 365 | } |
| 366 | |
| 367 | // blocking filter() on sequences |
| 368 | template <typename Sequence, typename KeepFunctor> |
| 369 | void blockingFilter(QThreadPool *pool, Sequence &sequence, KeepFunctor &&keep) |
| 370 | { |
| 371 | QFuture<void> future = filter(pool, sequence, std::forward<KeepFunctor>(keep)); |
| 372 | future.waitForFinished(); |
| 373 | } |
| 374 | |
| 375 | template <typename Sequence, typename KeepFunctor> |
| 376 | void blockingFilter(Sequence &sequence, KeepFunctor &&keep) |
| 377 | { |
| 378 | QFuture<void> future = filter(sequence, std::forward<KeepFunctor>(keep)); |
| 379 | future.waitForFinished(); |
| 380 | } |
| 381 | |
| 382 | // blocking filteredReduced() on sequences |
| 383 | template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor> |
| 384 | ResultType blockingFilteredReduced(QThreadPool *pool, |
| 385 | Sequence &&sequence, |
| 386 | KeepFunctor &&keep, |
| 387 | ReduceFunctor &&reduce, |
| 388 | ReduceOptions options = ReduceOptions(UnorderedReduce |
| 389 | | SequentialReduce)) |
| 390 | { |
| 391 | QFuture<ResultType> future = filteredReduced<ResultType>( |
| 392 | pool, std::forward<Sequence>(sequence), std::forward<KeepFunctor>(keep), |
| 393 | std::forward<ReduceFunctor>(reduce), options); |
| 394 | return future.takeResult(); |
| 395 | } |
| 396 | |
| 397 | template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor> |
| 398 | ResultType blockingFilteredReduced(Sequence &&sequence, |
| 399 | KeepFunctor &&keep, |
| 400 | ReduceFunctor &&reduce, |
| 401 | ReduceOptions options = ReduceOptions(UnorderedReduce |
| 402 | | SequentialReduce)) |
| 403 | { |
| 404 | QFuture<ResultType> future = filteredReduced<ResultType>( |
| 405 | std::forward<Sequence>(sequence), std::forward<KeepFunctor>(keep), |
| 406 | std::forward<ReduceFunctor>(reduce), options); |
| 407 | return future.takeResult(); |
| 408 | } |
| 409 | |
| 410 | #ifdef Q_QDOC |
| 411 | template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor, |
| 412 | typename InitialValueType> |
| 413 | #else |
| 414 | template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor, |
| 415 | typename InitialValueType, |
| 416 | std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, |
| 417 | int> = 0> |
| 418 | #endif |
| 419 | ResultType blockingFilteredReduced(QThreadPool *pool, |
| 420 | Sequence &&sequence, |
| 421 | KeepFunctor &&keep, |
| 422 | ReduceFunctor &&reduce, |
| 423 | InitialValueType &&initialValue, |
| 424 | ReduceOptions options = ReduceOptions(UnorderedReduce |
| 425 | | SequentialReduce)) |
| 426 | { |
| 427 | QFuture<ResultType> future = filteredReduced<ResultType>( |
| 428 | pool, std::forward<Sequence>(sequence), std::forward<KeepFunctor>(keep), |
| 429 | std::forward<ReduceFunctor>(reduce), |
| 430 | ResultType(std::forward<InitialValueType>(initialValue)), options); |
| 431 | return future.takeResult(); |
| 432 | } |
| 433 | |
| 434 | #ifdef Q_QDOC |
| 435 | template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor, |
| 436 | typename InitialValueType> |
| 437 | #else |
| 438 | template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor, |
| 439 | typename InitialValueType, |
| 440 | std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, |
| 441 | int> = 0> |
| 442 | #endif |
| 443 | ResultType blockingFilteredReduced(Sequence &&sequence, |
| 444 | KeepFunctor &&keep, |
| 445 | ReduceFunctor &&reduce, |
| 446 | InitialValueType &&initialValue, |
| 447 | ReduceOptions options = ReduceOptions(UnorderedReduce |
| 448 | | SequentialReduce)) |
| 449 | { |
| 450 | QFuture<ResultType> future = filteredReduced<ResultType>( |
| 451 | std::forward<Sequence>(sequence), std::forward<KeepFunctor>(keep), |
| 452 | std::forward<ReduceFunctor>(reduce), |
| 453 | ResultType(std::forward<InitialValueType>(initialValue)), options); |
| 454 | return future.takeResult(); |
| 455 | } |
| 456 | |
| 457 | #ifndef Q_QDOC |
| 458 | template <typename Sequence, typename KeepFunctor, typename ReduceFunctor, |
| 459 | std::enable_if_t<QtPrivate::isInvocable<KeepFunctor, Sequence>::value, int> = 0, |
| 460 | typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type> |
| 461 | ResultType blockingFilteredReduced(QThreadPool *pool, |
| 462 | Sequence &&sequence, |
| 463 | KeepFunctor &&keep, |
| 464 | ReduceFunctor &&reduce, |
| 465 | ReduceOptions options = ReduceOptions(UnorderedReduce |
| 466 | | SequentialReduce)) |
| 467 | { |
| 468 | QFuture<ResultType> future = filteredReduced<ResultType>( |
| 469 | pool, std::forward<Sequence>(sequence), std::forward<KeepFunctor>(keep), |
| 470 | std::forward<ReduceFunctor>(reduce), options); |
| 471 | return future.takeResult(); |
| 472 | } |
| 473 | |
| 474 | template <typename Sequence, typename KeepFunctor, typename ReduceFunctor, |
| 475 | std::enable_if_t<QtPrivate::isInvocable<KeepFunctor, Sequence>::value, int> = 0, |
| 476 | typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type> |
| 477 | ResultType blockingFilteredReduced(Sequence &&sequence, |
| 478 | KeepFunctor &&keep, |
| 479 | ReduceFunctor &&reduce, |
| 480 | ReduceOptions options = ReduceOptions(UnorderedReduce |
| 481 | | SequentialReduce)) |
| 482 | { |
| 483 | QFuture<ResultType> future = filteredReduced<ResultType>( |
| 484 | std::forward<Sequence>(sequence), std::forward<KeepFunctor>(keep), |
| 485 | std::forward<ReduceFunctor>(reduce), options); |
| 486 | return future.takeResult(); |
| 487 | } |
| 488 | |
| 489 | template <typename Sequence, typename KeepFunctor, typename ReduceFunctor, |
| 490 | typename InitialValueType, |
| 491 | std::enable_if_t<QtPrivate::isInvocable<KeepFunctor, Sequence>::value, int> = 0, |
| 492 | typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type, |
| 493 | std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, |
| 494 | int> = 0> |
| 495 | ResultType blockingFilteredReduced(QThreadPool *pool, |
| 496 | Sequence &&sequence, |
| 497 | KeepFunctor &&keep, |
| 498 | ReduceFunctor &&reduce, |
| 499 | InitialValueType &&initialValue, |
| 500 | ReduceOptions options = ReduceOptions(UnorderedReduce |
| 501 | | SequentialReduce)) |
| 502 | { |
| 503 | QFuture<ResultType> future = filteredReduced<ResultType>( |
| 504 | pool, std::forward<Sequence>(sequence), std::forward<KeepFunctor>(keep), |
| 505 | std::forward<ReduceFunctor>(reduce), |
| 506 | ResultType(std::forward<InitialValueType>(initialValue)), options); |
| 507 | return future.takeResult(); |
| 508 | } |
| 509 | |
| 510 | template <typename Sequence, typename KeepFunctor, typename ReduceFunctor, |
| 511 | typename InitialValueType, |
| 512 | std::enable_if_t<QtPrivate::isInvocable<KeepFunctor, Sequence>::value, int> = 0, |
| 513 | typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type, |
| 514 | std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, |
| 515 | int> = 0> |
| 516 | ResultType blockingFilteredReduced(Sequence &&sequence, |
| 517 | KeepFunctor &&keep, |
| 518 | ReduceFunctor &&reduce, |
| 519 | InitialValueType &&initialValue, |
| 520 | ReduceOptions options = ReduceOptions(UnorderedReduce |
| 521 | | SequentialReduce)) |
| 522 | { |
| 523 | QFuture<ResultType> future = filteredReduced<ResultType>( |
| 524 | std::forward<Sequence>(sequence), std::forward<KeepFunctor>(keep), |
| 525 | std::forward<ReduceFunctor>(reduce), |
| 526 | ResultType(std::forward<InitialValueType>(initialValue)), options); |
| 527 | return future.takeResult(); |
| 528 | } |
| 529 | #endif |
| 530 | |
| 531 | // blocking filteredReduced() on iterators |
| 532 | template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor> |
| 533 | ResultType blockingFilteredReduced(QThreadPool *pool, |
| 534 | Iterator begin, |
| 535 | Iterator end, |
| 536 | KeepFunctor &&keep, |
| 537 | ReduceFunctor &&reduce, |
| 538 | ReduceOptions options = ReduceOptions(UnorderedReduce |
| 539 | | SequentialReduce)) |
| 540 | { |
| 541 | QFuture<ResultType> future = |
| 542 | filteredReduced<ResultType>(pool, begin, end, std::forward<KeepFunctor>(keep), |
| 543 | std::forward<ReduceFunctor>(reduce), options); |
| 544 | return future.takeResult(); |
| 545 | } |
| 546 | |
| 547 | template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor> |
| 548 | ResultType blockingFilteredReduced(Iterator begin, |
| 549 | Iterator end, |
| 550 | KeepFunctor &&keep, |
| 551 | ReduceFunctor &&reduce, |
| 552 | ReduceOptions options = ReduceOptions(UnorderedReduce |
| 553 | | SequentialReduce)) |
| 554 | { |
| 555 | QFuture<ResultType> future = |
| 556 | filteredReduced<ResultType>(begin, end, std::forward<KeepFunctor>(keep), |
| 557 | std::forward<ReduceFunctor>(reduce), options); |
| 558 | return future.takeResult(); |
| 559 | } |
| 560 | |
| 561 | #ifdef Q_QDOC |
| 562 | template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor, |
| 563 | typename InitialValueType> |
| 564 | #else |
| 565 | template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor, |
| 566 | typename InitialValueType, |
| 567 | std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, |
| 568 | int> = 0> |
| 569 | #endif |
| 570 | ResultType blockingFilteredReduced(QThreadPool *pool, |
| 571 | Iterator begin, |
| 572 | Iterator end, |
| 573 | KeepFunctor &&keep, |
| 574 | ReduceFunctor &&reduce, |
| 575 | InitialValueType &&initialValue, |
| 576 | ReduceOptions options = ReduceOptions(UnorderedReduce |
| 577 | | SequentialReduce)) |
| 578 | { |
| 579 | QFuture<ResultType> future = filteredReduced<ResultType>( |
| 580 | pool, begin, end, std::forward<KeepFunctor>(keep), std::forward<ReduceFunctor>(reduce), |
| 581 | ResultType(std::forward<InitialValueType>(initialValue)), options); |
| 582 | return future.takeResult(); |
| 583 | } |
| 584 | |
| 585 | #ifdef Q_QDOC |
| 586 | template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor, |
| 587 | typename InitialValueType> |
| 588 | #else |
| 589 | template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor, |
| 590 | typename InitialValueType, |
| 591 | std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, |
| 592 | int> = 0> |
| 593 | #endif |
| 594 | ResultType blockingFilteredReduced(Iterator begin, |
| 595 | Iterator end, |
| 596 | KeepFunctor &&keep, |
| 597 | ReduceFunctor &&reduce, |
| 598 | InitialValueType &&initialValue, |
| 599 | ReduceOptions options = ReduceOptions(UnorderedReduce |
| 600 | | SequentialReduce)) |
| 601 | { |
| 602 | QFuture<ResultType> future = filteredReduced<ResultType>( |
| 603 | begin, end, std::forward<KeepFunctor>(keep), std::forward<ReduceFunctor>(reduce), |
| 604 | ResultType(std::forward<InitialValueType>(initialValue)), options); |
| 605 | return future.takeResult(); |
| 606 | } |
| 607 | |
| 608 | #ifndef Q_QDOC |
| 609 | template <typename Iterator, typename KeepFunctor, typename ReduceFunctor, |
| 610 | typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type> |
| 611 | ResultType blockingFilteredReduced(QThreadPool *pool, |
| 612 | Iterator begin, |
| 613 | Iterator end, |
| 614 | KeepFunctor &&keep, |
| 615 | ReduceFunctor &&reduce, |
| 616 | ReduceOptions options = ReduceOptions(UnorderedReduce |
| 617 | | SequentialReduce)) |
| 618 | { |
| 619 | QFuture<ResultType> future = |
| 620 | filteredReduced<ResultType>(pool, begin, end, std::forward<KeepFunctor>(keep), |
| 621 | std::forward<ReduceFunctor>(reduce), options); |
| 622 | return future.takeResult(); |
| 623 | } |
| 624 | |
| 625 | template <typename Iterator, typename KeepFunctor, typename ReduceFunctor, |
| 626 | typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type> |
| 627 | ResultType blockingFilteredReduced(Iterator begin, |
| 628 | Iterator end, |
| 629 | KeepFunctor &&keep, |
| 630 | ReduceFunctor &&reduce, |
| 631 | ReduceOptions options = ReduceOptions(UnorderedReduce |
| 632 | | SequentialReduce)) |
| 633 | { |
| 634 | QFuture<ResultType> future = |
| 635 | filteredReduced<ResultType>(begin, end, std::forward<KeepFunctor>(keep), |
| 636 | std::forward<ReduceFunctor>(reduce), options); |
| 637 | return future.takeResult(); |
| 638 | } |
| 639 | |
| 640 | template <typename Iterator, typename KeepFunctor, typename ReduceFunctor, |
| 641 | typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type, |
| 642 | typename InitialValueType, |
| 643 | std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, |
| 644 | int> = 0> |
| 645 | ResultType blockingFilteredReduced(QThreadPool *pool, |
| 646 | Iterator begin, |
| 647 | Iterator end, KeepFunctor &&keep, |
| 648 | ReduceFunctor &&reduce, |
| 649 | InitialValueType &&initialValue, |
| 650 | ReduceOptions options = ReduceOptions(UnorderedReduce |
| 651 | | SequentialReduce)) |
| 652 | { |
| 653 | QFuture<ResultType> future = filteredReduced<ResultType>( |
| 654 | pool, begin, end, std::forward<KeepFunctor>(keep), std::forward<ReduceFunctor>(reduce), |
| 655 | ResultType(std::forward<InitialValueType>(initialValue)), options); |
| 656 | return future.takeResult(); |
| 657 | } |
| 658 | |
| 659 | template <typename Iterator, typename KeepFunctor, typename ReduceFunctor, |
| 660 | std::enable_if_t<QtPrivate::isIterator_v<Iterator>, int> = 0, |
| 661 | typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type, |
| 662 | typename InitialValueType, |
| 663 | std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, |
| 664 | int> = 0> |
| 665 | ResultType blockingFilteredReduced(Iterator begin, |
| 666 | Iterator end, |
| 667 | KeepFunctor &&keep, |
| 668 | ReduceFunctor &&reduce, |
| 669 | InitialValueType &&initialValue, |
| 670 | ReduceOptions options = ReduceOptions(UnorderedReduce |
| 671 | | SequentialReduce)) |
| 672 | { |
| 673 | QFuture<ResultType> future = filteredReduced<ResultType>( |
| 674 | begin, end, std::forward<KeepFunctor>(keep), std::forward<ReduceFunctor>(reduce), |
| 675 | ResultType(std::forward<InitialValueType>(initialValue)), options); |
| 676 | return future.takeResult(); |
| 677 | } |
| 678 | #endif |
| 679 | |
| 680 | // blocking filtered() on sequences |
| 681 | template <typename Sequence, typename KeepFunctor> |
| 682 | std::decay_t<Sequence> blockingFiltered(QThreadPool *pool, Sequence &&sequence, KeepFunctor &&keep) |
| 683 | { |
| 684 | return blockingFilteredReduced<std::decay_t<Sequence>>( |
| 685 | pool, std::forward<Sequence>(sequence), std::forward<KeepFunctor>(keep), |
| 686 | QtPrivate::PushBackWrapper(), OrderedReduce); |
| 687 | } |
| 688 | |
| 689 | template <typename Sequence, typename KeepFunctor> |
| 690 | std::decay_t<Sequence> blockingFiltered(Sequence &&sequence, KeepFunctor &&keep) |
| 691 | { |
| 692 | return blockingFilteredReduced<std::decay_t<Sequence>>( |
| 693 | QThreadPool::globalInstance(), std::forward<Sequence>(sequence), |
| 694 | std::forward<KeepFunctor>(keep), QtPrivate::PushBackWrapper(), OrderedReduce); |
| 695 | } |
| 696 | |
| 697 | // blocking filtered() on iterators |
| 698 | template <typename OutputSequence, typename Iterator, typename KeepFunctor> |
| 699 | OutputSequence blockingFiltered(QThreadPool *pool, Iterator begin, Iterator end, KeepFunctor &&keep) |
| 700 | { |
| 701 | return blockingFilteredReduced<OutputSequence>(pool, begin, end, |
| 702 | std::forward<KeepFunctor>(keep), |
| 703 | QtPrivate::PushBackWrapper(), OrderedReduce); |
| 704 | } |
| 705 | |
| 706 | template <typename OutputSequence, typename Iterator, typename KeepFunctor> |
| 707 | OutputSequence blockingFiltered(Iterator begin, Iterator end, KeepFunctor &&keep) |
| 708 | { |
| 709 | return blockingFilteredReduced<OutputSequence>(QThreadPool::globalInstance(), begin, end, |
| 710 | std::forward<KeepFunctor>(keep), |
| 711 | QtPrivate::PushBackWrapper(), OrderedReduce); |
| 712 | } |
| 713 | |
| 714 | } // namespace QtConcurrent |
| 715 | |
| 716 | QT_END_NAMESPACE |
| 717 | |
| 718 | #endif // QT_NO_CONCURRENT |
| 719 | |
| 720 | #endif |
| 721 | |