summaryrefslogtreecommitdiffstats
path: root/src/concurrent/qtconcurrentmap.h
diff options
context:
space:
mode:
authorSona Kurazyan <sona.kurazyan@qt.io>2021-07-10 20:57:03 +0200
committerSona Kurazyan <sona.kurazyan@qt.io>2021-07-21 09:46:33 +0200
commit6ebe3d0f0806069f906522dfe9b81baa3f3478de (patch)
treeabf147001a9018a6f85d86a50c36a4f27f6c3eb7 /src/concurrent/qtconcurrentmap.h
parent1dcfb09c5bf431bf8b065ac038bd1fc618a68f96 (diff)
Fix QtConcurrent to properly work with functors
QtConcurrent reduce functions were requiring to explicitly pass the the result type when passing functors as reductor. This was because of inability to deduce the result type from the functors. The result type of the QtConcurrent reduce functions should match with the type of the fist argument of the operator() when a functor is passed. Reused the ArgResolver type trait (already used for QFuture and QtConcurrent::run) to find out the result type in that case. Task-number: QTBUG-88448 Change-Id: Ief0eeee197df8cb9c30f3403d71978f36e4fb0f2 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/concurrent/qtconcurrentmap.h')
-rw-r--r--src/concurrent/qtconcurrentmap.h69
1 files changed, 30 insertions, 39 deletions
diff --git a/src/concurrent/qtconcurrentmap.h b/src/concurrent/qtconcurrentmap.h
index 4043ecd8a2..44a6caea4c 100644
--- a/src/concurrent/qtconcurrentmap.h
+++ b/src/concurrent/qtconcurrentmap.h
@@ -151,8 +151,8 @@ QFuture<ResultType> mappedReduced(Sequence &&sequence,
}
template <typename Sequence, typename MapFunctor, typename ReduceFunctor,
- typename ResultType =
- typename QtPrivate::ReduceResultType<std::decay_t<ReduceFunctor>>::ResultType>
+ std::enable_if_t<QtPrivate::isInvocable<MapFunctor, Sequence>::value, int> = 0,
+ typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type>
QFuture<ResultType> mappedReduced(QThreadPool *pool,
Sequence &&sequence,
MapFunctor &&map,
@@ -166,8 +166,8 @@ QFuture<ResultType> mappedReduced(QThreadPool *pool,
}
template <typename Sequence, typename MapFunctor, typename ReduceFunctor,
- typename ResultType =
- typename QtPrivate::ReduceResultType<std::decay_t<ReduceFunctor>>::ResultType>
+ std::enable_if_t<QtPrivate::isInvocable<MapFunctor, Sequence>::value, int> = 0,
+ typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type>
QFuture<ResultType> mappedReduced(Sequence &&sequence,
MapFunctor &&map,
ReduceFunctor &&reduce,
@@ -183,10 +183,9 @@ QFuture<ResultType> mappedReduced(Sequence &&sequence,
template <typename Sequence, typename MapFunctor, typename ReduceFunctor, typename ResultType,
typename InitialValueType>
#else
-template <typename Sequence, typename MapFunctor, typename ReduceFunctor,
- typename ResultType =
- typename QtPrivate::ReduceResultType<std::decay_t<ReduceFunctor>>::ResultType,
- typename InitialValueType,
+template <typename Sequence, typename MapFunctor, typename ReduceFunctor, typename InitialValueType,
+ std::enable_if_t<QtPrivate::isInvocable<MapFunctor, Sequence>::value, int> = 0,
+ typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type,
std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0>
#endif
QFuture<ResultType> mappedReduced(QThreadPool *pool,
@@ -207,10 +206,9 @@ QFuture<ResultType> mappedReduced(QThreadPool *pool,
template <typename Sequence, typename MapFunctor, typename ReduceFunctor, typename ResultType,
typename InitialValueType>
#else
-template <typename Sequence, typename MapFunctor, typename ReduceFunctor,
- typename ResultType =
- typename QtPrivate::ReduceResultType<std::decay_t<ReduceFunctor>>::ResultType,
- typename InitialValueType,
+template <typename Sequence, typename MapFunctor, typename ReduceFunctor, typename InitialValueType,
+ std::enable_if_t<QtPrivate::isInvocable<MapFunctor, Sequence>::value, int> = 0,
+ typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type,
std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0>
#endif
QFuture<ResultType> mappedReduced(Sequence &&sequence,
@@ -299,8 +297,7 @@ QFuture<ResultType> mappedReduced(Iterator begin,
}
template <typename Iterator, typename MapFunctor, typename ReduceFunctor,
- typename ResultType =
- typename QtPrivate::ReduceResultType<std::decay_t<ReduceFunctor>>::ResultType>
+ typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type>
QFuture<ResultType> mappedReduced(QThreadPool *pool,
Iterator begin,
Iterator end,
@@ -315,7 +312,7 @@ QFuture<ResultType> mappedReduced(QThreadPool *pool,
}
template <typename Iterator, typename MapFunctor, typename ReduceFunctor,
- typename ResultType = typename QtPrivate::ReduceResultType<std::decay_t<ReduceFunctor>>::ResultType>
+ typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type>
QFuture<ResultType> mappedReduced(Iterator begin,
Iterator end,
MapFunctor &&map,
@@ -333,8 +330,7 @@ template <typename Iterator, typename MapFunctor, typename ReduceFunctor, typena
typename InitialValueType>
#else
template <typename Iterator, typename MapFunctor, typename ReduceFunctor,
- typename ResultType =
- typename QtPrivate::ReduceResultType<std::decay_t<ReduceFunctor>>::ResultType,
+ typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type,
typename InitialValueType,
std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0>
#endif
@@ -357,8 +353,8 @@ template <typename Iterator, typename MapFunctor, typename ReduceFunctor, typena
typename InitialValueType>
#else
template<typename Iterator, typename MapFunctor, typename ReduceFunctor,
- typename ResultType =
- typename QtPrivate::ReduceResultType<std::decay_t<ReduceFunctor>>::ResultType,
+ std::enable_if_t<QtPrivate::isIterator<Iterator>::value, int> = 0,
+ typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type,
typename InitialValueType,
std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0>
#endif
@@ -528,8 +524,8 @@ ResultType blockingMappedReduced(Sequence &&sequence,
}
template <typename MapFunctor, typename ReduceFunctor, typename Sequence,
- typename ResultType =
- typename QtPrivate::ReduceResultType<std::decay_t<ReduceFunctor>>::ResultType>
+ std::enable_if_t<QtPrivate::isInvocable<MapFunctor, Sequence>::value, int> = 0,
+ typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type>
ResultType blockingMappedReduced(QThreadPool *pool,
Sequence &&sequence,
MapFunctor &&map,
@@ -545,8 +541,8 @@ ResultType blockingMappedReduced(QThreadPool *pool,
}
template <typename MapFunctor, typename ReduceFunctor, typename Sequence,
- typename ResultType =
- typename QtPrivate::ReduceResultType<std::decay_t<ReduceFunctor>>::ResultType>
+ std::enable_if_t<QtPrivate::isInvocable<MapFunctor, Sequence>::value, int> = 0,
+ typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type>
ResultType blockingMappedReduced(Sequence &&sequence,
MapFunctor &&map,
ReduceFunctor &&reduce,
@@ -564,10 +560,9 @@ ResultType blockingMappedReduced(Sequence &&sequence,
template <typename MapFunctor, typename ReduceFunctor, typename Sequence, typename ResultType,
typename InitialValueType>
#else
-template <typename MapFunctor, typename ReduceFunctor, typename Sequence,
- typename ResultType =
- typename QtPrivate::ReduceResultType<std::decay_t<ReduceFunctor>>::ResultType,
- typename InitialValueType,
+template <typename MapFunctor, typename ReduceFunctor, typename Sequence, typename InitialValueType,
+ std::enable_if_t<QtPrivate::isInvocable<MapFunctor, Sequence>::value, int> = 0,
+ typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type,
std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0>
#endif
ResultType blockingMappedReduced(QThreadPool *pool,
@@ -589,10 +584,9 @@ ResultType blockingMappedReduced(QThreadPool *pool,
template <typename MapFunctor, typename ReduceFunctor, typename Sequence, typename ResultType,
typename InitialValueType>
#else
-template<typename MapFunctor, typename ReduceFunctor, typename Sequence,
- typename ResultType =
- typename QtPrivate::ReduceResultType<std::decay_t<ReduceFunctor>>::ResultType,
- typename InitialValueType,
+template<typename MapFunctor, typename ReduceFunctor, typename Sequence, typename InitialValueType,
+ std::enable_if_t<QtPrivate::isInvocable<MapFunctor, Sequence>::value, int> = 0,
+ typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type,
std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0>
#endif
ResultType blockingMappedReduced(Sequence &&sequence,
@@ -687,8 +681,7 @@ ResultType blockingMappedReduced(Iterator begin,
}
template <typename Iterator, typename MapFunctor, typename ReduceFunctor,
- typename ResultType =
- typename QtPrivate::ReduceResultType<std::decay_t<ReduceFunctor>>::ResultType>
+ typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type>
ResultType blockingMappedReduced(QThreadPool *pool,
Iterator begin,
Iterator end,
@@ -704,8 +697,7 @@ ResultType blockingMappedReduced(QThreadPool *pool,
}
template <typename Iterator, typename MapFunctor, typename ReduceFunctor,
- typename ResultType =
- typename QtPrivate::ReduceResultType<std::decay_t<ReduceFunctor>>::ResultType>
+ typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type>
ResultType blockingMappedReduced(Iterator begin,
Iterator end,
MapFunctor &&map,
@@ -724,8 +716,7 @@ template <typename Iterator, typename MapFunctor, typename ReduceFunctor, typena
typename InitialValueType>
#else
template <typename Iterator, typename MapFunctor, typename ReduceFunctor,
- typename ResultType =
- typename QtPrivate::ReduceResultType<std::decay_t<ReduceFunctor>>::ResultType,
+ typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type,
typename InitialValueType,
std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0>
#endif
@@ -749,8 +740,8 @@ template <typename Iterator, typename MapFunctor, typename ReduceFunctor, typena
typename InitialValueType>
#else
template <typename Iterator, typename MapFunctor, typename ReduceFunctor,
- typename ResultType =
- typename QtPrivate::ReduceResultType<std::decay_t<ReduceFunctor>>::ResultType,
+ std::enable_if_t<QtPrivate::isIterator<Iterator>::value, int> = 0,
+ typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type,
typename InitialValueType,
std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0>
#endif