1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QTCONCURRENT_MAP_H |
5 | #define QTCONCURRENT_MAP_H |
6 | |
7 | #if 0 |
8 | #pragma qt_class(QtConcurrentMap) |
9 | #endif |
10 | |
11 | #include <QtConcurrent/qtconcurrent_global.h> |
12 | |
13 | #if !defined(QT_NO_CONCURRENT) || defined(Q_QDOC) |
14 | |
15 | #include <QtConcurrent/qtconcurrentmapkernel.h> |
16 | #include <QtConcurrent/qtconcurrentreducekernel.h> |
17 | #include <QtConcurrent/qtconcurrentfunctionwrappers.h> |
18 | |
19 | QT_BEGIN_NAMESPACE |
20 | |
21 | |
22 | |
23 | namespace QtConcurrent { |
24 | |
25 | // map() on sequences |
26 | template <typename Sequence, typename MapFunctor> |
27 | QFuture<void> map(QThreadPool *pool, Sequence &&sequence, MapFunctor &&map) |
28 | { |
29 | return startMap(pool, sequence.begin(), sequence.end(), std::forward<MapFunctor>(map)); |
30 | } |
31 | |
32 | template <typename Sequence, typename MapFunctor> |
33 | QFuture<void> map(Sequence &&sequence, MapFunctor &&map) |
34 | { |
35 | return startMap(QThreadPool::globalInstance(), sequence.begin(), sequence.end(), |
36 | std::forward<MapFunctor>(map)); |
37 | } |
38 | |
39 | // map() on iterators |
40 | template <typename Iterator, typename MapFunctor> |
41 | QFuture<void> map(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor &&map) |
42 | { |
43 | return startMap(pool, begin, end, std::forward<MapFunctor>(map)); |
44 | } |
45 | |
46 | template <typename Iterator, typename MapFunctor> |
47 | QFuture<void> map(Iterator begin, Iterator end, MapFunctor &&map) |
48 | { |
49 | return startMap(QThreadPool::globalInstance(), begin, end, std::forward<MapFunctor>(map)); |
50 | } |
51 | |
52 | // mappedReduced() for sequences. |
53 | template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor> |
54 | QFuture<ResultType> mappedReduced(QThreadPool *pool, |
55 | Sequence &&sequence, |
56 | MapFunctor &&map, |
57 | ReduceFunctor &&reduce, |
58 | ReduceOptions options = ReduceOptions(UnorderedReduce |
59 | | SequentialReduce)) |
60 | { |
61 | return startMappedReduced<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType> |
62 | (pool, std::forward<Sequence>(sequence), std::forward<MapFunctor>(map), |
63 | std::forward<ReduceFunctor>(reduce), options); |
64 | } |
65 | |
66 | template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor> |
67 | QFuture<ResultType> mappedReduced(Sequence &&sequence, |
68 | MapFunctor &&map, |
69 | ReduceFunctor &&reduce, |
70 | ReduceOptions options = ReduceOptions(UnorderedReduce |
71 | | SequentialReduce)) |
72 | { |
73 | return startMappedReduced<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType> |
74 | (QThreadPool::globalInstance(), std::forward<Sequence>(sequence), |
75 | std::forward<MapFunctor>(map), std::forward<ReduceFunctor>(reduce), options); |
76 | } |
77 | |
78 | #ifdef Q_QDOC |
79 | template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor, |
80 | typename InitialValueType> |
81 | #else |
82 | template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor, |
83 | typename InitialValueType, |
84 | std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, |
85 | int> = 0> |
86 | #endif |
87 | QFuture<ResultType> mappedReduced(QThreadPool *pool, |
88 | Sequence &&sequence, |
89 | MapFunctor &&map, |
90 | ReduceFunctor &&reduce, |
91 | InitialValueType &&initialValue, |
92 | ReduceOptions options = ReduceOptions(UnorderedReduce |
93 | | SequentialReduce)) |
94 | { |
95 | return startMappedReduced<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>( |
96 | pool, std::forward<Sequence>(sequence), std::forward<MapFunctor>(map), |
97 | std::forward<ReduceFunctor>(reduce), |
98 | ResultType(std::forward<InitialValueType>(initialValue)), options); |
99 | } |
100 | #ifdef Q_QDOC |
101 | template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor, |
102 | typename InitialValueType> |
103 | #else |
104 | template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor, |
105 | typename InitialValueType, |
106 | std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, |
107 | int> = 0> |
108 | #endif |
109 | QFuture<ResultType> mappedReduced(Sequence &&sequence, |
110 | MapFunctor &&map, |
111 | ReduceFunctor &&reduce, |
112 | InitialValueType &&initialValue, |
113 | ReduceOptions options = ReduceOptions(UnorderedReduce |
114 | | SequentialReduce)) |
115 | { |
116 | return startMappedReduced<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType> |
117 | (QThreadPool::globalInstance(), std::forward<Sequence>(sequence), |
118 | std::forward<MapFunctor>(map), std::forward<ReduceFunctor>(reduce), |
119 | ResultType(std::forward<InitialValueType>(initialValue)), options); |
120 | } |
121 | |
122 | template <typename Sequence, typename MapFunctor, typename ReduceFunctor, |
123 | std::enable_if_t<QtPrivate::isInvocable<MapFunctor, Sequence>::value, int> = 0, |
124 | typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type> |
125 | QFuture<ResultType> mappedReduced(QThreadPool *pool, |
126 | Sequence &&sequence, |
127 | MapFunctor &&map, |
128 | ReduceFunctor &&reduce, |
129 | ReduceOptions options = ReduceOptions(UnorderedReduce |
130 | | SequentialReduce)) |
131 | { |
132 | return startMappedReduced<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType> |
133 | (pool, std::forward<Sequence>(sequence), std::forward<MapFunctor>(map), |
134 | std::forward<ReduceFunctor>(reduce), options); |
135 | } |
136 | |
137 | template <typename Sequence, typename MapFunctor, typename ReduceFunctor, |
138 | std::enable_if_t<QtPrivate::isInvocable<MapFunctor, Sequence>::value, int> = 0, |
139 | typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type> |
140 | QFuture<ResultType> mappedReduced(Sequence &&sequence, |
141 | MapFunctor &&map, |
142 | ReduceFunctor &&reduce, |
143 | ReduceOptions options = ReduceOptions(UnorderedReduce |
144 | | SequentialReduce)) |
145 | { |
146 | return startMappedReduced<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType> |
147 | (QThreadPool::globalInstance(), std::forward<Sequence>(sequence), |
148 | std::forward<MapFunctor>(map), std::forward<ReduceFunctor>(reduce), options); |
149 | } |
150 | |
151 | #ifdef Q_QDOC |
152 | template <typename Sequence, typename MapFunctor, typename ReduceFunctor, typename ResultType, |
153 | typename InitialValueType> |
154 | #else |
155 | template <typename Sequence, typename MapFunctor, typename ReduceFunctor, typename InitialValueType, |
156 | std::enable_if_t<QtPrivate::isInvocable<MapFunctor, Sequence>::value, int> = 0, |
157 | typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type, |
158 | std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, |
159 | int> = 0> |
160 | #endif |
161 | QFuture<ResultType> mappedReduced(QThreadPool *pool, |
162 | Sequence &&sequence, |
163 | MapFunctor &&map, |
164 | ReduceFunctor &&reduce, |
165 | InitialValueType &&initialValue, |
166 | ReduceOptions options = ReduceOptions(UnorderedReduce |
167 | | SequentialReduce)) |
168 | { |
169 | return startMappedReduced<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>( |
170 | pool, std::forward<Sequence>(sequence), std::forward<MapFunctor>(map), |
171 | std::forward<ReduceFunctor>(reduce), |
172 | ResultType(std::forward<InitialValueType>(initialValue)), options); |
173 | } |
174 | |
175 | #ifdef Q_QDOC |
176 | template <typename Sequence, typename MapFunctor, typename ReduceFunctor, typename ResultType, |
177 | typename InitialValueType> |
178 | #else |
179 | template <typename Sequence, typename MapFunctor, typename ReduceFunctor, typename InitialValueType, |
180 | std::enable_if_t<QtPrivate::isInvocable<MapFunctor, Sequence>::value, int> = 0, |
181 | typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type, |
182 | std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, |
183 | int> = 0> |
184 | #endif |
185 | QFuture<ResultType> mappedReduced(Sequence &&sequence, |
186 | MapFunctor &&map, |
187 | ReduceFunctor &&reduce, |
188 | InitialValueType &&initialValue, |
189 | ReduceOptions options = ReduceOptions(UnorderedReduce |
190 | | SequentialReduce)) |
191 | { |
192 | return startMappedReduced<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType> |
193 | (QThreadPool::globalInstance(), std::forward<Sequence>(sequence), |
194 | std::forward<MapFunctor>(map), std::forward<ReduceFunctor>(reduce), |
195 | ResultType(std::forward<InitialValueType>(initialValue)), options); |
196 | } |
197 | |
198 | // mappedReduced() for iterators |
199 | template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor> |
200 | QFuture<ResultType> mappedReduced(QThreadPool *pool, |
201 | Iterator begin, |
202 | Iterator end, |
203 | MapFunctor &&map, |
204 | ReduceFunctor &&reduce, |
205 | ReduceOptions options = ReduceOptions(UnorderedReduce |
206 | | SequentialReduce)) |
207 | { |
208 | return startMappedReduced<QtPrivate::MapResultType<Iterator, MapFunctor>, ResultType> |
209 | (pool, begin, end, std::forward<MapFunctor>(map), std::forward<ReduceFunctor>(reduce), |
210 | options); |
211 | } |
212 | |
213 | template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor> |
214 | QFuture<ResultType> mappedReduced(Iterator begin, |
215 | Iterator end, |
216 | MapFunctor &&map, |
217 | ReduceFunctor &&reduce, |
218 | ReduceOptions options = ReduceOptions(UnorderedReduce |
219 | | SequentialReduce)) |
220 | { |
221 | return startMappedReduced<QtPrivate::MapResultType<Iterator, MapFunctor>, ResultType> |
222 | (QThreadPool::globalInstance(), begin, end, std::forward<MapFunctor>(map), |
223 | std::forward<ReduceFunctor>(reduce), options); |
224 | } |
225 | |
226 | #ifdef Q_QDOC |
227 | template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor, |
228 | typename InitialValueType> |
229 | #else |
230 | template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor, |
231 | typename InitialValueType, |
232 | std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, |
233 | int> = 0> |
234 | #endif |
235 | QFuture<ResultType> mappedReduced(QThreadPool *pool, |
236 | Iterator begin, |
237 | Iterator end, |
238 | MapFunctor &&map, |
239 | ReduceFunctor &&reduce, |
240 | InitialValueType &&initialValue, |
241 | ReduceOptions options = ReduceOptions(UnorderedReduce |
242 | | SequentialReduce)) |
243 | { |
244 | return startMappedReduced<QtPrivate::MapResultType<Iterator, MapFunctor>, ResultType> |
245 | (pool, begin, end, std::forward<MapFunctor>(map), std::forward<ReduceFunctor>(reduce), |
246 | ResultType(std::forward<InitialValueType>(initialValue)), options); |
247 | } |
248 | |
249 | #ifdef Q_QDOC |
250 | template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor, |
251 | typename InitialValueType> |
252 | #else |
253 | template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor, |
254 | typename InitialValueType, |
255 | std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, |
256 | int> = 0> |
257 | #endif |
258 | QFuture<ResultType> mappedReduced(Iterator begin, |
259 | Iterator end, |
260 | MapFunctor &&map, |
261 | ReduceFunctor &&reduce, |
262 | InitialValueType &&initialValue, |
263 | ReduceOptions options = ReduceOptions(UnorderedReduce |
264 | | SequentialReduce)) |
265 | { |
266 | return startMappedReduced<QtPrivate::MapResultType<Iterator, MapFunctor>, ResultType> |
267 | (QThreadPool::globalInstance(), begin, end, std::forward<MapFunctor>(map), |
268 | std::forward<ReduceFunctor>(reduce), |
269 | ResultType(std::forward<InitialValueType>(initialValue)), options); |
270 | } |
271 | |
272 | template <typename Iterator, typename MapFunctor, typename ReduceFunctor, |
273 | typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type> |
274 | QFuture<ResultType> mappedReduced(QThreadPool *pool, |
275 | Iterator begin, |
276 | Iterator end, |
277 | MapFunctor &&map, |
278 | ReduceFunctor &&reduce, |
279 | ReduceOptions options = ReduceOptions(UnorderedReduce |
280 | | SequentialReduce)) |
281 | { |
282 | return startMappedReduced<QtPrivate::MapResultType<Iterator, MapFunctor>, ResultType>( |
283 | pool, begin, end, std::forward<MapFunctor>(map), std::forward<ReduceFunctor>(reduce), |
284 | options); |
285 | } |
286 | |
287 | template <typename Iterator, typename MapFunctor, typename ReduceFunctor, |
288 | typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type> |
289 | QFuture<ResultType> mappedReduced(Iterator begin, |
290 | Iterator end, |
291 | MapFunctor &&map, |
292 | ReduceFunctor &&reduce, |
293 | ReduceOptions options = ReduceOptions(UnorderedReduce |
294 | | SequentialReduce)) |
295 | { |
296 | return startMappedReduced<QtPrivate::MapResultType<Iterator, MapFunctor>, ResultType> |
297 | (QThreadPool::globalInstance(), begin, end, std::forward<MapFunctor>(map), |
298 | std::forward<ReduceFunctor>(reduce), options); |
299 | } |
300 | |
301 | #ifdef Q_QDOC |
302 | template <typename Iterator, typename MapFunctor, typename ReduceFunctor, typename ResultType, |
303 | typename InitialValueType> |
304 | #else |
305 | template <typename Iterator, typename MapFunctor, typename ReduceFunctor, |
306 | typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type, |
307 | typename InitialValueType, |
308 | std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, |
309 | int> = 0> |
310 | #endif |
311 | QFuture<ResultType> mappedReduced(QThreadPool *pool, |
312 | Iterator begin, |
313 | Iterator end, |
314 | MapFunctor &&map, |
315 | ReduceFunctor &&reduce, |
316 | InitialValueType &&initialValue, |
317 | ReduceOptions options = ReduceOptions(UnorderedReduce |
318 | | SequentialReduce)) |
319 | { |
320 | return startMappedReduced<QtPrivate::MapResultType<Iterator, MapFunctor>, ResultType> |
321 | (pool, begin, end, std::forward<MapFunctor>(map), std::forward<ReduceFunctor>(reduce), |
322 | ResultType(std::forward<InitialValueType>(initialValue)), options); |
323 | } |
324 | |
325 | #ifdef Q_QDOC |
326 | template <typename Iterator, typename MapFunctor, typename ReduceFunctor, typename ResultType, |
327 | typename InitialValueType> |
328 | #else |
329 | template<typename Iterator, typename MapFunctor, typename ReduceFunctor, |
330 | std::enable_if_t<QtPrivate::isIterator_v<Iterator>, int> = 0, |
331 | typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type, |
332 | typename InitialValueType, |
333 | std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, |
334 | int> = 0> |
335 | #endif |
336 | QFuture<ResultType> mappedReduced(Iterator begin, |
337 | Iterator end, |
338 | MapFunctor &&map, |
339 | ReduceFunctor &&reduce, |
340 | InitialValueType &&initialValue, |
341 | ReduceOptions options = ReduceOptions(UnorderedReduce |
342 | | SequentialReduce)) |
343 | { |
344 | return startMappedReduced<QtPrivate::MapResultType<Iterator, MapFunctor>, ResultType> |
345 | (QThreadPool::globalInstance(), begin, end, std::forward<MapFunctor>(map), |
346 | std::forward<ReduceFunctor>(reduce), |
347 | ResultType(std::forward<InitialValueType>(initialValue)), options); |
348 | } |
349 | |
350 | // mapped() for sequences |
351 | template <typename Sequence, typename MapFunctor> |
352 | QFuture<QtPrivate::MapResultType<Sequence, MapFunctor>> mapped( |
353 | QThreadPool *pool, |
354 | Sequence &&sequence, |
355 | MapFunctor &&map) |
356 | { |
357 | return startMapped<QtPrivate::MapResultType<Sequence, MapFunctor>>( |
358 | pool, std::forward<Sequence>(sequence), std::forward<MapFunctor>(map)); |
359 | } |
360 | |
361 | template <typename Sequence, typename MapFunctor> |
362 | QFuture<QtPrivate::MapResultType<Sequence, MapFunctor>> mapped( |
363 | Sequence &&sequence, |
364 | MapFunctor &&map) |
365 | { |
366 | return startMapped<QtPrivate::MapResultType<Sequence, MapFunctor>> |
367 | (QThreadPool::globalInstance(), std::forward<Sequence>(sequence), |
368 | std::forward<MapFunctor>(map)); |
369 | } |
370 | |
371 | // mapped() for iterator ranges. |
372 | template <typename Iterator, typename MapFunctor> |
373 | QFuture<QtPrivate::MapResultType<Iterator, MapFunctor>> mapped( |
374 | QThreadPool *pool, |
375 | Iterator begin, |
376 | Iterator end, |
377 | MapFunctor &&map) |
378 | { |
379 | return startMapped<QtPrivate::MapResultType<Iterator, MapFunctor>>( |
380 | pool, begin, end, std::forward<MapFunctor>(map)); |
381 | } |
382 | |
383 | template <typename Iterator, typename MapFunctor> |
384 | QFuture<QtPrivate::MapResultType<Iterator, MapFunctor>> mapped( |
385 | Iterator begin, |
386 | Iterator end, |
387 | MapFunctor &&map) |
388 | { |
389 | return startMapped<QtPrivate::MapResultType<Iterator, MapFunctor>> |
390 | (QThreadPool::globalInstance(), begin, end, std::forward<MapFunctor>(map)); |
391 | } |
392 | |
393 | // blockingMap() for sequences |
394 | template <typename Sequence, typename MapFunctor> |
395 | void blockingMap(QThreadPool *pool, Sequence &&sequence, MapFunctor map) |
396 | { |
397 | QFuture<void> future = |
398 | startMap(pool, sequence.begin(), sequence.end(), std::forward<MapFunctor>(map)); |
399 | future.waitForFinished(); |
400 | } |
401 | |
402 | template <typename Sequence, typename MapFunctor> |
403 | void blockingMap(Sequence &&sequence, MapFunctor &&map) |
404 | { |
405 | QFuture<void> future = startMap(QThreadPool::globalInstance(), sequence.begin(), sequence.end(), |
406 | std::forward<MapFunctor>(map)); |
407 | future.waitForFinished(); |
408 | } |
409 | |
410 | // blockingMap() for iterator ranges |
411 | template <typename Iterator, typename MapFunctor> |
412 | void blockingMap(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor &&map) |
413 | { |
414 | QFuture<void> future = startMap(pool, begin, end, map); |
415 | future.waitForFinished(); |
416 | } |
417 | |
418 | template <typename Iterator, typename MapFunctor> |
419 | void blockingMap(Iterator begin, Iterator end, MapFunctor &&map) |
420 | { |
421 | QFuture<void> future = startMap(QThreadPool::globalInstance(), begin, end, |
422 | std::forward<MapFunctor>(map)); |
423 | future.waitForFinished(); |
424 | } |
425 | |
426 | // blockingMappedReduced() for sequences |
427 | template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor> |
428 | ResultType blockingMappedReduced(QThreadPool *pool, |
429 | Sequence &&sequence, |
430 | MapFunctor &&map, |
431 | ReduceFunctor &&reduce, |
432 | ReduceOptions options = ReduceOptions(UnorderedReduce |
433 | | SequentialReduce)) |
434 | { |
435 | QFuture<ResultType> future = |
436 | mappedReduced<ResultType>(pool, std::forward<Sequence>(sequence), |
437 | std::forward<MapFunctor>(map), |
438 | std::forward<ReduceFunctor>(reduce), options); |
439 | return future.takeResult(); |
440 | } |
441 | |
442 | template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor> |
443 | ResultType blockingMappedReduced(Sequence &&sequence, |
444 | MapFunctor &&map, |
445 | ReduceFunctor &&reduce, |
446 | ReduceOptions options = ReduceOptions(UnorderedReduce |
447 | | SequentialReduce)) |
448 | { |
449 | QFuture<ResultType> future = |
450 | mappedReduced<ResultType>(std::forward<Sequence>(sequence), |
451 | std::forward<MapFunctor>(map), |
452 | std::forward<ReduceFunctor>(reduce), options); |
453 | return future.takeResult(); |
454 | } |
455 | |
456 | #ifdef Q_QDOC |
457 | template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor, |
458 | typename InitialValueType> |
459 | #else |
460 | template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor, |
461 | typename InitialValueType, |
462 | std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, |
463 | int> = 0> |
464 | #endif |
465 | ResultType blockingMappedReduced(QThreadPool *pool, |
466 | Sequence &&sequence, |
467 | MapFunctor &&map, |
468 | ReduceFunctor &&reduce, |
469 | InitialValueType &&initialValue, |
470 | ReduceOptions options = ReduceOptions(UnorderedReduce |
471 | | SequentialReduce)) |
472 | { |
473 | QFuture<ResultType> future = mappedReduced<ResultType>( |
474 | pool, std::forward<Sequence>(sequence), std::forward<MapFunctor>(map), |
475 | std::forward<ReduceFunctor>(reduce), |
476 | ResultType(std::forward<InitialValueType>(initialValue)), options); |
477 | return future.takeResult(); |
478 | } |
479 | |
480 | #ifdef Q_QDOC |
481 | template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor, |
482 | typename InitialValueType> |
483 | #else |
484 | template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor, |
485 | typename InitialValueType, |
486 | std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, |
487 | int> = 0> |
488 | #endif |
489 | ResultType blockingMappedReduced(Sequence &&sequence, |
490 | MapFunctor &&map, |
491 | ReduceFunctor &&reduce, |
492 | InitialValueType &&initialValue, |
493 | ReduceOptions options = ReduceOptions(UnorderedReduce |
494 | | SequentialReduce)) |
495 | { |
496 | QFuture<ResultType> future = mappedReduced<ResultType>( |
497 | std::forward<Sequence>(sequence), std::forward<MapFunctor>(map), |
498 | std::forward<ReduceFunctor>(reduce), |
499 | ResultType(std::forward<InitialValueType>(initialValue)), options); |
500 | return future.takeResult(); |
501 | } |
502 | |
503 | template <typename MapFunctor, typename ReduceFunctor, typename Sequence, |
504 | std::enable_if_t<QtPrivate::isInvocable<MapFunctor, Sequence>::value, int> = 0, |
505 | typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type> |
506 | ResultType blockingMappedReduced(QThreadPool *pool, |
507 | Sequence &&sequence, |
508 | MapFunctor &&map, |
509 | ReduceFunctor &&reduce, |
510 | ReduceOptions options = ReduceOptions(UnorderedReduce |
511 | | SequentialReduce)) |
512 | { |
513 | QFuture<ResultType> future = |
514 | mappedReduced<ResultType>(pool, std::forward<Sequence>(sequence), |
515 | std::forward<MapFunctor>(map), |
516 | std::forward<ReduceFunctor>(reduce), options); |
517 | return future.takeResult(); |
518 | } |
519 | |
520 | template <typename MapFunctor, typename ReduceFunctor, typename Sequence, |
521 | std::enable_if_t<QtPrivate::isInvocable<MapFunctor, Sequence>::value, int> = 0, |
522 | typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type> |
523 | ResultType blockingMappedReduced(Sequence &&sequence, |
524 | MapFunctor &&map, |
525 | ReduceFunctor &&reduce, |
526 | ReduceOptions options = ReduceOptions(UnorderedReduce |
527 | | SequentialReduce)) |
528 | { |
529 | QFuture<ResultType> future = |
530 | mappedReduced<ResultType>(std::forward<Sequence>(sequence), |
531 | std::forward<MapFunctor>(map), |
532 | std::forward<ReduceFunctor>(reduce), options); |
533 | return future.takeResult(); |
534 | } |
535 | |
536 | #ifdef Q_QDOC |
537 | template <typename MapFunctor, typename ReduceFunctor, typename Sequence, typename ResultType, |
538 | typename InitialValueType> |
539 | #else |
540 | template <typename MapFunctor, typename ReduceFunctor, typename Sequence, typename InitialValueType, |
541 | std::enable_if_t<QtPrivate::isInvocable<MapFunctor, Sequence>::value, int> = 0, |
542 | typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type, |
543 | std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, |
544 | int> = 0> |
545 | #endif |
546 | ResultType blockingMappedReduced(QThreadPool *pool, |
547 | Sequence &&sequence, |
548 | MapFunctor &&map, |
549 | ReduceFunctor &&reduce, |
550 | InitialValueType &&initialValue, |
551 | ReduceOptions options = ReduceOptions(UnorderedReduce |
552 | | SequentialReduce)) |
553 | { |
554 | QFuture<ResultType> future = mappedReduced<ResultType>( |
555 | pool, std::forward<Sequence>(sequence), std::forward<MapFunctor>(map), |
556 | std::forward<ReduceFunctor>(reduce), |
557 | ResultType(std::forward<InitialValueType>(initialValue)), options); |
558 | return future.takeResult(); |
559 | } |
560 | |
561 | #ifdef Q_QDOC |
562 | template <typename MapFunctor, typename ReduceFunctor, typename Sequence, typename ResultType, |
563 | typename InitialValueType> |
564 | #else |
565 | template<typename MapFunctor, typename ReduceFunctor, typename Sequence, typename InitialValueType, |
566 | std::enable_if_t<QtPrivate::isInvocable<MapFunctor, Sequence>::value, int> = 0, |
567 | typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type, |
568 | std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, |
569 | int> = 0> |
570 | #endif |
571 | ResultType blockingMappedReduced(Sequence &&sequence, |
572 | MapFunctor &&map, |
573 | ReduceFunctor &&reduce, |
574 | InitialValueType &&initialValue, |
575 | ReduceOptions options = ReduceOptions(UnorderedReduce |
576 | | SequentialReduce)) |
577 | { |
578 | QFuture<ResultType> future = mappedReduced<ResultType>( |
579 | std::forward<Sequence>(sequence), std::forward<MapFunctor>(map), |
580 | std::forward<ReduceFunctor>(reduce), |
581 | ResultType(std::forward<InitialValueType>(initialValue)), options); |
582 | return future.takeResult(); |
583 | } |
584 | |
585 | // blockingMappedReduced() for iterator ranges |
586 | template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor> |
587 | ResultType blockingMappedReduced(QThreadPool *pool, |
588 | Iterator begin, |
589 | Iterator end, |
590 | MapFunctor &&map, |
591 | ReduceFunctor &&reduce, |
592 | ReduceOptions options = ReduceOptions(UnorderedReduce |
593 | | SequentialReduce)) |
594 | { |
595 | QFuture<ResultType> future = |
596 | mappedReduced<ResultType>(pool, begin, end, std::forward<MapFunctor>(map), |
597 | std::forward<ReduceFunctor>(reduce), options); |
598 | return future.takeResult(); |
599 | } |
600 | |
601 | template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor> |
602 | ResultType blockingMappedReduced(Iterator begin, |
603 | Iterator end, |
604 | MapFunctor &&map, |
605 | ReduceFunctor &&reduce, |
606 | ReduceOptions options = ReduceOptions(UnorderedReduce |
607 | | SequentialReduce)) |
608 | { |
609 | QFuture<ResultType> future = |
610 | mappedReduced<ResultType>(begin, end, std::forward<MapFunctor>(map), |
611 | std::forward<ReduceFunctor>(reduce), options); |
612 | return future.takeResult(); |
613 | } |
614 | |
615 | #ifdef Q_QDOC |
616 | template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor, |
617 | typename InitialValueType> |
618 | #else |
619 | template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor, |
620 | typename InitialValueType, |
621 | std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, |
622 | int> = 0> |
623 | #endif |
624 | ResultType blockingMappedReduced(QThreadPool *pool, |
625 | Iterator begin, |
626 | Iterator end, |
627 | MapFunctor &&map, |
628 | ReduceFunctor &&reduce, |
629 | InitialValueType &&initialValue, |
630 | ReduceOptions options = ReduceOptions(UnorderedReduce |
631 | | SequentialReduce)) |
632 | { |
633 | QFuture<ResultType> future = mappedReduced<ResultType>( |
634 | pool, begin, end, std::forward<MapFunctor>(map), std::forward<ReduceFunctor>(reduce), |
635 | ResultType(std::forward<InitialValueType>(initialValue)), |
636 | options); |
637 | return future.takeResult(); |
638 | } |
639 | |
640 | #ifdef Q_QDOC |
641 | template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor, |
642 | typename InitialValueType> |
643 | #else |
644 | template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor, |
645 | typename InitialValueType, |
646 | std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, |
647 | int> = 0> |
648 | #endif |
649 | ResultType blockingMappedReduced(Iterator begin, |
650 | Iterator end, |
651 | MapFunctor &&map, |
652 | ReduceFunctor &&reduce, |
653 | InitialValueType &&initialValue, |
654 | ReduceOptions options = ReduceOptions(UnorderedReduce |
655 | | SequentialReduce)) |
656 | { |
657 | QFuture<ResultType> future = mappedReduced<ResultType>( |
658 | begin, end, std::forward<MapFunctor>(map), std::forward<ReduceFunctor>(reduce), |
659 | ResultType(std::forward<InitialValueType>(initialValue)), |
660 | options); |
661 | return future.takeResult(); |
662 | } |
663 | |
664 | template <typename Iterator, typename MapFunctor, typename ReduceFunctor, |
665 | typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type> |
666 | ResultType blockingMappedReduced(QThreadPool *pool, |
667 | Iterator begin, |
668 | Iterator end, |
669 | MapFunctor &&map, |
670 | ReduceFunctor &&reduce, |
671 | ReduceOptions options = ReduceOptions(UnorderedReduce |
672 | | SequentialReduce)) |
673 | { |
674 | QFuture<ResultType> future = |
675 | mappedReduced<ResultType>(pool, begin, end, std::forward<MapFunctor>(map), |
676 | std::forward<ReduceFunctor>(reduce), options); |
677 | return future.takeResult(); |
678 | } |
679 | |
680 | template <typename Iterator, typename MapFunctor, typename ReduceFunctor, |
681 | typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type> |
682 | ResultType blockingMappedReduced(Iterator begin, |
683 | Iterator end, |
684 | MapFunctor &&map, |
685 | ReduceFunctor &&reduce, |
686 | ReduceOptions options = ReduceOptions(UnorderedReduce |
687 | | SequentialReduce)) |
688 | { |
689 | QFuture<ResultType> future = |
690 | mappedReduced<ResultType>(begin, end, std::forward<MapFunctor>(map), |
691 | std::forward<ReduceFunctor>(reduce), options); |
692 | return future.takeResult(); |
693 | } |
694 | |
695 | #ifdef Q_QDOC |
696 | template <typename Iterator, typename MapFunctor, typename ReduceFunctor, typename ResultType, |
697 | typename InitialValueType> |
698 | #else |
699 | template <typename Iterator, typename MapFunctor, typename ReduceFunctor, |
700 | typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type, |
701 | typename InitialValueType, |
702 | std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, |
703 | int> = 0> |
704 | #endif |
705 | ResultType blockingMappedReduced(QThreadPool *pool, |
706 | Iterator begin, |
707 | Iterator end, |
708 | MapFunctor &&map, |
709 | ReduceFunctor &&reduce, |
710 | InitialValueType &&initialValue, |
711 | ReduceOptions options = ReduceOptions(UnorderedReduce |
712 | | SequentialReduce)) |
713 | { |
714 | QFuture<ResultType> future = mappedReduced<ResultType>( |
715 | pool, begin, end, std::forward<MapFunctor>(map), std::forward<ReduceFunctor>(reduce), |
716 | ResultType(std::forward<InitialValueType>(initialValue)), options); |
717 | return future.takeResult(); |
718 | } |
719 | |
720 | #ifdef Q_QDOC |
721 | template <typename Iterator, typename MapFunctor, typename ReduceFunctor, typename ResultType, |
722 | typename InitialValueType> |
723 | #else |
724 | template <typename Iterator, typename MapFunctor, typename ReduceFunctor, |
725 | std::enable_if_t<QtPrivate::isIterator_v<Iterator>, int> = 0, |
726 | typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type, |
727 | typename InitialValueType, |
728 | std::enable_if_t<QtPrivate::isInitialValueCompatible_v<InitialValueType, ResultType>, |
729 | int> = 0> |
730 | #endif |
731 | ResultType blockingMappedReduced(Iterator begin, |
732 | Iterator end, |
733 | MapFunctor &&map, |
734 | ReduceFunctor &&reduce, |
735 | InitialValueType &&initialValue, |
736 | ReduceOptions options = ReduceOptions(UnorderedReduce |
737 | | SequentialReduce)) |
738 | { |
739 | QFuture<ResultType> future = mappedReduced<ResultType>( |
740 | begin, end, std::forward<MapFunctor>(map), std::forward<ReduceFunctor>(reduce), |
741 | ResultType(std::forward<InitialValueType>(initialValue)), options); |
742 | return future.takeResult(); |
743 | } |
744 | |
745 | // mapped() for sequences with a different putput sequence type. |
746 | template <typename OutputSequence, typename InputSequence, typename MapFunctor> |
747 | OutputSequence blockingMapped(QThreadPool *pool, InputSequence &&sequence, MapFunctor &&map) |
748 | { |
749 | return blockingMappedReduced<OutputSequence>(pool, std::forward<InputSequence>(sequence), |
750 | std::forward<MapFunctor>(map), |
751 | QtPrivate::PushBackWrapper(), OrderedReduce); |
752 | } |
753 | |
754 | template <typename OutputSequence, typename InputSequence, typename MapFunctor> |
755 | OutputSequence blockingMapped(InputSequence &&sequence, MapFunctor &&map) |
756 | { |
757 | return blockingMappedReduced<OutputSequence>( |
758 | QThreadPool::globalInstance(), std::forward<InputSequence>(sequence), |
759 | std::forward<MapFunctor>(map), QtPrivate::PushBackWrapper(), OrderedReduce); |
760 | } |
761 | |
762 | template <typename MapFunctor, typename InputSequence> |
763 | auto blockingMapped(QThreadPool *pool, InputSequence &&sequence, MapFunctor &&map) |
764 | { |
765 | using OutputSequence = typename QtPrivate::MapSequenceResultType<std::decay_t<InputSequence>, |
766 | MapFunctor>::ResultType; |
767 | return blockingMappedReduced<OutputSequence>(pool, std::forward<InputSequence>(sequence), |
768 | std::forward<MapFunctor>(map), |
769 | QtPrivate::PushBackWrapper(), OrderedReduce); |
770 | } |
771 | |
772 | template <typename MapFunctor, typename InputSequence> |
773 | auto blockingMapped(InputSequence &&sequence, MapFunctor &&map) |
774 | { |
775 | using OutputSequence = typename QtPrivate::MapSequenceResultType<std::decay_t<InputSequence>, |
776 | MapFunctor>::ResultType; |
777 | return blockingMappedReduced<OutputSequence>(QThreadPool::globalInstance(), |
778 | std::forward<InputSequence>(sequence), |
779 | std::forward<MapFunctor>(map), |
780 | QtPrivate::PushBackWrapper(), OrderedReduce); |
781 | } |
782 | |
783 | // mapped() for iterator ranges |
784 | template <typename Sequence, typename Iterator, typename MapFunctor> |
785 | Sequence blockingMapped(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor &&map) |
786 | { |
787 | return blockingMappedReduced<Sequence>(pool, begin, end, std::forward<MapFunctor>(map), |
788 | QtPrivate::PushBackWrapper(), OrderedReduce); |
789 | } |
790 | |
791 | template <typename Sequence, typename Iterator, typename MapFunctor> |
792 | Sequence blockingMapped(Iterator begin, Iterator end, MapFunctor &&map) |
793 | { |
794 | return blockingMappedReduced<Sequence>(QThreadPool::globalInstance(), begin, end, |
795 | std::forward<MapFunctor>(map), |
796 | QtPrivate::PushBackWrapper(), OrderedReduce); |
797 | } |
798 | |
799 | template <typename Iterator, typename MapFunctor> |
800 | auto blockingMapped(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor &&map) |
801 | { |
802 | using OutputSequence = QtPrivate::MapResultType<Iterator, MapFunctor>; |
803 | return blockingMappedReduced<OutputSequence>(pool, begin, end, std::forward<MapFunctor>(map), |
804 | QtPrivate::PushBackWrapper(), OrderedReduce); |
805 | } |
806 | |
807 | template <typename Iterator, typename MapFunctor> |
808 | auto blockingMapped(Iterator begin, Iterator end, MapFunctor &&map) |
809 | { |
810 | using OutputSequence = QtPrivate::MapResultType<Iterator, MapFunctor>; |
811 | return blockingMappedReduced<OutputSequence>(QThreadPool::globalInstance(), begin, end, |
812 | std::forward<MapFunctor>(map), |
813 | QtPrivate::PushBackWrapper(), OrderedReduce); |
814 | } |
815 | |
816 | } // namespace QtConcurrent |
817 | |
818 | |
819 | QT_END_NAMESPACE |
820 | |
821 | #endif // QT_NO_CONCURRENT |
822 | |
823 | #endif |
824 | |