40 #ifndef QTCONCURRENT_MAP_H
41 #define QTCONCURRENT_MAP_H
43 #include <QtConcurrent/qtconcurrent_global.h>
45 #if !defined(QT_NO_CONCURRENT) || defined(Q_CLANG_QDOC)
47 #include <QtConcurrent/qtconcurrentmapkernel.h>
48 #include <QtConcurrent/qtconcurrentreducekernel.h>
49 #include <QtConcurrent/qtconcurrentfunctionwrappers.h>
58 template <
typename Sequence,
typename MapFunctor>
61 return startMap(
pool, sequence.begin(), sequence.end(), std::forward<MapFunctor>(
map));
64 template <
typename Sequence,
typename MapFunctor>
68 std::forward<MapFunctor>(
map));
72 template <
typename Iterator,
typename MapFunctor>
78 template <
typename Iterator,
typename MapFunctor>
85 template <
typename ResultType,
typename Sequence,
typename MapFunctor,
typename ReduceFunctor>
93 return startMappedReduced<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
94 (
pool, std::forward<Sequence>(sequence), std::forward<MapFunctor>(
map),
95 std::forward<ReduceFunctor>(
reduce), options);
98 template <
typename ResultType,
typename Sequence,
typename MapFunctor,
typename ReduceFunctor>
105 return startMappedReduced<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
107 std::forward<MapFunctor>(
map), std::forward<ReduceFunctor>(
reduce), options);
111 template <
typename ResultType,
typename Sequence,
typename MapFunctor,
typename ReduceFunctor,
112 typename InitialValueType>
114 template <
typename ResultType,
typename Sequence,
typename MapFunctor,
typename ReduceFunctor,
115 typename InitialValueType,
116 std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>,
123 InitialValueType &&initialValue,
127 return startMappedReduced<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>(
128 pool, std::forward<Sequence>(sequence), std::forward<MapFunctor>(
map),
129 std::forward<ReduceFunctor>(
reduce),
130 ResultType(std::forward<InitialValueType>(initialValue)), options);
133 template <
typename ResultType,
typename Sequence,
typename MapFunctor,
typename ReduceFunctor,
134 typename InitialValueType>
136 template <
typename ResultType,
typename Sequence,
typename MapFunctor,
typename ReduceFunctor,
137 typename InitialValueType,
138 std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>,
144 InitialValueType &&initialValue,
148 return startMappedReduced<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
150 std::forward<MapFunctor>(
map), std::forward<ReduceFunctor>(
reduce),
151 ResultType(std::forward<InitialValueType>(initialValue)), options);
154 template <
typename Sequence,
typename MapFunctor,
typename ReduceFunctor,
164 return startMappedReduced<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
165 (
pool, std::forward<Sequence>(sequence), std::forward<MapFunctor>(
map),
166 std::forward<ReduceFunctor>(
reduce), options);
169 template <
typename Sequence,
typename MapFunctor,
typename ReduceFunctor,
178 return startMappedReduced<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
180 std::forward<MapFunctor>(
map), std::forward<ReduceFunctor>(
reduce), options);
184 template <
typename Sequence,
typename MapFunctor,
typename ReduceFunctor,
typename ResultType,
185 typename InitialValueType>
187 template <
typename Sequence,
typename MapFunctor,
typename ReduceFunctor,
typename InitialValueType,
190 std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>,
197 InitialValueType &&initialValue,
201 return startMappedReduced<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>(
202 pool, std::forward<Sequence>(sequence), std::forward<MapFunctor>(
map),
203 std::forward<ReduceFunctor>(
reduce),
204 ResultType(std::forward<InitialValueType>(initialValue)), options);
208 template <
typename Sequence,
typename MapFunctor,
typename ReduceFunctor,
typename ResultType,
209 typename InitialValueType>
211 template <
typename Sequence,
typename MapFunctor,
typename ReduceFunctor,
typename InitialValueType,
214 std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>,
220 InitialValueType &&initialValue,
224 return startMappedReduced<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
226 std::forward<MapFunctor>(
map), std::forward<ReduceFunctor>(
reduce),
227 ResultType(std::forward<InitialValueType>(initialValue)), options);
231 template <
typename ResultType,
typename Iterator,
typename MapFunctor,
typename ReduceFunctor>
240 return startMappedReduced<QtPrivate::MapResultType<Iterator, MapFunctor>, ResultType>
245 template <
typename ResultType,
typename Iterator,
typename MapFunctor,
typename ReduceFunctor>
253 return startMappedReduced<QtPrivate::MapResultType<Iterator, MapFunctor>, ResultType>
255 std::forward<ReduceFunctor>(
reduce), options);
259 template <
typename ResultType,
typename Iterator,
typename MapFunctor,
typename ReduceFunctor,
260 typename InitialValueType>
262 template <
typename ResultType,
typename Iterator,
typename MapFunctor,
typename ReduceFunctor,
263 typename InitialValueType,
264 std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>,
272 InitialValueType &&initialValue,
276 return startMappedReduced<QtPrivate::MapResultType<Iterator, MapFunctor>, ResultType>
278 ResultType(std::forward<InitialValueType>(initialValue)), options);
282 template <
typename ResultType,
typename Iterator,
typename MapFunctor,
typename ReduceFunctor,
283 typename InitialValueType>
285 template <
typename ResultType,
typename Iterator,
typename MapFunctor,
typename ReduceFunctor,
286 typename InitialValueType,
287 std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>,
294 InitialValueType &&initialValue,
298 return startMappedReduced<QtPrivate::MapResultType<Iterator, MapFunctor>, ResultType>
300 std::forward<ReduceFunctor>(
reduce),
301 ResultType(std::forward<InitialValueType>(initialValue)), options);
304 template <
typename Iterator,
typename MapFunctor,
typename ReduceFunctor,
314 return startMappedReduced<QtPrivate::MapResultType<Iterator, MapFunctor>, ResultType>(
319 template <
typename Iterator,
typename MapFunctor,
typename ReduceFunctor,
328 return startMappedReduced<QtPrivate::MapResultType<Iterator, MapFunctor>, ResultType>
330 std::forward<ReduceFunctor>(
reduce), options);
334 template <
typename Iterator,
typename MapFunctor,
typename ReduceFunctor,
typename ResultType,
335 typename InitialValueType>
337 template <
typename Iterator,
typename MapFunctor,
typename ReduceFunctor,
339 typename InitialValueType,
340 std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>,
348 InitialValueType &&initialValue,
352 return startMappedReduced<QtPrivate::MapResultType<Iterator, MapFunctor>, ResultType>
354 ResultType(std::forward<InitialValueType>(initialValue)), options);
358 template <
typename Iterator,
typename MapFunctor,
typename ReduceFunctor,
typename ResultType,
359 typename InitialValueType>
361 template<
typename Iterator,
typename MapFunctor,
typename ReduceFunctor,
362 std::enable_if_t<QtPrivate::isIterator_v<Iterator>,
int> = 0,
364 typename InitialValueType,
365 std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>,
372 InitialValueType &&initialValue,
376 return startMappedReduced<QtPrivate::MapResultType<Iterator, MapFunctor>, ResultType>
378 std::forward<ReduceFunctor>(
reduce),
379 ResultType(std::forward<InitialValueType>(initialValue)), options);
383 template <
typename Sequence,
typename MapFunctor>
389 return startMapped<QtPrivate::MapResultType<Sequence, MapFunctor>>(
390 pool, std::forward<Sequence>(sequence), std::forward<MapFunctor>(
map));
393 template <
typename Sequence,
typename MapFunctor>
398 return startMapped<QtPrivate::MapResultType<Sequence, MapFunctor>>
400 std::forward<MapFunctor>(
map));
404 template <
typename Iterator,
typename MapFunctor>
411 return startMapped<QtPrivate::MapResultType<Iterator, MapFunctor>>(
415 template <
typename Iterator,
typename MapFunctor>
421 return startMapped<QtPrivate::MapResultType<Iterator, MapFunctor>>
426 template <
typename Sequence,
typename MapFunctor>
430 startMap(
pool, sequence.begin(), sequence.end(), std::forward<MapFunctor>(
map));
434 template <
typename Sequence,
typename MapFunctor>
438 std::forward<MapFunctor>(
map));
443 template <
typename Iterator,
typename MapFunctor>
450 template <
typename Iterator,
typename MapFunctor>
454 std::forward<MapFunctor>(
map));
459 template <
typename ResultType,
typename Sequence,
typename MapFunctor,
typename ReduceFunctor>
468 mappedReduced<ResultType>(
pool, std::forward<Sequence>(sequence),
469 std::forward<MapFunctor>(
map),
470 std::forward<ReduceFunctor>(
reduce), options);
474 template <
typename ResultType,
typename Sequence,
typename MapFunctor,
typename ReduceFunctor>
482 mappedReduced<ResultType>(std::forward<Sequence>(sequence),
483 std::forward<MapFunctor>(
map),
484 std::forward<ReduceFunctor>(
reduce), options);
489 template <
typename ResultType,
typename Sequence,
typename MapFunctor,
typename ReduceFunctor,
490 typename InitialValueType>
492 template <
typename ResultType,
typename Sequence,
typename MapFunctor,
typename ReduceFunctor,
493 typename InitialValueType,
494 std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>,
501 InitialValueType &&initialValue,
506 pool, std::forward<Sequence>(sequence), std::forward<MapFunctor>(
map),
507 std::forward<ReduceFunctor>(
reduce),
508 ResultType(std::forward<InitialValueType>(initialValue)), options);
513 template <
typename ResultType,
typename Sequence,
typename MapFunctor,
typename ReduceFunctor,
514 typename InitialValueType>
516 template <
typename ResultType,
typename Sequence,
typename MapFunctor,
typename ReduceFunctor,
517 typename InitialValueType,
518 std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>,
524 InitialValueType &&initialValue,
529 std::forward<Sequence>(sequence), std::forward<MapFunctor>(
map),
530 std::forward<ReduceFunctor>(
reduce),
531 ResultType(std::forward<InitialValueType>(initialValue)), options);
535 template <
typename MapFunctor,
typename ReduceFunctor,
typename Sequence,
546 mappedReduced<ResultType>(
pool, std::forward<Sequence>(sequence),
547 std::forward<MapFunctor>(
map),
548 std::forward<ReduceFunctor>(
reduce), options);
552 template <
typename MapFunctor,
typename ReduceFunctor,
typename Sequence,
562 mappedReduced<ResultType>(std::forward<Sequence>(sequence),
563 std::forward<MapFunctor>(
map),
564 std::forward<ReduceFunctor>(
reduce), options);
569 template <
typename MapFunctor,
typename ReduceFunctor,
typename Sequence,
typename ResultType,
570 typename InitialValueType>
572 template <
typename MapFunctor,
typename ReduceFunctor,
typename Sequence,
typename InitialValueType,
575 std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>,
582 InitialValueType &&initialValue,
587 pool, std::forward<Sequence>(sequence), std::forward<MapFunctor>(
map),
588 std::forward<ReduceFunctor>(
reduce),
589 ResultType(std::forward<InitialValueType>(initialValue)), options);
594 template <
typename MapFunctor,
typename ReduceFunctor,
typename Sequence,
typename ResultType,
595 typename InitialValueType>
597 template<
typename MapFunctor,
typename ReduceFunctor,
typename Sequence,
typename InitialValueType,
600 std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>,
606 InitialValueType &&initialValue,
611 std::forward<Sequence>(sequence), std::forward<MapFunctor>(
map),
612 std::forward<ReduceFunctor>(
reduce),
613 ResultType(std::forward<InitialValueType>(initialValue)), options);
618 template <
typename ResultType,
typename Iterator,
typename MapFunctor,
typename ReduceFunctor>
628 mappedReduced<ResultType>(
pool,
begin,
end, std::forward<MapFunctor>(
map),
629 std::forward<ReduceFunctor>(
reduce), options);
633 template <
typename ResultType,
typename Iterator,
typename MapFunctor,
typename ReduceFunctor>
642 mappedReduced<ResultType>(
begin,
end, std::forward<MapFunctor>(
map),
643 std::forward<ReduceFunctor>(
reduce), options);
648 template <
typename ResultType,
typename Iterator,
typename MapFunctor,
typename ReduceFunctor,
649 typename InitialValueType>
651 template <
typename ResultType,
typename Iterator,
typename MapFunctor,
typename ReduceFunctor,
652 typename InitialValueType,
653 std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>,
661 InitialValueType &&initialValue,
667 ResultType(std::forward<InitialValueType>(initialValue)),
673 template <
typename ResultType,
typename Iterator,
typename MapFunctor,
typename ReduceFunctor,
674 typename InitialValueType>
676 template <
typename ResultType,
typename Iterator,
typename MapFunctor,
typename ReduceFunctor,
677 typename InitialValueType,
678 std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>,
685 InitialValueType &&initialValue,
691 ResultType(std::forward<InitialValueType>(initialValue)),
696 template <
typename Iterator,
typename MapFunctor,
typename ReduceFunctor,
707 mappedReduced<ResultType>(
pool,
begin,
end, std::forward<MapFunctor>(
map),
708 std::forward<ReduceFunctor>(
reduce), options);
712 template <
typename Iterator,
typename MapFunctor,
typename ReduceFunctor,
722 mappedReduced<ResultType>(
begin,
end, std::forward<MapFunctor>(
map),
723 std::forward<ReduceFunctor>(
reduce), options);
728 template <
typename Iterator,
typename MapFunctor,
typename ReduceFunctor,
typename ResultType,
729 typename InitialValueType>
731 template <
typename Iterator,
typename MapFunctor,
typename ReduceFunctor,
733 typename InitialValueType,
734 std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>,
742 InitialValueType &&initialValue,
748 ResultType(std::forward<InitialValueType>(initialValue)), options);
753 template <
typename Iterator,
typename MapFunctor,
typename ReduceFunctor,
typename ResultType,
754 typename InitialValueType>
756 template <
typename Iterator,
typename MapFunctor,
typename ReduceFunctor,
757 std::enable_if_t<QtPrivate::isIterator_v<Iterator>,
int> = 0,
759 typename InitialValueType,
760 std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>,
767 InitialValueType &&initialValue,
773 ResultType(std::forward<InitialValueType>(initialValue)), options);
778 template <
typename OutputSequence,
typename InputSequence,
typename MapFunctor>
781 return blockingMappedReduced<OutputSequence>(
pool, std::forward<InputSequence>(sequence),
782 std::forward<MapFunctor>(
map),
786 template <
typename OutputSequence,
typename InputSequence,
typename MapFunctor>
789 return blockingMappedReduced<OutputSequence>(
794 template <
typename MapFunctor,
typename InputSequence>
798 MapFunctor>::ResultType;
799 return blockingMappedReduced<OutputSequence>(
pool, std::forward<InputSequence>(sequence),
800 std::forward<MapFunctor>(
map),
804 template <
typename MapFunctor,
typename InputSequence>
808 MapFunctor>::ResultType;
810 std::forward<InputSequence>(sequence),
811 std::forward<MapFunctor>(
map),
816 template <
typename Sequence,
typename Iterator,
typename MapFunctor>
819 return blockingMappedReduced<Sequence>(
pool,
begin,
end, std::forward<MapFunctor>(
map),
823 template <
typename Sequence,
typename Iterator,
typename MapFunctor>
827 std::forward<MapFunctor>(
map),
831 template <
typename Iterator,
typename MapFunctor>
835 return blockingMappedReduced<OutputSequence>(
pool,
begin,
end, std::forward<MapFunctor>(
map),
839 template <
typename Iterator,
typename MapFunctor>
844 std::forward<MapFunctor>(
map),
The QThreadPool class manages a collection of QThreads.
static QThreadPool * globalInstance()
void reduce(WordCount &result, const WordCount &w)
The QtConcurrent namespace provides high-level APIs that make it possible to write multi-threaded pro...
void blockingMap(QThreadPool *pool, Sequence &&sequence, MapFunctor map)
ThreadEngineStarter< void > startMap(QThreadPool *pool, Iterator begin, Iterator end, Functor &&functor)
[qtconcurrentmapkernel-1]
QFuture< void > map(QThreadPool *pool, Sequence &&sequence, MapFunctor &&map)
QFuture< QtPrivate::MapResultType< Sequence, MapFunctor > > mapped(QThreadPool *pool, Sequence &&sequence, MapFunctor &&map)
QFuture< ResultType > mappedReduced(QThreadPool *pool, Sequence &&sequence, MapFunctor &&map, ReduceFunctor &&reduce, ReduceOptions options=ReduceOptions(UnorderedReduce|SequentialReduce))
ResultType blockingMappedReduced(QThreadPool *pool, Sequence &&sequence, MapFunctor &&map, ReduceFunctor &&reduce, ReduceOptions options=ReduceOptions(UnorderedReduce|SequentialReduce))
OutputSequence blockingMapped(QThreadPool *pool, InputSequence &&sequence, MapFunctor &&map)
typename MapResult< T, MapFunctor >::Type MapResultType
def OutputSequence(toptions)
def InputSequence(toptions)
QtPrivate::QRegularExpressionMatchIteratorRangeBasedForIterator begin(const QRegularExpressionMatchIterator &iterator)
QFuture< void > future
[5]