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