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