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