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