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

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