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