From c91327645b1a659a5b749264d7fb3447c9c43c3f Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Wed, 30 Sep 2020 21:01:36 +0200 Subject: [PATCH] QtConcurrent: Reuse ArgResolver from qfuture_impl.h Task-number: QTBUG-83331 Change-Id: I572f68f6d3be4a50970d8d77d070f175be3ec785 Reviewed-by: Sona Kurazyan --- src/concurrent/qtconcurrentrun.h | 104 ++---------------------------- src/corelib/thread/qfuture_impl.h | 46 +++++++++++++ 2 files changed, 50 insertions(+), 100 deletions(-) diff --git a/src/concurrent/qtconcurrentrun.h b/src/concurrent/qtconcurrentrun.h index 5804393e25..79322b925f 100644 --- a/src/concurrent/qtconcurrentrun.h +++ b/src/concurrent/qtconcurrentrun.h @@ -73,102 +73,6 @@ namespace QtConcurrent { namespace QtConcurrent { -// Note: It's a copy taken from qfuture_impl.h with some specialization added -// TODO: Get rid of the code repetition and unify this for both purposes, see QTBUG-83331 -template -struct ArgsType; - -template -struct ArgsType -{ - using PromiseType = void; - static const bool IsPromise = false; -}; - -// Note: this specialization was added -template -struct ArgsType &, Args...> -{ - using PromiseType = Arg; - static const bool IsPromise = true; -}; - -template<> -struct ArgsType<> -{ - using PromiseType = void; - static const bool IsPromise = false; -}; - -template -struct ArgResolver : ArgResolver::operator())> -{ -}; - -// Note: this specialization was added, see callableObjectWithState() test in qtconcurrentrun -template -struct ArgResolver> : ArgResolver::operator())> -{ -}; - -template -struct ArgResolver : public ArgsType -{ -}; - -template -struct ArgResolver : public ArgsType -{ -}; - -// Note: this specialization was added, see light() test in qtconcurrentrun -template -struct ArgResolver : public ArgsType -{ -}; - -// Note: this specialization was added, see light() test in qtconcurrentrun -template -struct ArgResolver : public ArgsType -{ -}; - -template -struct ArgResolver : public ArgsType -{ -}; - -template -struct ArgResolver : public ArgsType -{ -}; - -template -struct ArgResolver : public ArgsType -{ -}; - -template -struct ArgResolver : public ArgsType -{ -}; - -template -struct ArgResolver : public ArgsType -{ -}; - -// Note: this specialization was added, see crefFunction() test in qtconcurrentrun -template -struct ArgResolver : public ArgsType -{ -}; - -template -struct ArgResolver : public ArgsType -{ -}; - template [[nodiscard]] auto run(QThreadPool *pool, Function &&f, Args &&...args) @@ -196,8 +100,8 @@ template [[nodiscard]] auto runWithPromise(QThreadPool *pool, Function &&f, Args &&...args) { - static_assert(ArgResolver::IsPromise, "The first argument of passed callable object isn't a QPromise & type."); - using PromiseType = typename ArgResolver::PromiseType; + static_assert(QtPrivate::ArgResolver::IsPromise, "The first argument of passed callable object isn't a QPromise & type."); + using PromiseType = typename QtPrivate::ArgResolver::PromiseType; return runWithPromise(pool, std::forward(f), std::forward(args)...); } @@ -205,8 +109,8 @@ template [[nodiscard]] auto runWithPromise(QThreadPool *pool, std::reference_wrapper &&functionWrapper, Args &&...args) { - static_assert(ArgResolver::IsPromise, "The first argument of passed callable object isn't a QPromise & type."); - using PromiseType = typename ArgResolver::PromiseType; + static_assert(QtPrivate::ArgResolver::IsPromise, "The first argument of passed callable object isn't a QPromise & type."); + using PromiseType = typename QtPrivate::ArgResolver::PromiseType; return runWithPromise(pool, std::forward(functionWrapper.get()), std::forward(args)...); } diff --git a/src/corelib/thread/qfuture_impl.h b/src/corelib/thread/qfuture_impl.h index 883f8d4f09..bd3976f990 100644 --- a/src/corelib/thread/qfuture_impl.h +++ b/src/corelib/thread/qfuture_impl.h @@ -59,6 +59,8 @@ template class QFuture; template class QFutureInterface; +template +class QPromise; namespace QtFuture { enum class Launch { Sync, Async, Inherit }; @@ -121,6 +123,8 @@ template struct ArgsType { using First = Arg; + using PromiseType = void; + static const bool IsPromise = false; static const bool HasExtraArgs = (sizeof...(Args) > 0); using AllArgs = std::conditional_t, std::decay_t...>, @@ -130,10 +134,27 @@ struct ArgsType static const bool CanInvokeWithArgs = std::is_invocable_v; }; +template +struct ArgsType &, Args...> +{ + using First = QPromise &; + using PromiseType = Arg; + static const bool IsPromise = true; + static const bool HasExtraArgs = (sizeof...(Args) > 0); + using AllArgs = + std::conditional_t &>, std::decay_t...>, + std::decay_t &>>; + + template + static const bool CanInvokeWithArgs = std::is_invocable_v &, Args...>; +}; + template<> struct ArgsType<> { using First = void; + using PromiseType = void; + static const bool IsPromise = false; static const bool HasExtraArgs = false; using AllArgs = void; @@ -146,6 +167,11 @@ struct ArgResolver : ArgResolver::operator())> { }; +template +struct ArgResolver> : ArgResolver::operator())> +{ +}; + template struct ArgResolver : public ArgsType { @@ -156,6 +182,16 @@ struct ArgResolver : public ArgsType { }; +template +struct ArgResolver : public ArgsType +{ +}; + +template +struct ArgResolver : public ArgsType +{ +}; + template struct ArgResolver : public ArgsType { @@ -181,6 +217,16 @@ struct ArgResolver : public ArgsType +struct ArgResolver : public ArgsType +{ +}; + +template +struct ArgResolver : public ArgsType +{ +}; + template using EnableIfInvocable = std::enable_if_t< QtPrivate::ArgResolver::template CanInvokeWithArgs>;