QtBase  v6.3.1
qtconcurrentmap.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the QtConcurrent module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 #ifndef QTCONCURRENT_MAP_H
41 #define QTCONCURRENT_MAP_H
42 
43 #include <QtConcurrent/qtconcurrent_global.h>
44 
45 #if !defined(QT_NO_CONCURRENT) || defined(Q_CLANG_QDOC)
46 
47 #include <QtConcurrent/qtconcurrentmapkernel.h>
48 #include <QtConcurrent/qtconcurrentreducekernel.h>
49 #include <QtConcurrent/qtconcurrentfunctionwrappers.h>
50 
52 
53 
54 
55 namespace QtConcurrent {
56 
57 // map() on sequences
58 template <typename Sequence, typename MapFunctor>
59 QFuture<void> map(QThreadPool *pool, Sequence &&sequence, MapFunctor &&map)
60 {
61  return startMap(pool, sequence.begin(), sequence.end(), std::forward<MapFunctor>(map));
62 }
63 
64 template <typename Sequence, typename MapFunctor>
65 QFuture<void> map(Sequence &&sequence, MapFunctor &&map)
66 {
67  return startMap(QThreadPool::globalInstance(), sequence.begin(), sequence.end(),
68  std::forward<MapFunctor>(map));
69 }
70 
71 // map() on iterators
72 template <typename Iterator, typename MapFunctor>
73 QFuture<void> map(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor &&map)
74 {
75  return startMap(pool, begin, end, std::forward<MapFunctor>(map));
76 }
77 
78 template <typename Iterator, typename MapFunctor>
79 QFuture<void> map(Iterator begin, Iterator end, MapFunctor &&map)
80 {
81  return startMap(QThreadPool::globalInstance(), begin, end, std::forward<MapFunctor>(map));
82 }
83 
84 // mappedReduced() for sequences.
85 template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor>
87  Sequence &&sequence,
88  MapFunctor &&map,
89  ReduceFunctor &&reduce,
90  ReduceOptions options = ReduceOptions(UnorderedReduce
92 {
93  return startMappedReduced<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
94  (pool, std::forward<Sequence>(sequence), std::forward<MapFunctor>(map),
95  std::forward<ReduceFunctor>(reduce), options);
96 }
97 
98 template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor>
99 QFuture<ResultType> mappedReduced(Sequence &&sequence,
100  MapFunctor &&map,
101  ReduceFunctor &&reduce,
102  ReduceOptions options = ReduceOptions(UnorderedReduce
103  | SequentialReduce))
104 {
105  return startMappedReduced<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
106  (QThreadPool::globalInstance(), std::forward<Sequence>(sequence),
107  std::forward<MapFunctor>(map), std::forward<ReduceFunctor>(reduce), options);
108 }
109 
110 #ifdef Q_CLANG_QDOC
111 template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor,
112  typename InitialValueType>
113 #else
114 template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor,
115  typename InitialValueType,
116  std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>,
117  int> = 0>
118 #endif
120  Sequence &&sequence,
121  MapFunctor &&map,
122  ReduceFunctor &&reduce,
123  InitialValueType &&initialValue,
124  ReduceOptions options = ReduceOptions(UnorderedReduce
125  | SequentialReduce))
126 {
127  return startMappedReduced<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>(
128  pool, std::forward<Sequence>(sequence), std::forward<MapFunctor>(map),
129  std::forward<ReduceFunctor>(reduce),
130  ResultType(std::forward<InitialValueType>(initialValue)), options);
131 }
132 #ifdef Q_CLANG_QDOC
133 template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor,
134  typename InitialValueType>
135 #else
136 template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor,
137  typename InitialValueType,
138  std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>,
139  int> = 0>
140 #endif
141 QFuture<ResultType> mappedReduced(Sequence &&sequence,
142  MapFunctor &&map,
143  ReduceFunctor &&reduce,
144  InitialValueType &&initialValue,
145  ReduceOptions options = ReduceOptions(UnorderedReduce
146  | SequentialReduce))
147 {
148  return startMappedReduced<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
149  (QThreadPool::globalInstance(), std::forward<Sequence>(sequence),
150  std::forward<MapFunctor>(map), std::forward<ReduceFunctor>(reduce),
151  ResultType(std::forward<InitialValueType>(initialValue)), options);
152 }
153 
154 template <typename Sequence, typename MapFunctor, typename ReduceFunctor,
156  typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type>
158  Sequence &&sequence,
159  MapFunctor &&map,
160  ReduceFunctor &&reduce,
161  ReduceOptions options = ReduceOptions(UnorderedReduce
162  | SequentialReduce))
163 {
164  return startMappedReduced<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
165  (pool, std::forward<Sequence>(sequence), std::forward<MapFunctor>(map),
166  std::forward<ReduceFunctor>(reduce), options);
167 }
168 
169 template <typename Sequence, typename MapFunctor, typename ReduceFunctor,
171  typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type>
172 QFuture<ResultType> mappedReduced(Sequence &&sequence,
173  MapFunctor &&map,
174  ReduceFunctor &&reduce,
175  ReduceOptions options = ReduceOptions(UnorderedReduce
176  | SequentialReduce))
177 {
178  return startMappedReduced<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
179  (QThreadPool::globalInstance(), std::forward<Sequence>(sequence),
180  std::forward<MapFunctor>(map), std::forward<ReduceFunctor>(reduce), options);
181 }
182 
183 #ifdef Q_CLANG_QDOC
184 template <typename Sequence, typename MapFunctor, typename ReduceFunctor, typename ResultType,
185  typename InitialValueType>
186 #else
187 template <typename Sequence, typename MapFunctor, typename ReduceFunctor, typename InitialValueType,
189  typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type,
190  std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>,
191  int> = 0>
192 #endif
194  Sequence &&sequence,
195  MapFunctor &&map,
196  ReduceFunctor &&reduce,
197  InitialValueType &&initialValue,
198  ReduceOptions options = ReduceOptions(UnorderedReduce
199  | SequentialReduce))
200 {
201  return startMappedReduced<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>(
202  pool, std::forward<Sequence>(sequence), std::forward<MapFunctor>(map),
203  std::forward<ReduceFunctor>(reduce),
204  ResultType(std::forward<InitialValueType>(initialValue)), options);
205 }
206 
207 #ifdef Q_CLANG_QDOC
208 template <typename Sequence, typename MapFunctor, typename ReduceFunctor, typename ResultType,
209  typename InitialValueType>
210 #else
211 template <typename Sequence, typename MapFunctor, typename ReduceFunctor, typename InitialValueType,
213  typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type,
214  std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>,
215  int> = 0>
216 #endif
217 QFuture<ResultType> mappedReduced(Sequence &&sequence,
218  MapFunctor &&map,
219  ReduceFunctor &&reduce,
220  InitialValueType &&initialValue,
221  ReduceOptions options = ReduceOptions(UnorderedReduce
222  | SequentialReduce))
223 {
224  return startMappedReduced<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
225  (QThreadPool::globalInstance(), std::forward<Sequence>(sequence),
226  std::forward<MapFunctor>(map), std::forward<ReduceFunctor>(reduce),
227  ResultType(std::forward<InitialValueType>(initialValue)), options);
228 }
229 
230 // mappedReduced() for iterators
231 template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor>
233  Iterator begin,
234  Iterator end,
235  MapFunctor &&map,
236  ReduceFunctor &&reduce,
237  ReduceOptions options = ReduceOptions(UnorderedReduce
238  | SequentialReduce))
239 {
240  return startMappedReduced<QtPrivate::MapResultType<Iterator, MapFunctor>, ResultType>
241  (pool, begin, end, std::forward<MapFunctor>(map), std::forward<ReduceFunctor>(reduce),
242  options);
243 }
244 
245 template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor>
247  Iterator end,
248  MapFunctor &&map,
249  ReduceFunctor &&reduce,
250  ReduceOptions options = ReduceOptions(UnorderedReduce
251  | SequentialReduce))
252 {
253  return startMappedReduced<QtPrivate::MapResultType<Iterator, MapFunctor>, ResultType>
254  (QThreadPool::globalInstance(), begin, end, std::forward<MapFunctor>(map),
255  std::forward<ReduceFunctor>(reduce), options);
256 }
257 
258 #ifdef Q_CLANG_QDOC
259 template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor,
260  typename InitialValueType>
261 #else
262 template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor,
263  typename InitialValueType,
264  std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>,
265  int> = 0>
266 #endif
268  Iterator begin,
269  Iterator end,
270  MapFunctor &&map,
271  ReduceFunctor &&reduce,
272  InitialValueType &&initialValue,
273  ReduceOptions options = ReduceOptions(UnorderedReduce
274  | SequentialReduce))
275 {
276  return startMappedReduced<QtPrivate::MapResultType<Iterator, MapFunctor>, ResultType>
277  (pool, begin, end, std::forward<MapFunctor>(map), std::forward<ReduceFunctor>(reduce),
278  ResultType(std::forward<InitialValueType>(initialValue)), options);
279 }
280 
281 #ifdef Q_CLANG_QDOC
282 template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor,
283  typename InitialValueType>
284 #else
285 template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor,
286  typename InitialValueType,
287  std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>,
288  int> = 0>
289 #endif
291  Iterator end,
292  MapFunctor &&map,
293  ReduceFunctor &&reduce,
294  InitialValueType &&initialValue,
295  ReduceOptions options = ReduceOptions(UnorderedReduce
296  | SequentialReduce))
297 {
298  return startMappedReduced<QtPrivate::MapResultType<Iterator, MapFunctor>, ResultType>
299  (QThreadPool::globalInstance(), begin, end, std::forward<MapFunctor>(map),
300  std::forward<ReduceFunctor>(reduce),
301  ResultType(std::forward<InitialValueType>(initialValue)), options);
302 }
303 
304 template <typename Iterator, typename MapFunctor, typename ReduceFunctor,
305  typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type>
307  Iterator begin,
308  Iterator end,
309  MapFunctor &&map,
310  ReduceFunctor &&reduce,
311  ReduceOptions options = ReduceOptions(UnorderedReduce
312  | SequentialReduce))
313 {
314  return startMappedReduced<QtPrivate::MapResultType<Iterator, MapFunctor>, ResultType>(
315  pool, begin, end, std::forward<MapFunctor>(map), std::forward<ReduceFunctor>(reduce),
316  options);
317 }
318 
319 template <typename Iterator, typename MapFunctor, typename ReduceFunctor,
320  typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type>
322  Iterator end,
323  MapFunctor &&map,
324  ReduceFunctor &&reduce,
325  ReduceOptions options = ReduceOptions(UnorderedReduce
326  | SequentialReduce))
327 {
328  return startMappedReduced<QtPrivate::MapResultType<Iterator, MapFunctor>, ResultType>
329  (QThreadPool::globalInstance(), begin, end, std::forward<MapFunctor>(map),
330  std::forward<ReduceFunctor>(reduce), options);
331 }
332 
333 #ifdef Q_CLANG_QDOC
334 template <typename Iterator, typename MapFunctor, typename ReduceFunctor, typename ResultType,
335  typename InitialValueType>
336 #else
337 template <typename Iterator, typename MapFunctor, typename ReduceFunctor,
338  typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type,
339  typename InitialValueType,
340  std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>,
341  int> = 0>
342 #endif
344  Iterator begin,
345  Iterator end,
346  MapFunctor &&map,
347  ReduceFunctor &&reduce,
348  InitialValueType &&initialValue,
349  ReduceOptions options = ReduceOptions(UnorderedReduce
350  | SequentialReduce))
351 {
352  return startMappedReduced<QtPrivate::MapResultType<Iterator, MapFunctor>, ResultType>
353  (pool, begin, end, std::forward<MapFunctor>(map), std::forward<ReduceFunctor>(reduce),
354  ResultType(std::forward<InitialValueType>(initialValue)), options);
355 }
356 
357 #ifdef Q_CLANG_QDOC
358 template <typename Iterator, typename MapFunctor, typename ReduceFunctor, typename ResultType,
359  typename InitialValueType>
360 #else
361 template<typename Iterator, typename MapFunctor, typename ReduceFunctor,
362  std::enable_if_t<QtPrivate::isIterator_v<Iterator>, int> = 0,
363  typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type,
364  typename InitialValueType,
365  std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>,
366  int> = 0>
367 #endif
369  Iterator end,
370  MapFunctor &&map,
371  ReduceFunctor &&reduce,
372  InitialValueType &&initialValue,
373  ReduceOptions options = ReduceOptions(UnorderedReduce
374  | SequentialReduce))
375 {
376  return startMappedReduced<QtPrivate::MapResultType<Iterator, MapFunctor>, ResultType>
377  (QThreadPool::globalInstance(), begin, end, std::forward<MapFunctor>(map),
378  std::forward<ReduceFunctor>(reduce),
379  ResultType(std::forward<InitialValueType>(initialValue)), options);
380 }
381 
382 // mapped() for sequences
383 template <typename Sequence, typename MapFunctor>
385  QThreadPool *pool,
386  Sequence &&sequence,
387  MapFunctor &&map)
388 {
389  return startMapped<QtPrivate::MapResultType<Sequence, MapFunctor>>(
390  pool, std::forward<Sequence>(sequence), std::forward<MapFunctor>(map));
391 }
392 
393 template <typename Sequence, typename MapFunctor>
395  Sequence &&sequence,
396  MapFunctor &&map)
397 {
398  return startMapped<QtPrivate::MapResultType<Sequence, MapFunctor>>
399  (QThreadPool::globalInstance(), std::forward<Sequence>(sequence),
400  std::forward<MapFunctor>(map));
401 }
402 
403 // mapped() for iterator ranges.
404 template <typename Iterator, typename MapFunctor>
406  QThreadPool *pool,
407  Iterator begin,
408  Iterator end,
409  MapFunctor &&map)
410 {
411  return startMapped<QtPrivate::MapResultType<Iterator, MapFunctor>>(
412  pool, begin, end, std::forward<MapFunctor>(map));
413 }
414 
415 template <typename Iterator, typename MapFunctor>
417  Iterator begin,
418  Iterator end,
419  MapFunctor &&map)
420 {
421  return startMapped<QtPrivate::MapResultType<Iterator, MapFunctor>>
422  (QThreadPool::globalInstance(), begin, end, std::forward<MapFunctor>(map));
423 }
424 
425 // blockingMap() for sequences
426 template <typename Sequence, typename MapFunctor>
427 void blockingMap(QThreadPool *pool, Sequence &&sequence, MapFunctor map)
428 {
430  startMap(pool, sequence.begin(), sequence.end(), std::forward<MapFunctor>(map));
432 }
433 
434 template <typename Sequence, typename MapFunctor>
435 void blockingMap(Sequence &&sequence, MapFunctor &&map)
436 {
437  QFuture<void> future = startMap(QThreadPool::globalInstance(), sequence.begin(), sequence.end(),
438  std::forward<MapFunctor>(map));
440 }
441 
442 // blockingMap() for iterator ranges
443 template <typename Iterator, typename MapFunctor>
444 void blockingMap(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor &&map)
445 {
448 }
449 
450 template <typename Iterator, typename MapFunctor>
451 void blockingMap(Iterator begin, Iterator end, MapFunctor &&map)
452 {
454  std::forward<MapFunctor>(map));
456 }
457 
458 // blockingMappedReduced() for sequences
459 template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor>
461  Sequence &&sequence,
462  MapFunctor &&map,
463  ReduceFunctor &&reduce,
464  ReduceOptions options = ReduceOptions(UnorderedReduce
465  | SequentialReduce))
466 {
468  mappedReduced<ResultType>(pool, std::forward<Sequence>(sequence),
469  std::forward<MapFunctor>(map),
470  std::forward<ReduceFunctor>(reduce), options);
471  return future.takeResult();
472 }
473 
474 template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor>
475 ResultType blockingMappedReduced(Sequence &&sequence,
476  MapFunctor &&map,
477  ReduceFunctor &&reduce,
478  ReduceOptions options = ReduceOptions(UnorderedReduce
479  | SequentialReduce))
480 {
482  mappedReduced<ResultType>(std::forward<Sequence>(sequence),
483  std::forward<MapFunctor>(map),
484  std::forward<ReduceFunctor>(reduce), options);
485  return future.takeResult();
486 }
487 
488 #ifdef Q_CLANG_QDOC
489 template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor,
490  typename InitialValueType>
491 #else
492 template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor,
493  typename InitialValueType,
494  std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>,
495  int> = 0>
496 #endif
498  Sequence &&sequence,
499  MapFunctor &&map,
500  ReduceFunctor &&reduce,
501  InitialValueType &&initialValue,
502  ReduceOptions options = ReduceOptions(UnorderedReduce
503  | SequentialReduce))
504 {
505  QFuture<ResultType> future = mappedReduced<ResultType>(
506  pool, std::forward<Sequence>(sequence), std::forward<MapFunctor>(map),
507  std::forward<ReduceFunctor>(reduce),
508  ResultType(std::forward<InitialValueType>(initialValue)), options);
509  return future.takeResult();
510 }
511 
512 #ifdef Q_CLANG_QDOC
513 template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor,
514  typename InitialValueType>
515 #else
516 template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor,
517  typename InitialValueType,
518  std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>,
519  int> = 0>
520 #endif
521 ResultType blockingMappedReduced(Sequence &&sequence,
522  MapFunctor &&map,
523  ReduceFunctor &&reduce,
524  InitialValueType &&initialValue,
525  ReduceOptions options = ReduceOptions(UnorderedReduce
526  | SequentialReduce))
527 {
528  QFuture<ResultType> future = mappedReduced<ResultType>(
529  std::forward<Sequence>(sequence), std::forward<MapFunctor>(map),
530  std::forward<ReduceFunctor>(reduce),
531  ResultType(std::forward<InitialValueType>(initialValue)), options);
532  return future.takeResult();
533 }
534 
535 template <typename MapFunctor, typename ReduceFunctor, typename Sequence,
537  typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type>
539  Sequence &&sequence,
540  MapFunctor &&map,
541  ReduceFunctor &&reduce,
542  ReduceOptions options = ReduceOptions(UnorderedReduce
543  | SequentialReduce))
544 {
546  mappedReduced<ResultType>(pool, std::forward<Sequence>(sequence),
547  std::forward<MapFunctor>(map),
548  std::forward<ReduceFunctor>(reduce), options);
549  return future.takeResult();
550 }
551 
552 template <typename MapFunctor, typename ReduceFunctor, typename Sequence,
554  typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type>
555 ResultType blockingMappedReduced(Sequence &&sequence,
556  MapFunctor &&map,
557  ReduceFunctor &&reduce,
558  ReduceOptions options = ReduceOptions(UnorderedReduce
559  | SequentialReduce))
560 {
562  mappedReduced<ResultType>(std::forward<Sequence>(sequence),
563  std::forward<MapFunctor>(map),
564  std::forward<ReduceFunctor>(reduce), options);
565  return future.takeResult();
566 }
567 
568 #ifdef Q_CLANG_QDOC
569 template <typename MapFunctor, typename ReduceFunctor, typename Sequence, typename ResultType,
570  typename InitialValueType>
571 #else
572 template <typename MapFunctor, typename ReduceFunctor, typename Sequence, typename InitialValueType,
574  typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type,
575  std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>,
576  int> = 0>
577 #endif
579  Sequence &&sequence,
580  MapFunctor &&map,
581  ReduceFunctor &&reduce,
582  InitialValueType &&initialValue,
583  ReduceOptions options = ReduceOptions(UnorderedReduce
584  | SequentialReduce))
585 {
586  QFuture<ResultType> future = mappedReduced<ResultType>(
587  pool, std::forward<Sequence>(sequence), std::forward<MapFunctor>(map),
588  std::forward<ReduceFunctor>(reduce),
589  ResultType(std::forward<InitialValueType>(initialValue)), options);
590  return future.takeResult();
591 }
592 
593 #ifdef Q_CLANG_QDOC
594 template <typename MapFunctor, typename ReduceFunctor, typename Sequence, typename ResultType,
595  typename InitialValueType>
596 #else
597 template<typename MapFunctor, typename ReduceFunctor, typename Sequence, typename InitialValueType,
599  typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type,
600  std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>,
601  int> = 0>
602 #endif
603 ResultType blockingMappedReduced(Sequence &&sequence,
604  MapFunctor &&map,
605  ReduceFunctor &&reduce,
606  InitialValueType &&initialValue,
607  ReduceOptions options = ReduceOptions(UnorderedReduce
608  | SequentialReduce))
609 {
610  QFuture<ResultType> future = mappedReduced<ResultType>(
611  std::forward<Sequence>(sequence), std::forward<MapFunctor>(map),
612  std::forward<ReduceFunctor>(reduce),
613  ResultType(std::forward<InitialValueType>(initialValue)), options);
614  return future.takeResult();
615 }
616 
617 // blockingMappedReduced() for iterator ranges
618 template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor>
620  Iterator begin,
621  Iterator end,
622  MapFunctor &&map,
623  ReduceFunctor &&reduce,
624  ReduceOptions options = ReduceOptions(UnorderedReduce
625  | SequentialReduce))
626 {
628  mappedReduced<ResultType>(pool, begin, end, std::forward<MapFunctor>(map),
629  std::forward<ReduceFunctor>(reduce), options);
630  return future.takeResult();
631 }
632 
633 template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor>
634 ResultType blockingMappedReduced(Iterator begin,
635  Iterator end,
636  MapFunctor &&map,
637  ReduceFunctor &&reduce,
638  ReduceOptions options = ReduceOptions(UnorderedReduce
639  | SequentialReduce))
640 {
642  mappedReduced<ResultType>(begin, end, std::forward<MapFunctor>(map),
643  std::forward<ReduceFunctor>(reduce), options);
644  return future.takeResult();
645 }
646 
647 #ifdef Q_CLANG_QDOC
648 template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor,
649  typename InitialValueType>
650 #else
651 template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor,
652  typename InitialValueType,
653  std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>,
654  int> = 0>
655 #endif
657  Iterator begin,
658  Iterator end,
659  MapFunctor &&map,
660  ReduceFunctor &&reduce,
661  InitialValueType &&initialValue,
662  ReduceOptions options = ReduceOptions(UnorderedReduce
663  | SequentialReduce))
664 {
665  QFuture<ResultType> future = mappedReduced<ResultType>(
666  pool, begin, end, std::forward<MapFunctor>(map), std::forward<ReduceFunctor>(reduce),
667  ResultType(std::forward<InitialValueType>(initialValue)),
668  options);
669  return future.takeResult();
670 }
671 
672 #ifdef Q_CLANG_QDOC
673 template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor,
674  typename InitialValueType>
675 #else
676 template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor,
677  typename InitialValueType,
678  std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>,
679  int> = 0>
680 #endif
681 ResultType blockingMappedReduced(Iterator begin,
682  Iterator end,
683  MapFunctor &&map,
684  ReduceFunctor &&reduce,
685  InitialValueType &&initialValue,
686  ReduceOptions options = ReduceOptions(UnorderedReduce
687  | SequentialReduce))
688 {
689  QFuture<ResultType> future = mappedReduced<ResultType>(
690  begin, end, std::forward<MapFunctor>(map), std::forward<ReduceFunctor>(reduce),
691  ResultType(std::forward<InitialValueType>(initialValue)),
692  options);
693  return future.takeResult();
694 }
695 
696 template <typename Iterator, typename MapFunctor, typename ReduceFunctor,
697  typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type>
699  Iterator begin,
700  Iterator end,
701  MapFunctor &&map,
702  ReduceFunctor &&reduce,
703  ReduceOptions options = ReduceOptions(UnorderedReduce
704  | SequentialReduce))
705 {
707  mappedReduced<ResultType>(pool, begin, end, std::forward<MapFunctor>(map),
708  std::forward<ReduceFunctor>(reduce), options);
709  return future.takeResult();
710 }
711 
712 template <typename Iterator, typename MapFunctor, typename ReduceFunctor,
713  typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type>
714 ResultType blockingMappedReduced(Iterator begin,
715  Iterator end,
716  MapFunctor &&map,
717  ReduceFunctor &&reduce,
718  ReduceOptions options = ReduceOptions(UnorderedReduce
719  | SequentialReduce))
720 {
722  mappedReduced<ResultType>(begin, end, std::forward<MapFunctor>(map),
723  std::forward<ReduceFunctor>(reduce), options);
724  return future.takeResult();
725 }
726 
727 #ifdef Q_CLANG_QDOC
728 template <typename Iterator, typename MapFunctor, typename ReduceFunctor, typename ResultType,
729  typename InitialValueType>
730 #else
731 template <typename Iterator, typename MapFunctor, typename ReduceFunctor,
732  typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type,
733  typename InitialValueType,
734  std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>,
735  int> = 0>
736 #endif
738  Iterator begin,
739  Iterator end,
740  MapFunctor &&map,
741  ReduceFunctor &&reduce,
742  InitialValueType &&initialValue,
743  ReduceOptions options = ReduceOptions(UnorderedReduce
744  | SequentialReduce))
745 {
746  QFuture<ResultType> future = mappedReduced<ResultType>(
747  pool, begin, end, std::forward<MapFunctor>(map), std::forward<ReduceFunctor>(reduce),
748  ResultType(std::forward<InitialValueType>(initialValue)), options);
749  return future.takeResult();
750 }
751 
752 #ifdef Q_CLANG_QDOC
753 template <typename Iterator, typename MapFunctor, typename ReduceFunctor, typename ResultType,
754  typename InitialValueType>
755 #else
756 template <typename Iterator, typename MapFunctor, typename ReduceFunctor,
757  std::enable_if_t<QtPrivate::isIterator_v<Iterator>, int> = 0,
758  typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type,
759  typename InitialValueType,
760  std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>,
761  int> = 0>
762 #endif
763 ResultType blockingMappedReduced(Iterator begin,
764  Iterator end,
765  MapFunctor &&map,
766  ReduceFunctor &&reduce,
767  InitialValueType &&initialValue,
768  ReduceOptions options = ReduceOptions(UnorderedReduce
769  | SequentialReduce))
770 {
771  QFuture<ResultType> future = mappedReduced<ResultType>(
772  begin, end, std::forward<MapFunctor>(map), std::forward<ReduceFunctor>(reduce),
773  ResultType(std::forward<InitialValueType>(initialValue)), options);
774  return future.takeResult();
775 }
776 
777 // mapped() for sequences with a different putput sequence type.
778 template <typename OutputSequence, typename InputSequence, typename MapFunctor>
780 {
781  return blockingMappedReduced<OutputSequence>(pool, std::forward<InputSequence>(sequence),
782  std::forward<MapFunctor>(map),
784 }
785 
786 template <typename OutputSequence, typename InputSequence, typename MapFunctor>
788 {
789  return blockingMappedReduced<OutputSequence>(
790  QThreadPool::globalInstance(), std::forward<InputSequence>(sequence),
791  std::forward<MapFunctor>(map), QtPrivate::PushBackWrapper(), OrderedReduce);
792 }
793 
794 template <typename MapFunctor, typename InputSequence>
795 auto blockingMapped(QThreadPool *pool, InputSequence &&sequence, MapFunctor &&map)
796 {
798  MapFunctor>::ResultType;
799  return blockingMappedReduced<OutputSequence>(pool, std::forward<InputSequence>(sequence),
800  std::forward<MapFunctor>(map),
802 }
803 
804 template <typename MapFunctor, typename InputSequence>
805 auto blockingMapped(InputSequence &&sequence, MapFunctor &&map)
806 {
808  MapFunctor>::ResultType;
809  return blockingMappedReduced<OutputSequence>(QThreadPool::globalInstance(),
810  std::forward<InputSequence>(sequence),
811  std::forward<MapFunctor>(map),
813 }
814 
815 // mapped() for iterator ranges
816 template <typename Sequence, typename Iterator, typename MapFunctor>
817 Sequence blockingMapped(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor &&map)
818 {
819  return blockingMappedReduced<Sequence>(pool, begin, end, std::forward<MapFunctor>(map),
821 }
822 
823 template <typename Sequence, typename Iterator, typename MapFunctor>
824 Sequence blockingMapped(Iterator begin, Iterator end, MapFunctor &&map)
825 {
826  return blockingMappedReduced<Sequence>(QThreadPool::globalInstance(), begin, end,
827  std::forward<MapFunctor>(map),
829 }
830 
831 template <typename Iterator, typename MapFunctor>
832 auto blockingMapped(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor &&map)
833 {
835  return blockingMappedReduced<OutputSequence>(pool, begin, end, std::forward<MapFunctor>(map),
837 }
838 
839 template <typename Iterator, typename MapFunctor>
840 auto blockingMapped(Iterator begin, Iterator end, MapFunctor &&map)
841 {
843  return blockingMappedReduced<OutputSequence>(QThreadPool::globalInstance(), begin, end,
844  std::forward<MapFunctor>(map),
846 }
847 
848 } // namespace QtConcurrent
849 
850 
852 
853 #endif // QT_NO_CONCURRENT
854 
855 #endif
#define value
[5]
void waitForFinished()
Definition: qfuture.h:138
T takeResult()
Definition: qfuture.h:153
The QThreadPool class manages a collection of QThreads.
Definition: qthreadpool.h:56
static QThreadPool * globalInstance()
void reduce(WordCount &result, const WordCount &w)
Definition: main.cpp:127
The QtConcurrent namespace provides high-level APIs that make it possible to write multi-threaded pro...
Definition: qtaskbuilder.h:81
void blockingMap(QThreadPool *pool, Sequence &&sequence, MapFunctor map)
ThreadEngineStarter< void > startMap(QThreadPool *pool, Iterator begin, Iterator end, Functor &&functor)
[qtconcurrentmapkernel-1]
QFuture< void > map(QThreadPool *pool, Sequence &&sequence, MapFunctor &&map)
QFuture< QtPrivate::MapResultType< Sequence, MapFunctor > > mapped(QThreadPool *pool, Sequence &&sequence, MapFunctor &&map)
QFuture< ResultType > mappedReduced(QThreadPool *pool, Sequence &&sequence, MapFunctor &&map, ReduceFunctor &&reduce, ReduceOptions options=ReduceOptions(UnorderedReduce|SequentialReduce))
ResultType blockingMappedReduced(QThreadPool *pool, Sequence &&sequence, MapFunctor &&map, ReduceFunctor &&reduce, ReduceOptions options=ReduceOptions(UnorderedReduce|SequentialReduce))
OutputSequence blockingMapped(QThreadPool *pool, InputSequence &&sequence, MapFunctor &&map)
typename MapResult< T, MapFunctor >::Type MapResultType
def OutputSequence(toptions)
def InputSequence(toptions)
GLuint GLuint end
QtPrivate::QRegularExpressionMatchIteratorRangeBasedForIterator begin(const QRegularExpressionMatchIterator &iterator)
QFuture< void > future
[5]
QThreadPool pool