1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4/*!
5 \namespace QtConcurrent
6 \inmodule QtConcurrent
7 \since 4.4
8 \brief The QtConcurrent namespace provides high-level APIs that make it
9 possible to write multi-threaded programs without using low-level
10 threading primitives.
11
12 See the \l {Qt Concurrent} module documentation for an overview of available
13 functions, or see below for detailed information on each function.
14
15 \inheaderfile QtConcurrent
16 \ingroup thread
17*/
18
19/*!
20 \enum QtConcurrent::ReduceQueueLimits
21 \internal
22 */
23
24/*!
25 \class QtConcurrent::ReduceKernel
26 \inmodule QtConcurrent
27 \internal
28*/
29
30/*!
31 \class QtConcurrent::SequenceHolder2
32 \inmodule QtConcurrent
33 \internal
34*/
35
36/*!
37 \class QtConcurrent::MapKernel
38 \inmodule QtConcurrent
39 \internal
40*/
41
42/*!
43 \class QtConcurrent::MappedReducedKernel
44 \inmodule QtConcurrent
45 \internal
46*/
47
48/*!
49 \class QtConcurrent::MappedEachKernel
50 \inmodule QtConcurrent
51 \internal
52*/
53
54/*!
55 \class QtConcurrent::SequenceHolder1
56 \inmodule QtConcurrent
57 \internal
58*/
59
60/*!
61 \fn [qtconcurrentmapkernel-1] ThreadEngineStarter<void> QtConcurrent::startMap(Iterator begin, Iterator end, Functor &&functor)
62 \internal
63*/
64
65/*!
66 \fn [qtconcurrentmapkernel-2] ThreadEngineStarter<T> QtConcurrent::startMapped(Iterator begin, Iterator end, Functor &&functor)
67 \internal
68*/
69
70/*!
71 \fn [qtconcurrentmapkernel-3] ThreadEngineStarter<T> QtConcurrent::startMapped(Sequence &&sequence, Functor &&functor)
72 \internal
73*/
74
75/*!
76 \fn [qtconcurrentmapkernel-4] ThreadEngineStarter<ResultType> QtConcurrent::startMappedReduced(Sequence &&sequence, MapFunctor &&mapFunctor, ReduceFunctor &&reduceFunctor, ReduceOptions options)
77 \internal
78*/
79
80/*!
81 \fn [qtconcurrentmapkernel-5] ThreadEngineStarter<ResultType> QtConcurrent::startMappedReduced(Iterator begin, Iterator end, MapFunctor &&mapFunctor, ReduceFunctor &&reduceFunctor, ReduceOptions options)
82 \internal
83*/
84
85/*!
86 \fn [qtconcurrentmapkernel-6] ThreadEngineStarter<ResultType> QtConcurrent::startMappedReduced(Sequence &&sequence, MapFunctor &&mapFunctor, ReduceFunctor &&reduceFunctor, ResultType &&initialValue, ReduceOptions options)
87 \internal
88*/
89
90/*!
91 \fn [qtconcurrentmapkernel-7] ThreadEngineStarter<ResultType> QtConcurrent::startMappedReduced(Iterator begin, Iterator end, MapFunctor &&mapFunctor, ReduceFunctor &&reduceFunctor, ResultType &&initialValue, ReduceOptions options)
92 \internal
93*/
94
95/*!
96 \enum QtConcurrent::ReduceOption
97 This enum specifies the order of which results from the map or filter
98 function are passed to the reduce function.
99
100 \value UnorderedReduce Reduction is done in an arbitrary order.
101 \value OrderedReduce Reduction is done in the order of the
102 original sequence.
103 \value SequentialReduce Reduction is done sequentially: only one
104 thread will enter the reduce function at a time. (Parallel reduction
105 might be supported in a future version of Qt Concurrent.)
106*/
107
108/*!
109 \page qtconcurrentmap.html
110 \title Concurrent Map and Map-Reduce
111 \brief Transforming values from a sequence and combining them, all in parallel.
112 \ingroup thread
113
114 The QtConcurrent::map(), QtConcurrent::mapped() and
115 QtConcurrent::mappedReduced() functions run computations in parallel on
116 the items in a sequence such as a QList. QtConcurrent::map()
117 modifies a sequence in-place, QtConcurrent::mapped() returns a new
118 sequence containing the modified content, and QtConcurrent::mappedReduced()
119 returns a single result.
120
121 These functions are part of the \l {Qt Concurrent} framework.
122
123 Each of the above functions has a blocking variant that returns
124 the final result instead of a QFuture. You use them in the same
125 way as the asynchronous variants.
126
127 \snippet code/src_concurrent_qtconcurrentmap.cpp 7
128
129 Note that the result types above are not QFuture objects, but real result
130 types (in this case, QList<QImage> and QImage).
131
132 \section1 Concurrent Map
133
134 QtConcurrent::mapped() takes an input sequence and a map function. This map
135 function is then called for each item in the sequence, and a new sequence
136 containing the return values from the map function is returned.
137
138 The map function must be of the form:
139
140 \snippet code/src_concurrent_qtconcurrentmap.cpp 0
141
142 T and U can be any type (and they can even be the same type), but T must
143 match the type stored in the sequence. The function returns the modified
144 or \e mapped content.
145
146 This example shows how to apply a scale function to all the items
147 in a sequence:
148
149 \snippet code/src_concurrent_qtconcurrentmap.cpp 1
150
151 The results of the map are made available through QFuture. See the
152 QFuture and QFutureWatcher documentation for more information on how to
153 use QFuture in your applications.
154
155 If you want to modify a sequence in-place, use QtConcurrent::map(). The
156 map function must then be of the form:
157
158 \snippet code/src_concurrent_qtconcurrentmap.cpp 2
159
160 Note that the return value and return type of the map function are not
161 used.
162
163 Using QtConcurrent::map() is similar to using QtConcurrent::mapped():
164
165 \snippet code/src_concurrent_qtconcurrentmap.cpp 3
166
167 Since the sequence is modified in place, QtConcurrent::map() does not
168 return any results via QFuture. However, you can still use QFuture and
169 QFutureWatcher to monitor the status of the map.
170
171 \section1 Concurrent Map-Reduce
172
173 QtConcurrent::mappedReduced() is similar to QtConcurrent::mapped(), but
174 instead of returning a sequence with the new results, the results are
175 combined into a single value using a reduce function.
176
177 The reduce function must be of the form:
178
179 \snippet code/src_concurrent_qtconcurrentmap.cpp 4
180
181 T is the type of the final result, U is the return type of the map
182 function. Note that the return value and return type of the reduce
183 function are not used.
184
185 Call QtConcurrent::mappedReduced() like this:
186
187 \snippet code/src_concurrent_qtconcurrentmap.cpp 5
188
189 The reduce function will be called once for each result returned by the map
190 function, and should merge the \e{intermediate} into the \e{result}
191 variable. QtConcurrent::mappedReduced() guarantees that only one thread
192 will call reduce at a time, so using a mutex to lock the result variable
193 is not necessary. The QtConcurrent::ReduceOptions enum provides a way to
194 control the order in which the reduction is done. If
195 QtConcurrent::UnorderedReduce is used (the default), the order is
196 undefined, while QtConcurrent::OrderedReduce ensures that the reduction
197 is done in the order of the original sequence.
198
199 \section1 Additional API Features
200
201 \section2 Using Iterators instead of Sequence
202
203 Each of the above functions has a variant that takes an iterator range
204 instead of a sequence. You use them in the same way as the sequence
205 variants:
206
207 \snippet code/src_concurrent_qtconcurrentmap.cpp 6
208
209 \section2 Blocking Variants
210
211 Each of the above functions has a blocking variant that returns
212 the final result instead of a QFuture. You use them in the same
213 way as the asynchronous variants.
214
215 \snippet code/src_concurrent_qtconcurrentmap.cpp 7
216
217 Note that the result types above are not QFuture objects, but real result
218 types (in this case, QList<QImage> and QImage).
219
220 \section2 Using Member Functions
221
222 QtConcurrent::map(), QtConcurrent::mapped(), and
223 QtConcurrent::mappedReduced() accept pointers to member functions.
224 The member function class type must match the type stored in the sequence:
225
226 \snippet code/src_concurrent_qtconcurrentmap.cpp 8
227
228 Note the use of qOverload. It is needed to resolve the ambiguity for the
229 methods, that have multiple overloads.
230
231 Also note that when using QtConcurrent::mappedReduced(), you can mix the use of
232 normal and member functions freely:
233
234 \snippet code/src_concurrent_qtconcurrentmap.cpp 9
235
236 \section2 Using Function Objects
237
238 QtConcurrent::map(), QtConcurrent::mapped(), and
239 QtConcurrent::mappedReduced() accept function objects
240 for the map function. These function objects can be used to
241 add state to a function call:
242
243 \snippet code/src_concurrent_qtconcurrentmap.cpp 14
244
245 Function objects are also supported for the reduce function:
246
247 \snippet code/src_concurrent_qtconcurrentmap.cpp 11
248
249 \section2 Using Lambda Expressions
250
251 QtConcurrent::map(), QtConcurrent::mapped(), and
252 QtConcurrent::mappedReduced() accept lambda expressions for the map and
253 reduce function:
254
255 \snippet code/src_concurrent_qtconcurrentmap.cpp 15
256
257 When using QtConcurrent::mappedReduced() or
258 QtConcurrent::blockingMappedReduced(), you can mix the use of normal
259 functions, member functions and lambda expressions freely.
260
261 \snippet code/src_concurrent_qtconcurrentmap.cpp 16
262
263 You can also pass a lambda as a reduce object:
264
265 \snippet code/src_concurrent_qtconcurrentmap.cpp 17
266
267 \section2 Wrapping Functions that Take Multiple Arguments
268
269 If you want to use a map function that takes more than one argument you can
270 use a lambda function or \c std::bind() to transform it onto a function that
271 takes one argument.
272
273 As an example, we'll use QImage::scaledToWidth():
274
275 \snippet code/src_concurrent_qtconcurrentmap.cpp 10
276
277 scaledToWidth takes three arguments (including the "this" pointer) and
278 can't be used with QtConcurrent::mapped() directly, because
279 QtConcurrent::mapped() expects a function that takes one argument. To use
280 QImage::scaledToWidth() with QtConcurrent::mapped() we have to provide a
281 value for the \e{width} and the \e{transformation mode}:
282
283 \snippet code/src_concurrent_qtconcurrentmap.cpp 13
284*/
285
286/*!
287 \fn template <typename Sequence, typename MapFunctor> QFuture<void> QtConcurrent::map(QThreadPool *pool, Sequence &&sequence, MapFunctor &&function)
288
289 Calls \a function once for each item in \a sequence.
290 All calls to \a function are invoked from the threads taken from the QThreadPool \a pool.
291 The \a function takes a reference to the item, so that any modifications done to the item
292 will appear in \a sequence.
293
294 \sa {Concurrent Map and Map-Reduce}
295*/
296
297/*!
298 \fn template <typename Sequence, typename MapFunctor> QFuture<void> QtConcurrent::map(Sequence &&sequence, MapFunctor &&function)
299
300 Calls \a function once for each item in \a sequence. The \a function takes
301 a reference to the item, so that any modifications done to the item
302 will appear in \a sequence.
303
304 \sa {Concurrent Map and Map-Reduce}
305*/
306
307/*!
308 \fn template <typename Iterator, typename MapFunctor> QFuture<void> QtConcurrent::map(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor &&function)
309
310 Calls \a function once for each item from \a begin to \a end.
311 All calls to \a function are invoked from the threads taken from the QThreadPool \a pool.
312 The \a function takes a reference to the item, so that any modifications
313 done to the item will appear in the sequence which the iterators belong to.
314
315 \sa {Concurrent Map and Map-Reduce}
316*/
317
318/*!
319 \fn template <typename Iterator, typename MapFunctor> QFuture<void> QtConcurrent::map(Iterator begin, Iterator end, MapFunctor &&function)
320
321 Calls \a function once for each item from \a begin to \a end. The
322 \a function takes a reference to the item, so that any modifications
323 done to the item will appear in the sequence which the iterators belong to.
324
325 \sa {Concurrent Map and Map-Reduce}
326*/
327
328/*!
329 \fn template <typename Sequence, typename MapFunctor> QFuture<QtPrivate::MapResultType<Sequence, MapFunctor>> QtConcurrent::mapped(QThreadPool *pool, Sequence &&sequence, MapFunctor &&function)
330
331 Calls \a function once for each item in \a sequence and returns a future
332 with each mapped item as a result. All calls to \a function are invoked from the
333 threads taken from the QThreadPool \a pool. You can use QFuture::const_iterator or
334 QFutureIterator to iterate through the results.
335
336 \sa {Concurrent Map and Map-Reduce}
337*/
338
339/*!
340 \fn template <typename Sequence, typename MapFunctor> QFuture<QtPrivate::MapResultType<Sequence, MapFunctor>> QtConcurrent::mapped(Sequence &&sequence, MapFunctor &&function)
341
342 Calls \a function once for each item in \a sequence and returns a future
343 with each mapped item as a result. You can use QFuture::const_iterator or
344 QFutureIterator to iterate through the results.
345
346 \sa {Concurrent Map and Map-Reduce}
347*/
348
349/*!
350 \fn template <typename Iterator, typename MapFunctor> QFuture<QtPrivate::MapResultType<Iterator, MapFunctor>> QtConcurrent::mapped(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor &&function)
351
352 Calls \a function once for each item from \a begin to \a end and returns a
353 future with each mapped item as a result. All calls to \a function are invoked from the
354 threads taken from the QThreadPool \a pool. You can use
355 QFuture::const_iterator or QFutureIterator to iterate through the results.
356
357 \sa {Concurrent Map and Map-Reduce}
358*/
359
360/*!
361 \fn template <typename Iterator, typename MapFunctor> QFuture<QtPrivate::MapResultType<Iterator, MapFunctor>> QtConcurrent::mapped(Iterator begin, Iterator end, MapFunctor &&function)
362
363 Calls \a function once for each item from \a begin to \a end and returns a
364 future with each mapped item as a result. You can use
365 QFuture::const_iterator or QFutureIterator to iterate through the results.
366
367 \sa {Concurrent Map and Map-Reduce}
368*/
369
370/*!
371 \fn template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor> QFuture<ResultType> QtConcurrent::mappedReduced(QThreadPool *pool, Sequence &&sequence, MapFunctor &&mapFunction, ReduceFunctor &&reduceFunction, QtConcurrent::ReduceOptions reduceOptions)
372
373 Calls \a mapFunction once for each item in \a sequence.
374 All calls to \a mapFunction are invoked from the threads taken from the QThreadPool \a pool.
375 The return value of each \a mapFunction is passed to \a reduceFunction.
376
377 Note that while \a mapFunction is called concurrently, only one thread at a
378 time will call \a reduceFunction. The order in which \a reduceFunction is
379 called is determined by \a reduceOptions.
380
381 \sa {Concurrent Map and Map-Reduce}
382*/
383
384/*!
385 \fn template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor> QFuture<ResultType> QtConcurrent::mappedReduced(Sequence &&sequence, MapFunctor &&mapFunction, ReduceFunctor &&reduceFunction, QtConcurrent::ReduceOptions reduceOptions)
386
387 Calls \a mapFunction once for each item in \a sequence. The return value of
388 each \a mapFunction is passed to \a reduceFunction.
389
390 Note that while \a mapFunction is called concurrently, only one thread at a
391 time will call \a reduceFunction. The order in which \a reduceFunction is
392 called is determined by \a reduceOptions.
393
394 \sa {Concurrent Map and Map-Reduce}
395*/
396
397/*!
398 \fn template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor, typename InitialValueType> QFuture<ResultType> QtConcurrent::mappedReduced(QThreadPool *pool, Sequence &&sequence, MapFunctor &&mapFunction, ReduceFunctor &&reduceFunction, InitialValueType &&initialValue, QtConcurrent::ReduceOptions reduceOptions)
399
400 Calls \a mapFunction once for each item in \a sequence.
401 All calls to \a mapFunction are invoked from the threads taken from the QThreadPool \a pool.
402 The return value of each \a mapFunction is passed to \a reduceFunction.
403 The result value is initialized to \a initialValue when the function is
404 called, and the first call to \a reduceFunction will operate on
405 this value.
406
407 Note that while \a mapFunction is called concurrently, only one thread at a
408 time will call \a reduceFunction. The order in which \a reduceFunction is
409 called is determined by \a reduceOptions.
410
411 \sa {Concurrent Map and Map-Reduce}
412*/
413
414/*!
415 \fn template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor, typename InitialValueType> QFuture<ResultType> QtConcurrent::mappedReduced(Sequence &&sequence, MapFunctor &&mapFunction, ReduceFunctor &&reduceFunction, InitialValueType &&initialValue, QtConcurrent::ReduceOptions reduceOptions)
416
417 Calls \a mapFunction once for each item in \a sequence. The return value of
418 each \a mapFunction is passed to \a reduceFunction.
419 The result value is initialized to \a initialValue when the function is
420 called, and the first call to \a reduceFunction will operate on
421 this value.
422
423 Note that while \a mapFunction is called concurrently, only one thread at a
424 time will call \a reduceFunction. The order in which \a reduceFunction is
425 called is determined by \a reduceOptions.
426
427 \sa {Concurrent Map and Map-Reduce}
428*/
429
430/*!
431 \fn template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor> QFuture<ResultType> QtConcurrent::mappedReduced(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor &&mapFunction, ReduceFunctor &&reduceFunction, QtConcurrent::ReduceOptions reduceOptions)
432
433 Calls \a mapFunction once for each item from \a begin to \a end.
434 All calls to \a mapFunction are invoked from the threads taken from the QThreadPool \a pool.
435 The return value of each \a mapFunction is passed to \a reduceFunction.
436
437 Note that while \a mapFunction is called concurrently, only one thread at a
438 time will call \a reduceFunction. By default, the order in which
439 \a reduceFunction is called is undefined.
440
441 \note QtConcurrent::OrderedReduce results in the ordered reduction.
442
443 \sa {Concurrent Map and Map-Reduce}
444*/
445
446/*!
447 \fn template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor> QFuture<ResultType> QtConcurrent::mappedReduced(Iterator begin, Iterator end, MapFunctor &&mapFunction, ReduceFunctor &&reduceFunction, QtConcurrent::ReduceOptions reduceOptions)
448
449 Calls \a mapFunction once for each item from \a begin to \a end. The return
450 value of each \a mapFunction is passed to \a reduceFunction.
451
452 Note that while \a mapFunction is called concurrently, only one thread at a
453 time will call \a reduceFunction. By default, the order in which
454 \a reduceFunction is called is undefined.
455
456 \note QtConcurrent::OrderedReduce results in the ordered reduction.
457
458 \sa {Concurrent Map and Map-Reduce}
459*/
460
461/*!
462 \fn template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor, typename InitialValueType> QFuture<ResultType> QtConcurrent::mappedReduced(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor &&mapFunction, ReduceFunctor &&reduceFunction, InitialValueType &&initialValue, QtConcurrent::ReduceOptions reduceOptions)
463
464 Calls \a mapFunction once for each item from \a begin to \a end.
465 All calls to \a mapFunction are invoked from the threads taken from the QThreadPool \a pool.
466 The return value of each \a mapFunction is passed to \a reduceFunction.
467 The result value is initialized to \a initialValue when the function is
468 called, and the first call to \a reduceFunction will operate on
469 this value.
470
471 Note that while \a mapFunction is called concurrently, only one thread at a
472 time will call \a reduceFunction. By default, the order in which
473 \a reduceFunction is called is undefined.
474
475 \note QtConcurrent::OrderedReduce results in the ordered reduction.
476
477 \sa {Concurrent Map and Map-Reduce}
478*/
479
480/*!
481 \fn template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor, typename InitialValueType> QFuture<ResultType> QtConcurrent::mappedReduced(Iterator begin, Iterator end, MapFunctor &&mapFunction, ReduceFunctor &&reduceFunction, InitialValueType &&initialValue, QtConcurrent::ReduceOptions reduceOptions)
482
483 Calls \a mapFunction once for each item from \a begin to \a end. The return
484 value of each \a mapFunction is passed to \a reduceFunction.
485 The result value is initialized to \a initialValue when the function is
486 called, and the first call to \a reduceFunction will operate on
487 this value.
488
489 Note that while \a mapFunction is called concurrently, only one thread at a
490 time will call \a reduceFunction. By default, the order in which
491 \a reduceFunction is called is undefined.
492
493 \note QtConcurrent::OrderedReduce results in the ordered reduction.
494
495 \sa {Concurrent Map and Map-Reduce}
496*/
497
498/*!
499 \fn template <typename Sequence, typename MapFunctor> void QtConcurrent::blockingMap(QThreadPool *pool, Sequence &&sequence, MapFunctor function)
500
501 Calls \a function once for each item in \a sequence.
502 All calls to \a function are invoked from the threads taken from the QThreadPool \a pool.
503 The \a function takes a reference to the item, so that any modifications done to the item
504 will appear in \a sequence.
505
506 \note This function will block until all items in the sequence have been processed.
507
508 \sa map(), {Concurrent Map and Map-Reduce}
509*/
510
511/*!
512 \fn template <typename Sequence, typename MapFunctor> void QtConcurrent::blockingMap(Sequence &&sequence, MapFunctor &&function)
513
514 Calls \a function once for each item in \a sequence. The \a function takes
515 a reference to the item, so that any modifications done to the item
516 will appear in \a sequence.
517
518 \note This function will block until all items in the sequence have been processed.
519
520 \sa map(), {Concurrent Map and Map-Reduce}
521*/
522
523/*!
524 \fn template <typename Iterator, typename MapFunctor> void QtConcurrent::blockingMap(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor &&function)
525
526 Calls \a function once for each item from \a begin to \a end.
527 All calls to \a function are invoked from the threads taken from the QThreadPool \a pool.
528 The \a function takes a reference to the item, so that any modifications
529 done to the item will appear in the sequence which the iterators belong to.
530
531 \note This function will block until the iterator reaches the end of the
532 sequence being processed.
533
534 \sa map(), {Concurrent Map and Map-Reduce}
535*/
536
537/*!
538 \fn template <typename Iterator, typename MapFunctor> void QtConcurrent::blockingMap(Iterator begin, Iterator end, MapFunctor &&function)
539
540 Calls \a function once for each item from \a begin to \a end. The
541 \a function takes a reference to the item, so that any modifications
542 done to the item will appear in the sequence which the iterators belong to.
543
544 \note This function will block until the iterator reaches the end of the
545 sequence being processed.
546
547 \sa map(), {Concurrent Map and Map-Reduce}
548*/
549
550/*!
551 \fn template <typename OutputSequence, typename InputSequence, typename MapFunctor> OutputSequence QtConcurrent::blockingMapped(QThreadPool *pool, InputSequence &&sequence, MapFunctor &&function)
552
553 Calls \a function once for each item in \a sequence and returns an OutputSequence containing
554 the results. All calls to \a function are invoked from the threads taken from the QThreadPool
555 \a pool. The type of the results will match the type returned by the MapFunctor.
556
557 \note This function will block until all items in the sequence have been processed.
558
559 \sa mapped(), {Concurrent Map and Map-Reduce}
560*/
561
562/*!
563 \fn template <typename OutputSequence, typename InputSequence, typename MapFunctor> OutputSequence QtConcurrent::blockingMapped(InputSequence &&sequence, MapFunctor &&function)
564
565 Calls \a function once for each item in \a sequence and returns an OutputSequence containing
566 the results. The type of the results will match the type returned by the MapFunctor.
567
568 \note This function will block until all items in the sequence have been processed.
569
570 \sa mapped(), {Concurrent Map and Map-Reduce}
571*/
572
573/*!
574 \fn template <typename Sequence, typename Iterator, typename MapFunctor> Sequence QtConcurrent::blockingMapped(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor &&function)
575
576 Calls \a function once for each item from \a begin to \a end and returns a
577 container with the results. All calls to \a function are invoked from the threads
578 taken from the QThreadPool \a pool. You can specify the type of container as the a template
579 argument, like this:
580
581 \code
582 QList<int> ints = QtConcurrent::blockingMapped<QList<int> >(beginIterator, endIterator, fn);
583 \endcode
584
585 \note This function will block until the iterator reaches the end of the
586 sequence being processed.
587
588 \sa mapped(), {Concurrent Map and Map-Reduce}
589*/
590
591/*!
592 \fn template <typename Sequence, typename Iterator, typename MapFunctor> Sequence QtConcurrent::blockingMapped(Iterator begin, Iterator end, MapFunctor &&function)
593
594 Calls \a function once for each item from \a begin to \a end and returns a
595 container with the results. You can specify the type of container as the a template
596 argument, like this:
597
598 \code
599 QList<int> ints = QtConcurrent::blockingMapped<QList<int> >(beginIterator, endIterator, fn);
600 \endcode
601
602 \note This function will block until the iterator reaches the end of the
603 sequence being processed.
604
605 \sa mapped(), {Concurrent Map and Map-Reduce}
606*/
607
608/*!
609 \fn template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor> ResultType QtConcurrent::blockingMappedReduced(QThreadPool *pool, Sequence &&sequence, MapFunctor &&mapFunction, ReduceFunctor &&reduceFunction, QtConcurrent::ReduceOptions reduceOptions)
610
611 Calls \a mapFunction once for each item in \a sequence.
612 All calls to \a mapFunction are invoked from the threads taken from the QThreadPool \a pool.
613 The return value of each \a mapFunction is passed to \a reduceFunction.
614
615 Note that while \a mapFunction is called concurrently, only one thread at a
616 time will call \a reduceFunction. The order in which \a reduceFunction is
617 called is determined by \a reduceOptions.
618
619 \note This function will block until all items in the sequence have been processed.
620
621 \sa mapped(), {Concurrent Map and Map-Reduce}
622*/
623
624/*!
625 \fn template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor> ResultType QtConcurrent::blockingMappedReduced(Sequence &&sequence, MapFunctor &&mapFunction, ReduceFunctor &&reduceFunction, QtConcurrent::ReduceOptions reduceOptions)
626
627 Calls \a mapFunction once for each item in \a sequence. The return value of
628 each \a mapFunction is passed to \a reduceFunction.
629
630 Note that while \a mapFunction is called concurrently, only one thread at a
631 time will call \a reduceFunction. The order in which \a reduceFunction is
632 called is determined by \a reduceOptions.
633
634 \note This function will block until all items in the sequence have been processed.
635
636 \sa mapped(), {Concurrent Map and Map-Reduce}
637*/
638
639/*!
640 \fn template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor, typename InitialValueType> ResultType QtConcurrent::blockingMappedReduced(QThreadPool *pool, Sequence &&sequence, MapFunctor &&mapFunction, ReduceFunctor &&reduceFunction, InitialValueType &&initialValue, QtConcurrent::ReduceOptions reduceOptions)
641
642 Calls \a mapFunction once for each item in \a sequence.
643 All calls to \a mapFunction are invoked from the threads taken from the QThreadPool \a pool.
644 The return value of each \a mapFunction is passed to \a reduceFunction.
645 The result value is initialized to \a initialValue when the function is
646 called, and the first call to \a reduceFunction will operate on
647 this value.
648
649 Note that while \a mapFunction is called concurrently, only one thread at a
650 time will call \a reduceFunction. The order in which \a reduceFunction is
651 called is determined by \a reduceOptions.
652
653 \note This function will block until all items in the sequence have been processed.
654
655 \sa mapped(), {Concurrent Map and Map-Reduce}
656*/
657
658/*!
659 \fn template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor, typename InitialValueType> ResultType QtConcurrent::blockingMappedReduced(Sequence &&sequence, MapFunctor &&mapFunction, ReduceFunctor &&reduceFunction, InitialValueType &&initialValue, QtConcurrent::ReduceOptions reduceOptions)
660
661 Calls \a mapFunction once for each item in \a sequence. The return value of
662 each \a mapFunction is passed to \a reduceFunction.
663 The result value is initialized to \a initialValue when the function is
664 called, and the first call to \a reduceFunction will operate on
665 this value.
666
667 Note that while \a mapFunction is called concurrently, only one thread at a
668 time will call \a reduceFunction. The order in which \a reduceFunction is
669 called is determined by \a reduceOptions.
670
671 \note This function will block until all items in the sequence have been processed.
672
673 \sa mapped(), {Concurrent Map and Map-Reduce}
674*/
675
676/*!
677 \fn template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor> ResultType QtConcurrent::blockingMappedReduced(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor &&mapFunction, ReduceFunctor &&reduceFunction, QtConcurrent::ReduceOptions reduceOptions)
678
679 Calls \a mapFunction once for each item from \a begin to \a end.
680 All calls to \a mapFunction are invoked from the threads taken from the QThreadPool \a pool.
681 The return value of each \a mapFunction is passed to \a reduceFunction.
682
683 Note that while \a mapFunction is called concurrently, only one thread at a
684 time will call \a reduceFunction. The order in which \a reduceFunction is
685 called is undefined.
686
687 \note This function will block until the iterator reaches the end of the
688 sequence being processed.
689
690 \sa blockingMappedReduced(), {Concurrent Map and Map-Reduce}
691*/
692
693/*!
694 \fn template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor> ResultType QtConcurrent::blockingMappedReduced(Iterator begin, Iterator end, MapFunctor &&mapFunction, ReduceFunctor &&reduceFunction, QtConcurrent::ReduceOptions reduceOptions)
695
696 Calls \a mapFunction once for each item from \a begin to \a end. The return
697 value of each \a mapFunction is passed to \a reduceFunction.
698
699 Note that while \a mapFunction is called concurrently, only one thread at a
700 time will call \a reduceFunction. The order in which \a reduceFunction is
701 called is undefined.
702
703 \note This function will block until the iterator reaches the end of the
704 sequence being processed.
705
706 \sa blockingMappedReduced(), {Concurrent Map and Map-Reduce}
707*/
708
709/*!
710 \fn template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor, typename InitialValueType> ResultType QtConcurrent::blockingMappedReduced(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor &&mapFunction, ReduceFunctor &&reduceFunction, InitialValueType &&initialValue, QtConcurrent::ReduceOptions reduceOptions)
711
712 Calls \a mapFunction once for each item from \a begin to \a end.
713 All calls to \a mapFunction are invoked from the threads taken from the QThreadPool \a pool.
714 The return value of each \a mapFunction is passed to \a reduceFunction.
715 The result value is initialized to \a initialValue when the function is
716 called, and the first call to \a reduceFunction will operate on
717 this value.
718
719 Note that while \a mapFunction is called concurrently, only one thread at a
720 time will call \a reduceFunction. The order in which \a reduceFunction is
721 called is undefined.
722
723 \note This function will block until the iterator reaches the end of the
724 sequence being processed.
725
726 \sa blockingMappedReduced(), {Concurrent Map and Map-Reduce}
727*/
728
729/*!
730 \fn template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor, typename InitialValueType> ResultType QtConcurrent::blockingMappedReduced(Iterator begin, Iterator end, MapFunctor &&mapFunction, ReduceFunctor &&reduceFunction, InitialValueType &&initialValue, QtConcurrent::ReduceOptions reduceOptions)
731
732 Calls \a mapFunction once for each item from \a begin to \a end. The return
733 value of each \a mapFunction is passed to \a reduceFunction.
734 The result value is initialized to \a initialValue when the function is
735 called, and the first call to \a reduceFunction will operate on
736 this value.
737
738 Note that while \a mapFunction is called concurrently, only one thread at a
739 time will call \a reduceFunction. The order in which \a reduceFunction is
740 called is undefined.
741
742 \note This function will block until the iterator reaches the end of the
743 sequence being processed.
744
745 \sa blockingMappedReduced(), {Concurrent Map and Map-Reduce}
746*/
747

source code of qtbase/src/concurrent/qtconcurrentmap.cpp