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