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