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

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