From 1e8d623340bb18c3d39d9bcd165e2250744a445a Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Fri, 3 Jul 2020 12:19:08 +0200 Subject: QThread::create: remove the pre-C++17 codepaths As we require C++17 now. The configure-time test checking for future/async is left in for the moment being. Change-Id: Ifde39d420673f70a2277f5a645bfaad30935a381 Reviewed-by: Thiago Macieira Reviewed-by: Marc Mutz Reviewed-by: Edward Welbourne Reviewed-by: Qt CI Bot --- src/corelib/thread/qthread.h | 79 ++------------------------------------------ 1 file changed, 3 insertions(+), 76 deletions(-) (limited to 'src/corelib/thread/qthread.h') diff --git a/src/corelib/thread/qthread.h b/src/corelib/thread/qthread.h index 5a1e63ee0a..caa91b100f 100644 --- a/src/corelib/thread/qthread.h +++ b/src/corelib/thread/qthread.h @@ -44,18 +44,10 @@ #include #include -// For QThread::create. The configure-time test just checks for the availability -// of std::future and std::async; for the C++17 codepath we perform some extra -// checks here (for std::invoke and C++14 lambdas). +// For QThread::create #if QT_CONFIG(cxx11_future) # include // for std::async # include // for std::invoke; no guard needed as it's a C++98 header - -# if defined(__cpp_lib_invoke) && __cpp_lib_invoke >= 201411 \ - && defined(__cpp_init_captures) && __cpp_init_captures >= 201304 \ - && defined(__cpp_generic_lambdas) && __cpp_generic_lambdas >= 201304 -# define QTHREAD_HAS_VARIADIC_CREATE -# endif #endif QT_BEGIN_NAMESPACE @@ -111,22 +103,10 @@ public: bool event(QEvent *event) override; int loopLevel() const; -#ifdef Q_CLANG_QDOC +#if QT_CONFIG(cxx11_future) || defined(Q_CLANG_QDOC) template static QThread *create(Function &&f, Args &&... args); - template - static QThread *create(Function &&f); -#else -# if QT_CONFIG(cxx11_future) -# ifdef QTHREAD_HAS_VARIADIC_CREATE - template - static QThread *create(Function &&f, Args &&... args); -# else - template - static QThread *create(Function &&f); -# endif // QTHREAD_HAS_VARIADIC_CREATE -# endif // QT_CONFIG(cxx11_future) -#endif // Q_CLANG_QDOC +#endif public Q_SLOTS: void start(Priority = InheritPriority); @@ -168,9 +148,6 @@ private: }; #if QT_CONFIG(cxx11_future) - -#if defined(QTHREAD_HAS_VARIADIC_CREATE) || defined(Q_CLANG_QDOC) -// C++17: std::thread's constructor complying call template QThread *QThread::create(Function &&f, Args &&... args) { @@ -185,56 +162,6 @@ QThread *QThread::create(Function &&f, Args &&... args) std::move(threadFunction), std::forward(args)...)); } -#elif defined(__cpp_init_captures) && __cpp_init_captures >= 201304 -// C++14: implementation for just one callable -template -QThread *QThread::create(Function &&f) -{ - using DecayedFunction = typename std::decay::type; - auto threadFunction = - [f = static_cast(std::forward(f))]() mutable -> void - { - (void)f(); - }; - - return createThreadImpl(std::async(std::launch::deferred, std::move(threadFunction))); -} -#else -// C++11: same as C++14, but with a workaround for not having generalized lambda captures -namespace QtPrivate { -template -struct Callable -{ - explicit Callable(Function &&f) - : m_function(std::forward(f)) - { - } - - // Apply the same semantics of a lambda closure type w.r.t. the special - // member functions, if possible: delete the copy assignment operator, - // bring back all the others as per the RO5 (cf. ยง8.1.5.1/11 [expr.prim.lambda.closure]) - ~Callable() = default; - Callable(const Callable &) = default; - Callable(Callable &&) = default; - Callable &operator=(const Callable &) = delete; - Callable &operator=(Callable &&) = default; - - void operator()() - { - (void)m_function(); - } - - typename std::decay::type m_function; -}; -} // namespace QtPrivate - -template -QThread *QThread::create(Function &&f) -{ - return createThreadImpl(std::async(std::launch::deferred, QtPrivate::Callable(std::forward(f)))); -} -#endif // QTHREAD_HAS_VARIADIC_CREATE - #endif // QT_CONFIG(cxx11_future) /* -- cgit v1.2.3