File indexing completed on 2026-01-07 10:15:52
0001
0002
0003
0004
0005 #ifndef QTCONCURRENT_FILTER_H
0006 #define QTCONCURRENT_FILTER_H
0007
0008 #if 0
0009 #pragma qt_class(QtConcurrentFilter)
0010 #endif
0011
0012 #include <QtConcurrent/qtconcurrent_global.h>
0013
0014 #if !defined(QT_NO_CONCURRENT) || defined(Q_QDOC)
0015
0016 #include <QtConcurrent/qtconcurrentfilterkernel.h>
0017 #include <QtConcurrent/qtconcurrentfunctionwrappers.h>
0018
0019 QT_BEGIN_NAMESPACE
0020
0021 namespace QtConcurrent {
0022
0023
0024 template <typename Sequence, typename KeepFunctor, typename ReduceFunctor>
0025 ThreadEngineStarter<void> filterInternal(QThreadPool *pool, Sequence &sequence,
0026 KeepFunctor &&keep, ReduceFunctor &&reduce)
0027 {
0028 typedef FilterKernel<Sequence, std::decay_t<KeepFunctor>, std::decay_t<ReduceFunctor>>
0029 KernelType;
0030 return startThreadEngine(new KernelType(pool, sequence, std::forward<KeepFunctor>(keep),
0031 std::forward<ReduceFunctor>(reduce)));
0032 }
0033
0034
0035 template <typename Sequence, typename KeepFunctor>
0036 QFuture<void> filter(QThreadPool *pool, Sequence &sequence, KeepFunctor &&keep)
0037 {
0038 return filterInternal(pool, sequence, std::forward<KeepFunctor>(keep),
0039 QtPrivate::PushBackWrapper());
0040 }
0041
0042 template <typename Sequence, typename KeepFunctor>
0043 QFuture<void> filter(Sequence &sequence, KeepFunctor &&keep)
0044 {
0045 return filterInternal(QThreadPool::globalInstance(),
0046 sequence, std::forward<KeepFunctor>(keep), QtPrivate::PushBackWrapper());
0047 }
0048
0049
0050 template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor>
0051 QFuture<ResultType> filteredReduced(QThreadPool *pool,
0052 Sequence &&sequence,
0053 KeepFunctor &&keep,
0054 ReduceFunctor &&reduce,
0055 ReduceOptions options = ReduceOptions(UnorderedReduce
0056 | SequentialReduce))
0057 {
0058 return startFilteredReduced<ResultType>(pool, std::forward<Sequence>(sequence),
0059 std::forward<KeepFunctor>(keep),
0060 std::forward<ReduceFunctor>(reduce), options);
0061 }
0062
0063 template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor>
0064 QFuture<ResultType> filteredReduced(Sequence &&sequence,
0065 KeepFunctor &&keep,
0066 ReduceFunctor &&reduce,
0067 ReduceOptions options = ReduceOptions(UnorderedReduce
0068 | SequentialReduce))
0069 {
0070 return startFilteredReduced<ResultType>(
0071 QThreadPool::globalInstance(), std::forward<Sequence>(sequence),
0072 std::forward<KeepFunctor>(keep), std::forward<ReduceFunctor>(reduce), options);
0073 }
0074
0075 #ifdef Q_QDOC
0076 template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor,
0077 typename InitialValueType>
0078 #else
0079 template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor,
0080 typename InitialValueType,
0081 std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>,
0082 int> = 0>
0083 #endif
0084 QFuture<ResultType> filteredReduced(QThreadPool *pool,
0085 Sequence &&sequence,
0086 KeepFunctor &&keep,
0087 ReduceFunctor &&reduce,
0088 InitialValueType &&initialValue,
0089 ReduceOptions options = ReduceOptions(UnorderedReduce
0090 | SequentialReduce))
0091 {
0092 return startFilteredReduced<ResultType>(
0093 pool, std::forward<Sequence>(sequence), std::forward<KeepFunctor>(keep),
0094 std::forward<ReduceFunctor>(reduce),
0095 ResultType(std::forward<InitialValueType>(initialValue)), options);
0096 }
0097
0098 #ifdef Q_QDOC
0099 template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor,
0100 typename InitialValueType>
0101 #else
0102 template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor,
0103 typename InitialValueType,
0104 std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>,
0105 int> = 0>
0106 #endif
0107 QFuture<ResultType> filteredReduced(Sequence &&sequence,
0108 KeepFunctor &&keep,
0109 ReduceFunctor &&reduce,
0110 InitialValueType &&initialValue,
0111 ReduceOptions options = ReduceOptions(UnorderedReduce
0112 | SequentialReduce))
0113 {
0114 return startFilteredReduced<ResultType>(
0115 QThreadPool::globalInstance(), std::forward<Sequence>(sequence),
0116 std::forward<KeepFunctor>(keep), std::forward<ReduceFunctor>(reduce),
0117 ResultType(std::forward<InitialValueType>(initialValue)), options);
0118 }
0119
0120 #ifndef Q_QDOC
0121 template <typename Sequence, typename KeepFunctor, typename ReduceFunctor,
0122 std::enable_if_t<QtPrivate::isInvocable<KeepFunctor, Sequence>::value, int> = 0,
0123 typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type>
0124 QFuture<ResultType> filteredReduced(QThreadPool *pool,
0125 Sequence &&sequence,
0126 KeepFunctor &&keep,
0127 ReduceFunctor &&reduce,
0128 ReduceOptions options = ReduceOptions(UnorderedReduce
0129 | SequentialReduce))
0130 {
0131 return startFilteredReduced<ResultType>(pool, std::forward<Sequence>(sequence),
0132 std::forward<KeepFunctor>(keep),
0133 std::forward<ReduceFunctor>(reduce), options);
0134 }
0135
0136 template <typename Sequence, typename KeepFunctor, typename ReduceFunctor,
0137 std::enable_if_t<QtPrivate::isInvocable<KeepFunctor, Sequence>::value, int> = 0,
0138 typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type>
0139 QFuture<ResultType> filteredReduced(Sequence &&sequence,
0140 KeepFunctor &&keep,
0141 ReduceFunctor &&reduce,
0142 ReduceOptions options = ReduceOptions(UnorderedReduce
0143 | SequentialReduce))
0144 {
0145 return startFilteredReduced<ResultType>(
0146 QThreadPool::globalInstance(), std::forward<Sequence>(sequence),
0147 std::forward<KeepFunctor>(keep), std::forward<ReduceFunctor>(reduce), options);
0148 }
0149
0150 template <typename Sequence, typename KeepFunctor, typename ReduceFunctor,
0151 typename InitialValueType,
0152 std::enable_if_t<QtPrivate::isInvocable<KeepFunctor, Sequence>::value, int> = 0,
0153 typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type,
0154 std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>,
0155 int> = 0>
0156 QFuture<ResultType> filteredReduced(QThreadPool *pool,
0157 Sequence &&sequence,
0158 KeepFunctor &&keep,
0159 ReduceFunctor &&reduce,
0160 InitialValueType &&initialValue,
0161 ReduceOptions options = ReduceOptions(UnorderedReduce
0162 | SequentialReduce))
0163 {
0164 return startFilteredReduced<ResultType>(
0165 pool, std::forward<Sequence>(sequence), std::forward<KeepFunctor>(keep),
0166 std::forward<ReduceFunctor>(reduce),
0167 ResultType(std::forward<InitialValueType>(initialValue)), options);
0168 }
0169
0170 template <typename Sequence, typename KeepFunctor, typename ReduceFunctor,
0171 typename InitialValueType,
0172 std::enable_if_t<QtPrivate::isInvocable<KeepFunctor, Sequence>::value, int> = 0,
0173 typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type,
0174 std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>,
0175 int> = 0>
0176 QFuture<ResultType> filteredReduced(Sequence &&sequence,
0177 KeepFunctor &&keep,
0178 ReduceFunctor &&reduce,
0179 InitialValueType &&initialValue,
0180 ReduceOptions options = ReduceOptions(UnorderedReduce
0181 | SequentialReduce))
0182 {
0183 return startFilteredReduced<ResultType>(
0184 QThreadPool::globalInstance(), std::forward<Sequence>(sequence),
0185 std::forward<KeepFunctor>(keep), std::forward<ReduceFunctor>(reduce),
0186 ResultType(std::forward<InitialValueType>(initialValue)), options);
0187 }
0188 #endif
0189
0190
0191 template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor>
0192 QFuture<ResultType> filteredReduced(QThreadPool *pool,
0193 Iterator begin,
0194 Iterator end,
0195 KeepFunctor &&keep,
0196 ReduceFunctor &&reduce,
0197 ReduceOptions options = ReduceOptions(UnorderedReduce
0198 | SequentialReduce))
0199 {
0200 return startFilteredReduced<ResultType>(pool, begin, end, std::forward<KeepFunctor>(keep),
0201 std::forward<ReduceFunctor>(reduce), options);
0202 }
0203
0204 template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor>
0205 QFuture<ResultType> filteredReduced(Iterator begin,
0206 Iterator end,
0207 KeepFunctor &&keep,
0208 ReduceFunctor &&reduce,
0209 ReduceOptions options = ReduceOptions(UnorderedReduce
0210 | SequentialReduce))
0211 {
0212 return startFilteredReduced<ResultType>(QThreadPool::globalInstance(), begin, end,
0213 std::forward<KeepFunctor>(keep),
0214 std::forward<ReduceFunctor>(reduce), options);
0215 }
0216
0217 #ifdef Q_QDOC
0218 template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor,
0219 typename InitialValueType>
0220 #else
0221 template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor,
0222 typename InitialValueType,
0223 std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>,
0224 int> = 0>
0225 #endif
0226 QFuture<ResultType> filteredReduced(QThreadPool *pool,
0227 Iterator begin,
0228 Iterator end,
0229 KeepFunctor &&keep,
0230 ReduceFunctor &&reduce,
0231 InitialValueType &&initialValue,
0232 ReduceOptions options = ReduceOptions(UnorderedReduce
0233 | SequentialReduce))
0234 {
0235 return startFilteredReduced<ResultType>(
0236 pool, begin, end, std::forward<KeepFunctor>(keep), std::forward<ReduceFunctor>(reduce),
0237 ResultType(std::forward<InitialValueType>(initialValue)), options);
0238 }
0239
0240 #ifdef Q_QDOC
0241 template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor,
0242 typename InitialValueType>
0243 #else
0244 template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor,
0245 typename InitialValueType,
0246 std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>,
0247 int> = 0>
0248 #endif
0249 QFuture<ResultType> filteredReduced(Iterator begin,
0250 Iterator end,
0251 KeepFunctor &&keep,
0252 ReduceFunctor &&reduce,
0253 InitialValueType &&initialValue,
0254 ReduceOptions options = ReduceOptions(UnorderedReduce
0255 | SequentialReduce))
0256 {
0257 return startFilteredReduced<ResultType>(
0258 QThreadPool::globalInstance(), begin, end, std::forward<KeepFunctor>(keep),
0259 std::forward<ReduceFunctor>(reduce),
0260 ResultType(std::forward<InitialValueType>(initialValue)), options);
0261 }
0262
0263 #ifndef Q_QDOC
0264 template <typename Iterator, typename KeepFunctor, typename ReduceFunctor,
0265 typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type>
0266 QFuture<ResultType> filteredReduced(QThreadPool *pool,
0267 Iterator begin,
0268 Iterator end,
0269 KeepFunctor &&keep,
0270 ReduceFunctor &&reduce,
0271 ReduceOptions options = ReduceOptions(UnorderedReduce
0272 | SequentialReduce))
0273 {
0274 return startFilteredReduced<ResultType>(pool, begin, end, std::forward<KeepFunctor>(keep),
0275 std::forward<ReduceFunctor>(reduce), options);
0276 }
0277
0278 template <typename Iterator, typename KeepFunctor, typename ReduceFunctor,
0279 typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type>
0280 QFuture<ResultType> filteredReduced(Iterator begin,
0281 Iterator end,
0282 KeepFunctor &&keep,
0283 ReduceFunctor &&reduce,
0284 ReduceOptions options = ReduceOptions(UnorderedReduce
0285 | SequentialReduce))
0286 {
0287 return startFilteredReduced<ResultType>(QThreadPool::globalInstance(), begin, end,
0288 std::forward<KeepFunctor>(keep),
0289 std::forward<ReduceFunctor>(reduce), options);
0290 }
0291
0292 template <typename Iterator, typename KeepFunctor, typename ReduceFunctor,
0293 typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type,
0294 typename InitialValueType,
0295 std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>,
0296 int> = 0>
0297 QFuture<ResultType> filteredReduced(QThreadPool *pool,
0298 Iterator begin,
0299 Iterator end,
0300 KeepFunctor &&keep,
0301 ReduceFunctor &&reduce,
0302 InitialValueType &&initialValue,
0303 ReduceOptions options = ReduceOptions(UnorderedReduce
0304 | SequentialReduce))
0305 {
0306 return startFilteredReduced<ResultType>(
0307 pool, begin, end, std::forward<KeepFunctor>(keep), std::forward<ReduceFunctor>(reduce),
0308 ResultType(std::forward<InitialValueType>(initialValue)), options);
0309 }
0310
0311 template <typename Iterator, typename KeepFunctor, typename ReduceFunctor,
0312 std::enable_if_t<QtPrivate::isIterator_v<Iterator>, int> = 0,
0313 typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type,
0314 typename InitialValueType,
0315 std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>,
0316 int> = 0>
0317 QFuture<ResultType> filteredReduced(Iterator begin,
0318 Iterator end,
0319 KeepFunctor &&keep,
0320 ReduceFunctor &&reduce,
0321 InitialValueType &&initialValue,
0322 ReduceOptions options = ReduceOptions(UnorderedReduce
0323 | SequentialReduce))
0324 {
0325 return startFilteredReduced<ResultType>(
0326 QThreadPool::globalInstance(), begin, end, std::forward<KeepFunctor>(keep),
0327 std::forward<ReduceFunctor>(reduce),
0328 ResultType(std::forward<InitialValueType>(initialValue)), options);
0329 }
0330 #endif
0331
0332
0333 template <typename Sequence, typename KeepFunctor>
0334 QFuture<typename std::decay_t<Sequence>::value_type> filtered(QThreadPool *pool,Sequence &&sequence,
0335 KeepFunctor &&keep)
0336 {
0337 return startFiltered(pool, std::forward<Sequence>(sequence), std::forward<KeepFunctor>(keep));
0338 }
0339
0340 template <typename Sequence, typename KeepFunctor>
0341 QFuture<typename std::decay_t<Sequence>::value_type> filtered(Sequence &&sequence,
0342 KeepFunctor &&keep)
0343 {
0344 return startFiltered(QThreadPool::globalInstance(), std::forward<Sequence>(sequence),
0345 std::forward<KeepFunctor>(keep));
0346 }
0347
0348
0349 template <typename Iterator, typename KeepFunctor>
0350 QFuture<typename qValueType<Iterator>::value_type> filtered(QThreadPool *pool,
0351 Iterator begin,
0352 Iterator end,
0353 KeepFunctor &&keep)
0354 {
0355 return startFiltered(pool, begin, end, std::forward<KeepFunctor>(keep));
0356 }
0357
0358 template <typename Iterator, typename KeepFunctor>
0359 QFuture<typename qValueType<Iterator>::value_type> filtered(Iterator begin,
0360 Iterator end,
0361 KeepFunctor &&keep)
0362 {
0363 return startFiltered(QThreadPool::globalInstance(), begin, end,
0364 std::forward<KeepFunctor>(keep));
0365 }
0366
0367
0368 template <typename Sequence, typename KeepFunctor>
0369 void blockingFilter(QThreadPool *pool, Sequence &sequence, KeepFunctor &&keep)
0370 {
0371 QFuture<void> future = filter(pool, sequence, std::forward<KeepFunctor>(keep));
0372 future.waitForFinished();
0373 }
0374
0375 template <typename Sequence, typename KeepFunctor>
0376 void blockingFilter(Sequence &sequence, KeepFunctor &&keep)
0377 {
0378 QFuture<void> future = filter(sequence, std::forward<KeepFunctor>(keep));
0379 future.waitForFinished();
0380 }
0381
0382
0383 template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor>
0384 ResultType blockingFilteredReduced(QThreadPool *pool,
0385 Sequence &&sequence,
0386 KeepFunctor &&keep,
0387 ReduceFunctor &&reduce,
0388 ReduceOptions options = ReduceOptions(UnorderedReduce
0389 | SequentialReduce))
0390 {
0391 QFuture<ResultType> future = filteredReduced<ResultType>(
0392 pool, std::forward<Sequence>(sequence), std::forward<KeepFunctor>(keep),
0393 std::forward<ReduceFunctor>(reduce), options);
0394 return future.takeResult();
0395 }
0396
0397 template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor>
0398 ResultType blockingFilteredReduced(Sequence &&sequence,
0399 KeepFunctor &&keep,
0400 ReduceFunctor &&reduce,
0401 ReduceOptions options = ReduceOptions(UnorderedReduce
0402 | SequentialReduce))
0403 {
0404 QFuture<ResultType> future = filteredReduced<ResultType>(
0405 std::forward<Sequence>(sequence), std::forward<KeepFunctor>(keep),
0406 std::forward<ReduceFunctor>(reduce), options);
0407 return future.takeResult();
0408 }
0409
0410 #ifdef Q_QDOC
0411 template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor,
0412 typename InitialValueType>
0413 #else
0414 template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor,
0415 typename InitialValueType,
0416 std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>,
0417 int> = 0>
0418 #endif
0419 ResultType blockingFilteredReduced(QThreadPool *pool,
0420 Sequence &&sequence,
0421 KeepFunctor &&keep,
0422 ReduceFunctor &&reduce,
0423 InitialValueType &&initialValue,
0424 ReduceOptions options = ReduceOptions(UnorderedReduce
0425 | SequentialReduce))
0426 {
0427 QFuture<ResultType> future = filteredReduced<ResultType>(
0428 pool, std::forward<Sequence>(sequence), std::forward<KeepFunctor>(keep),
0429 std::forward<ReduceFunctor>(reduce),
0430 ResultType(std::forward<InitialValueType>(initialValue)), options);
0431 return future.takeResult();
0432 }
0433
0434 #ifdef Q_QDOC
0435 template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor,
0436 typename InitialValueType>
0437 #else
0438 template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor,
0439 typename InitialValueType,
0440 std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>,
0441 int> = 0>
0442 #endif
0443 ResultType blockingFilteredReduced(Sequence &&sequence,
0444 KeepFunctor &&keep,
0445 ReduceFunctor &&reduce,
0446 InitialValueType &&initialValue,
0447 ReduceOptions options = ReduceOptions(UnorderedReduce
0448 | SequentialReduce))
0449 {
0450 QFuture<ResultType> future = filteredReduced<ResultType>(
0451 std::forward<Sequence>(sequence), std::forward<KeepFunctor>(keep),
0452 std::forward<ReduceFunctor>(reduce),
0453 ResultType(std::forward<InitialValueType>(initialValue)), options);
0454 return future.takeResult();
0455 }
0456
0457 #ifndef Q_QDOC
0458 template <typename Sequence, typename KeepFunctor, typename ReduceFunctor,
0459 std::enable_if_t<QtPrivate::isInvocable<KeepFunctor, Sequence>::value, int> = 0,
0460 typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type>
0461 ResultType blockingFilteredReduced(QThreadPool *pool,
0462 Sequence &&sequence,
0463 KeepFunctor &&keep,
0464 ReduceFunctor &&reduce,
0465 ReduceOptions options = ReduceOptions(UnorderedReduce
0466 | SequentialReduce))
0467 {
0468 QFuture<ResultType> future = filteredReduced<ResultType>(
0469 pool, std::forward<Sequence>(sequence), std::forward<KeepFunctor>(keep),
0470 std::forward<ReduceFunctor>(reduce), options);
0471 return future.takeResult();
0472 }
0473
0474 template <typename Sequence, typename KeepFunctor, typename ReduceFunctor,
0475 std::enable_if_t<QtPrivate::isInvocable<KeepFunctor, Sequence>::value, int> = 0,
0476 typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type>
0477 ResultType blockingFilteredReduced(Sequence &&sequence,
0478 KeepFunctor &&keep,
0479 ReduceFunctor &&reduce,
0480 ReduceOptions options = ReduceOptions(UnorderedReduce
0481 | SequentialReduce))
0482 {
0483 QFuture<ResultType> future = filteredReduced<ResultType>(
0484 std::forward<Sequence>(sequence), std::forward<KeepFunctor>(keep),
0485 std::forward<ReduceFunctor>(reduce), options);
0486 return future.takeResult();
0487 }
0488
0489 template <typename Sequence, typename KeepFunctor, typename ReduceFunctor,
0490 typename InitialValueType,
0491 std::enable_if_t<QtPrivate::isInvocable<KeepFunctor, Sequence>::value, int> = 0,
0492 typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type,
0493 std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>,
0494 int> = 0>
0495 ResultType blockingFilteredReduced(QThreadPool *pool,
0496 Sequence &&sequence,
0497 KeepFunctor &&keep,
0498 ReduceFunctor &&reduce,
0499 InitialValueType &&initialValue,
0500 ReduceOptions options = ReduceOptions(UnorderedReduce
0501 | SequentialReduce))
0502 {
0503 QFuture<ResultType> future = filteredReduced<ResultType>(
0504 pool, std::forward<Sequence>(sequence), std::forward<KeepFunctor>(keep),
0505 std::forward<ReduceFunctor>(reduce),
0506 ResultType(std::forward<InitialValueType>(initialValue)), options);
0507 return future.takeResult();
0508 }
0509
0510 template <typename Sequence, typename KeepFunctor, typename ReduceFunctor,
0511 typename InitialValueType,
0512 std::enable_if_t<QtPrivate::isInvocable<KeepFunctor, Sequence>::value, int> = 0,
0513 typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type,
0514 std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>,
0515 int> = 0>
0516 ResultType blockingFilteredReduced(Sequence &&sequence,
0517 KeepFunctor &&keep,
0518 ReduceFunctor &&reduce,
0519 InitialValueType &&initialValue,
0520 ReduceOptions options = ReduceOptions(UnorderedReduce
0521 | SequentialReduce))
0522 {
0523 QFuture<ResultType> future = filteredReduced<ResultType>(
0524 std::forward<Sequence>(sequence), std::forward<KeepFunctor>(keep),
0525 std::forward<ReduceFunctor>(reduce),
0526 ResultType(std::forward<InitialValueType>(initialValue)), options);
0527 return future.takeResult();
0528 }
0529 #endif
0530
0531
0532 template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor>
0533 ResultType blockingFilteredReduced(QThreadPool *pool,
0534 Iterator begin,
0535 Iterator end,
0536 KeepFunctor &&keep,
0537 ReduceFunctor &&reduce,
0538 ReduceOptions options = ReduceOptions(UnorderedReduce
0539 | SequentialReduce))
0540 {
0541 QFuture<ResultType> future =
0542 filteredReduced<ResultType>(pool, begin, end, std::forward<KeepFunctor>(keep),
0543 std::forward<ReduceFunctor>(reduce), options);
0544 return future.takeResult();
0545 }
0546
0547 template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor>
0548 ResultType blockingFilteredReduced(Iterator begin,
0549 Iterator end,
0550 KeepFunctor &&keep,
0551 ReduceFunctor &&reduce,
0552 ReduceOptions options = ReduceOptions(UnorderedReduce
0553 | SequentialReduce))
0554 {
0555 QFuture<ResultType> future =
0556 filteredReduced<ResultType>(begin, end, std::forward<KeepFunctor>(keep),
0557 std::forward<ReduceFunctor>(reduce), options);
0558 return future.takeResult();
0559 }
0560
0561 #ifdef Q_QDOC
0562 template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor,
0563 typename InitialValueType>
0564 #else
0565 template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor,
0566 typename InitialValueType,
0567 std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>,
0568 int> = 0>
0569 #endif
0570 ResultType blockingFilteredReduced(QThreadPool *pool,
0571 Iterator begin,
0572 Iterator end,
0573 KeepFunctor &&keep,
0574 ReduceFunctor &&reduce,
0575 InitialValueType &&initialValue,
0576 ReduceOptions options = ReduceOptions(UnorderedReduce
0577 | SequentialReduce))
0578 {
0579 QFuture<ResultType> future = filteredReduced<ResultType>(
0580 pool, begin, end, std::forward<KeepFunctor>(keep), std::forward<ReduceFunctor>(reduce),
0581 ResultType(std::forward<InitialValueType>(initialValue)), options);
0582 return future.takeResult();
0583 }
0584
0585 #ifdef Q_QDOC
0586 template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor,
0587 typename InitialValueType>
0588 #else
0589 template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor,
0590 typename InitialValueType,
0591 std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>,
0592 int> = 0>
0593 #endif
0594 ResultType blockingFilteredReduced(Iterator begin,
0595 Iterator end,
0596 KeepFunctor &&keep,
0597 ReduceFunctor &&reduce,
0598 InitialValueType &&initialValue,
0599 ReduceOptions options = ReduceOptions(UnorderedReduce
0600 | SequentialReduce))
0601 {
0602 QFuture<ResultType> future = filteredReduced<ResultType>(
0603 begin, end, std::forward<KeepFunctor>(keep), std::forward<ReduceFunctor>(reduce),
0604 ResultType(std::forward<InitialValueType>(initialValue)), options);
0605 return future.takeResult();
0606 }
0607
0608 #ifndef Q_QDOC
0609 template <typename Iterator, typename KeepFunctor, typename ReduceFunctor,
0610 typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type>
0611 ResultType blockingFilteredReduced(QThreadPool *pool,
0612 Iterator begin,
0613 Iterator end,
0614 KeepFunctor &&keep,
0615 ReduceFunctor &&reduce,
0616 ReduceOptions options = ReduceOptions(UnorderedReduce
0617 | SequentialReduce))
0618 {
0619 QFuture<ResultType> future =
0620 filteredReduced<ResultType>(pool, begin, end, std::forward<KeepFunctor>(keep),
0621 std::forward<ReduceFunctor>(reduce), options);
0622 return future.takeResult();
0623 }
0624
0625 template <typename Iterator, typename KeepFunctor, typename ReduceFunctor,
0626 typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type>
0627 ResultType blockingFilteredReduced(Iterator begin,
0628 Iterator end,
0629 KeepFunctor &&keep,
0630 ReduceFunctor &&reduce,
0631 ReduceOptions options = ReduceOptions(UnorderedReduce
0632 | SequentialReduce))
0633 {
0634 QFuture<ResultType> future =
0635 filteredReduced<ResultType>(begin, end, std::forward<KeepFunctor>(keep),
0636 std::forward<ReduceFunctor>(reduce), options);
0637 return future.takeResult();
0638 }
0639
0640 template <typename Iterator, typename KeepFunctor, typename ReduceFunctor,
0641 typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type,
0642 typename InitialValueType,
0643 std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>,
0644 int> = 0>
0645 ResultType blockingFilteredReduced(QThreadPool *pool,
0646 Iterator begin,
0647 Iterator end, KeepFunctor &&keep,
0648 ReduceFunctor &&reduce,
0649 InitialValueType &&initialValue,
0650 ReduceOptions options = ReduceOptions(UnorderedReduce
0651 | SequentialReduce))
0652 {
0653 QFuture<ResultType> future = filteredReduced<ResultType>(
0654 pool, begin, end, std::forward<KeepFunctor>(keep), std::forward<ReduceFunctor>(reduce),
0655 ResultType(std::forward<InitialValueType>(initialValue)), options);
0656 return future.takeResult();
0657 }
0658
0659 template <typename Iterator, typename KeepFunctor, typename ReduceFunctor,
0660 std::enable_if_t<QtPrivate::isIterator_v<Iterator>, int> = 0,
0661 typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type,
0662 typename InitialValueType,
0663 std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>,
0664 int> = 0>
0665 ResultType blockingFilteredReduced(Iterator begin,
0666 Iterator end,
0667 KeepFunctor &&keep,
0668 ReduceFunctor &&reduce,
0669 InitialValueType &&initialValue,
0670 ReduceOptions options = ReduceOptions(UnorderedReduce
0671 | SequentialReduce))
0672 {
0673 QFuture<ResultType> future = filteredReduced<ResultType>(
0674 begin, end, std::forward<KeepFunctor>(keep), std::forward<ReduceFunctor>(reduce),
0675 ResultType(std::forward<InitialValueType>(initialValue)), options);
0676 return future.takeResult();
0677 }
0678 #endif
0679
0680
0681 template <typename Sequence, typename KeepFunctor>
0682 std::decay_t<Sequence> blockingFiltered(QThreadPool *pool, Sequence &&sequence, KeepFunctor &&keep)
0683 {
0684 return blockingFilteredReduced<std::decay_t<Sequence>>(
0685 pool, std::forward<Sequence>(sequence), std::forward<KeepFunctor>(keep),
0686 QtPrivate::PushBackWrapper(), OrderedReduce);
0687 }
0688
0689 template <typename Sequence, typename KeepFunctor>
0690 std::decay_t<Sequence> blockingFiltered(Sequence &&sequence, KeepFunctor &&keep)
0691 {
0692 return blockingFilteredReduced<std::decay_t<Sequence>>(
0693 QThreadPool::globalInstance(), std::forward<Sequence>(sequence),
0694 std::forward<KeepFunctor>(keep), QtPrivate::PushBackWrapper(), OrderedReduce);
0695 }
0696
0697
0698 template <typename OutputSequence, typename Iterator, typename KeepFunctor>
0699 OutputSequence blockingFiltered(QThreadPool *pool, Iterator begin, Iterator end, KeepFunctor &&keep)
0700 {
0701 return blockingFilteredReduced<OutputSequence>(pool, begin, end,
0702 std::forward<KeepFunctor>(keep),
0703 QtPrivate::PushBackWrapper(), OrderedReduce);
0704 }
0705
0706 template <typename OutputSequence, typename Iterator, typename KeepFunctor>
0707 OutputSequence blockingFiltered(Iterator begin, Iterator end, KeepFunctor &&keep)
0708 {
0709 return blockingFilteredReduced<OutputSequence>(QThreadPool::globalInstance(), begin, end,
0710 std::forward<KeepFunctor>(keep),
0711 QtPrivate::PushBackWrapper(), OrderedReduce);
0712 }
0713
0714 }
0715
0716 QT_END_NAMESPACE
0717
0718 #endif
0719
0720 #endif