mirror of
https://github.com/simonbrunel/qtpromise.git
synced 2024-11-21 18:24:29 +08:00
Fix deprecations and compile warnings (#34)
- Use std::invoke_result, fallback to std::result_of on C++11/14. - Use RVO instead of std::move (GCC warning: redundant-move). - Replace QSharedPointer with std::shared_ptr (GCC warning: unititialized value). - QLinkedList is deprecated in Qt 5.15.
This commit is contained in:
parent
88289a7635
commit
b7ecd95b04
@ -34,6 +34,14 @@ class QPromiseReject;
|
||||
|
||||
namespace QtPromisePrivate {
|
||||
|
||||
// Use std::invoke_result for C++17 and beyond
|
||||
#if (__cplusplus >= 201703L) || defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L)
|
||||
using std::invoke_result;
|
||||
#else
|
||||
template<class F, class... ArgTypes>
|
||||
using invoke_result = std::result_of<F(ArgTypes...)>;
|
||||
#endif
|
||||
|
||||
// https://stackoverflow.com/a/21653558
|
||||
template<typename F>
|
||||
static void qtpromise_defer(F&& f, const QPointer<QThread>& thread)
|
||||
@ -138,7 +146,7 @@ struct PromiseDeduce<QtPromise::QPromise<T>> : public PromiseDeduce<T>
|
||||
template<typename Functor, typename... Args>
|
||||
struct PromiseFunctor
|
||||
{
|
||||
using ResultType = typename std::result_of<Functor(Args...)>::type;
|
||||
using ResultType = typename invoke_result<Functor, Args...>::type;
|
||||
using PromiseType = typename PromiseDeduce<ResultType>::Type;
|
||||
};
|
||||
|
||||
@ -231,7 +239,7 @@ struct PromiseDispatch<void>
|
||||
template<typename T, typename THandler, typename TArg = typename ArgsOf<THandler>::first>
|
||||
struct PromiseHandler
|
||||
{
|
||||
using ResType = typename std::result_of<THandler(T)>::type;
|
||||
using ResType = typename invoke_result<THandler, T>::type;
|
||||
using Promise = typename PromiseDeduce<ResType>::Type;
|
||||
|
||||
template<typename TResolve, typename TReject>
|
||||
@ -247,7 +255,7 @@ struct PromiseHandler
|
||||
template<typename T, typename THandler>
|
||||
struct PromiseHandler<T, THandler, void>
|
||||
{
|
||||
using ResType = typename std::result_of<THandler()>::type;
|
||||
using ResType = typename invoke_result<THandler>::type;
|
||||
using Promise = typename PromiseDeduce<ResType>::Type;
|
||||
|
||||
template<typename TResolve, typename TReject>
|
||||
@ -263,7 +271,7 @@ struct PromiseHandler<T, THandler, void>
|
||||
template<typename THandler>
|
||||
struct PromiseHandler<void, THandler, void>
|
||||
{
|
||||
using ResType = typename std::result_of<THandler()>::type;
|
||||
using ResType = typename invoke_result<THandler>::type;
|
||||
using Promise = typename PromiseDeduce<ResType>::Type;
|
||||
|
||||
template<typename TResolve, typename TReject>
|
||||
@ -312,7 +320,7 @@ struct PromiseHandler<void, std::nullptr_t, void>
|
||||
template<typename T, typename THandler, typename TArg = typename ArgsOf<THandler>::first>
|
||||
struct PromiseCatcher
|
||||
{
|
||||
using ResType = typename std::result_of<THandler(TArg)>::type;
|
||||
using ResType = typename invoke_result<THandler, TArg>::type;
|
||||
|
||||
template<typename TResolve, typename TReject>
|
||||
static std::function<void(const PromiseError&)>
|
||||
@ -333,7 +341,7 @@ struct PromiseCatcher
|
||||
template<typename T, typename THandler>
|
||||
struct PromiseCatcher<T, THandler, void>
|
||||
{
|
||||
using ResType = typename std::result_of<THandler()>::type;
|
||||
using ResType = typename invoke_result<THandler>::type;
|
||||
|
||||
template<typename TResolve, typename TReject>
|
||||
static std::function<void(const PromiseError&)>
|
||||
@ -371,7 +379,7 @@ struct PromiseMapper
|
||||
template<typename T, typename F, template<typename, typename...> class Sequence, typename... Args>
|
||||
struct PromiseMapper<Sequence<T, Args...>, F>
|
||||
{
|
||||
using ReturnType = typename std::result_of<F(T, int)>::type;
|
||||
using ReturnType = typename invoke_result<F, T, int>::type;
|
||||
using ResultType = QVector<typename PromiseDeduce<ReturnType>::Type::Type>;
|
||||
using PromiseType = QtPromise::QPromise<ResultType>;
|
||||
};
|
||||
|
@ -8,14 +8,15 @@
|
||||
#ifndef QTPROMISE_QPROMISECONNECTIONS_H
|
||||
#define QTPROMISE_QPROMISECONNECTIONS_H
|
||||
|
||||
#include <QtCore/QSharedPointer>
|
||||
#include <QtCore/QObject>
|
||||
#include <memory>
|
||||
|
||||
namespace QtPromise {
|
||||
|
||||
class QPromiseConnections
|
||||
{
|
||||
public:
|
||||
QPromiseConnections() : m_d(QSharedPointer<Data>::create()) { }
|
||||
QPromiseConnections() : m_d(std::make_shared<Data>()) { }
|
||||
|
||||
int count() const { return m_d->connections.count(); }
|
||||
|
||||
@ -48,7 +49,7 @@ private:
|
||||
}
|
||||
};
|
||||
|
||||
QSharedPointer<Data> m_d;
|
||||
std::shared_ptr<Data> m_d;
|
||||
};
|
||||
|
||||
} // namespace QtPromise
|
||||
|
@ -32,7 +32,7 @@ static inline typename QtPromisePrivate::PromiseDeduce<T>::Type resolve(T&& valu
|
||||
template<typename T>
|
||||
static inline QPromise<T> resolve(QPromise<T> value)
|
||||
{
|
||||
return std::move(value);
|
||||
return value;
|
||||
}
|
||||
|
||||
static inline QPromise<void> resolve()
|
||||
|
@ -290,7 +290,10 @@ void tst_helpers_reduce::functorThrows()
|
||||
|
||||
void tst_helpers_reduce::sequenceTypes()
|
||||
{
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0))
|
||||
// QLinkedList is deprecated since Qt 5.15.
|
||||
SequenceTester<QLinkedList<QPromise<int>>>::exec();
|
||||
#endif
|
||||
SequenceTester<QList<QPromise<int>>>::exec();
|
||||
SequenceTester<QVector<QPromise<int>>>::exec();
|
||||
SequenceTester<std::list<QPromise<int>>>::exec();
|
||||
|
@ -283,7 +283,10 @@ void tst_qpromise_reduce::functorThrows()
|
||||
|
||||
void tst_qpromise_reduce::sequenceTypes()
|
||||
{
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0))
|
||||
// QLinkedList is deprecated since Qt 5.15.
|
||||
SequenceTester<QLinkedList<QPromise<int>>>::exec();
|
||||
#endif
|
||||
SequenceTester<QList<QPromise<int>>>::exec();
|
||||
SequenceTester<QVector<QPromise<int>>>::exec();
|
||||
SequenceTester<std::list<QPromise<int>>>::exec();
|
||||
|
Loading…
Reference in New Issue
Block a user