QtConcurrent: use variable templates for compile-time checks

Noticed during the API review.

Pick-to: 6.3 6.2
Task-number: QTBUG-99883
Change-Id: I19571343a0cf0609beae2422ef1f69f7a34eb9ac
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
Sona Kurazyan 2022-01-20 14:02:34 +01:00
parent d99714e316
commit 7f318327e5
3 changed files with 10 additions and 17 deletions

View File

@ -333,7 +333,7 @@ QFuture<ResultType> filteredReduced(QThreadPool *pool,
}
template <typename Iterator, typename KeepFunctor, typename ReduceFunctor,
std::enable_if_t<QtPrivate::isIterator<Iterator>::value, int> = 0,
std::enable_if_t<QtPrivate::isIterator_v<Iterator>, int> = 0,
typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type,
typename InitialValueType,
std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0>
@ -673,7 +673,7 @@ ResultType blockingFilteredReduced(QThreadPool *pool,
}
template <typename Iterator, typename KeepFunctor, typename ReduceFunctor,
std::enable_if_t<QtPrivate::isIterator<Iterator>::value, int> = 0,
std::enable_if_t<QtPrivate::isIterator_v<Iterator>, int> = 0,
typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type,
typename InitialValueType,
std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0>

View File

@ -142,24 +142,17 @@ struct ReduceResultType<T(C::*)(U) noexcept>
};
template<class T, class Enable = void>
struct hasCallOperator : std::false_type
{
};
inline constexpr bool hasCallOperator_v = false;
template<class T>
struct hasCallOperator<T, std::void_t<decltype(&T::operator())>> : std::true_type
{
};
inline constexpr bool hasCallOperator_v<T, std::void_t<decltype(&T::operator())>> = true;
template<class T, class Enable = void>
struct isIterator : std::false_type
{
};
inline constexpr bool isIterator_v = false;
template<class T>
struct isIterator<T, std::void_t<typename std::iterator_traits<T>::value_type>> : std::true_type
{
};
inline constexpr bool isIterator_v<T, std::void_t<typename std::iterator_traits<T>::value_type>> =
true;
template <class Callable, class Sequence>
using isInvocable = std::is_invocable<Callable, typename std::decay_t<Sequence>::value_type>;
@ -180,7 +173,7 @@ struct ReduceResultTypeHelper<Callable,
template <class Callable>
struct ReduceResultTypeHelper<Callable,
typename std::enable_if_t<!std::is_function_v<std::remove_pointer_t<std::decay_t<Callable>>>
&& hasCallOperator<std::decay_t<Callable>>::value>>
&& hasCallOperator_v<std::decay_t<Callable>>>>
{
using type = std::decay_t<typename QtPrivate::ArgResolver<Callable>::First>;
};

View File

@ -352,7 +352,7 @@ template <typename Iterator, typename MapFunctor, typename ReduceFunctor, typena
typename InitialValueType>
#else
template<typename Iterator, typename MapFunctor, typename ReduceFunctor,
std::enable_if_t<QtPrivate::isIterator<Iterator>::value, int> = 0,
std::enable_if_t<QtPrivate::isIterator_v<Iterator>, int> = 0,
typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type,
typename InitialValueType,
std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0>
@ -739,7 +739,7 @@ template <typename Iterator, typename MapFunctor, typename ReduceFunctor, typena
typename InitialValueType>
#else
template <typename Iterator, typename MapFunctor, typename ReduceFunctor,
std::enable_if_t<QtPrivate::isIterator<Iterator>::value, int> = 0,
std::enable_if_t<QtPrivate::isIterator_v<Iterator>, int> = 0,
typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type,
typename InitialValueType,
std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0>