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