mirror of
https://github.com/simonbrunel/qtpromise.git
synced 2024-11-22 02:34:30 +08:00
Use QSharedPointer::create and std::make_shared
This commit is contained in:
parent
2c1e631aed
commit
0bfdddd887
@ -81,8 +81,8 @@ class PromiseValue
|
||||
{
|
||||
public:
|
||||
PromiseValue() { }
|
||||
PromiseValue(const T& data) : m_data(new T(data)) { }
|
||||
PromiseValue(T&& data) : m_data(new T(std::move(data))) { }
|
||||
PromiseValue(const T& data) : m_data(QSharedPointer<T>::create(data)) { }
|
||||
PromiseValue(T&& data) : m_data(QSharedPointer<T>::create(std::forward<T>(data))) { }
|
||||
bool isNull() const { return m_data.isNull(); }
|
||||
const T& data() const { return *m_data; }
|
||||
|
||||
|
@ -15,7 +15,7 @@ namespace QtPromise {
|
||||
class QPromiseConnections
|
||||
{
|
||||
public:
|
||||
QPromiseConnections() : m_d(new Data()) { }
|
||||
QPromiseConnections() : m_d(QSharedPointer<Data>::create()) { }
|
||||
|
||||
int count() const { return m_d->connections.count(); }
|
||||
|
||||
|
@ -59,8 +59,8 @@ all(const Sequence<QPromise<T>, Args...>& promises)
|
||||
const QPromiseResolve<QVector<T>>& resolve,
|
||||
const QPromiseReject<QVector<T>>& reject) {
|
||||
|
||||
QSharedPointer<int> remaining(new int(count));
|
||||
QSharedPointer<QVector<T>> results(new QVector<T>(count));
|
||||
auto remaining = QSharedPointer<int>::create(count);
|
||||
auto results = QSharedPointer<QVector<T>>::create(count);
|
||||
|
||||
int i = 0;
|
||||
for (const auto& promise: promises) {
|
||||
@ -94,7 +94,7 @@ all(const Sequence<QPromise<void>, Args...>& promises)
|
||||
const QPromiseResolve<void>& resolve,
|
||||
const QPromiseReject<void>& reject) {
|
||||
|
||||
QSharedPointer<int> remaining(new int(count));
|
||||
auto remaining = QSharedPointer<int>::create(count);
|
||||
|
||||
for (const auto& promise: promises) {
|
||||
promise.then([=]() {
|
||||
|
@ -108,10 +108,10 @@ void tst_deprecations_helpers_qpromise::qtSharedPtr()
|
||||
QWeakPointer<Data> wptr;
|
||||
|
||||
{
|
||||
QSharedPointer<Data> sptr0(new Data(42));
|
||||
auto sptr0 = QSharedPointer<Data>::create(42);
|
||||
const QSharedPointer<Data> sptr1 = sptr0;
|
||||
|
||||
auto p0 = qPromise(QSharedPointer<Data>(new Data(42)));
|
||||
auto p0 = qPromise(QSharedPointer<Data>::create(42));
|
||||
auto p1 = qPromise(sptr0);
|
||||
auto p2 = qPromise(sptr1);
|
||||
|
||||
@ -144,10 +144,10 @@ void tst_deprecations_helpers_qpromise::stdSharedPtr()
|
||||
std::weak_ptr<Data> wptr;
|
||||
|
||||
{
|
||||
std::shared_ptr<Data> sptr0(new Data(42));
|
||||
auto sptr0 = std::make_shared<Data>(42);
|
||||
const std::shared_ptr<Data> sptr1 = sptr0;
|
||||
|
||||
auto p0 = qPromise(std::shared_ptr<Data>(new Data(42)));
|
||||
auto p0 = qPromise(std::make_shared<Data>(42));
|
||||
auto p1 = qPromise(sptr0);
|
||||
auto p2 = qPromise(sptr1);
|
||||
|
||||
|
@ -41,7 +41,7 @@ void tst_helpers_reject::rejectWithQSharedPtr()
|
||||
QWeakPointer<int> wptr;
|
||||
|
||||
{
|
||||
QSharedPointer<int> sptr(new int(42));
|
||||
auto sptr = QSharedPointer<int>::create(42);
|
||||
auto p = QPromise<int>::reject(sptr);
|
||||
|
||||
QCOMPARE(waitForError(p, QSharedPointer<int>()), sptr);
|
||||
@ -61,7 +61,7 @@ void tst_helpers_reject::rejectWithStdSharedPtr()
|
||||
std::weak_ptr<int> wptr;
|
||||
|
||||
{
|
||||
std::shared_ptr<int> sptr(new int(42));
|
||||
auto sptr = std::make_shared<int>(42);
|
||||
auto p = QPromise<int>::reject(sptr);
|
||||
|
||||
QCOMPARE(waitForError(p, std::shared_ptr<int>()), sptr);
|
||||
|
@ -108,10 +108,10 @@ void tst_helpers_resolve::qtSharedPtr()
|
||||
QWeakPointer<Data> wptr;
|
||||
|
||||
{
|
||||
QSharedPointer<Data> sptr0(new Data(42));
|
||||
auto sptr0 = QSharedPointer<Data>::create(42);
|
||||
const QSharedPointer<Data> sptr1 = sptr0;
|
||||
|
||||
auto p0 = QtPromise::resolve(QSharedPointer<Data>(new Data(42)));
|
||||
auto p0 = QtPromise::resolve(QSharedPointer<Data>::create(42));
|
||||
auto p1 = QtPromise::resolve(sptr0);
|
||||
auto p2 = QtPromise::resolve(sptr1);
|
||||
|
||||
@ -144,10 +144,10 @@ void tst_helpers_resolve::stdSharedPtr()
|
||||
std::weak_ptr<Data> wptr;
|
||||
|
||||
{
|
||||
std::shared_ptr<Data> sptr0(new Data(42));
|
||||
auto sptr0 = std::make_shared<Data>(42);
|
||||
const std::shared_ptr<Data> sptr1 = sptr0;
|
||||
|
||||
auto p0 = QtPromise::resolve(std::shared_ptr<Data>(new Data(42)));
|
||||
auto p0 = QtPromise::resolve(std::make_shared<Data>(42));
|
||||
auto p1 = QtPromise::resolve(sptr0);
|
||||
auto p2 = QtPromise::resolve(sptr1);
|
||||
|
||||
|
@ -276,7 +276,7 @@ void tst_qpromise_construct::connectAndResolve()
|
||||
|
||||
connect(object.data(), &QObject::objectNameChanged,
|
||||
[=, &wptr](const QString& name) {
|
||||
std::shared_ptr<int> sptr(new int(42));
|
||||
auto sptr = std::make_shared<int>(42);
|
||||
|
||||
wptr = sptr;
|
||||
|
||||
@ -313,7 +313,7 @@ void tst_qpromise_construct::connectAndReject()
|
||||
|
||||
connect(object.data(), &QObject::objectNameChanged,
|
||||
[=, &wptr](const QString& name) {
|
||||
std::shared_ptr<int> sptr(new int(42));
|
||||
auto sptr = std::make_shared<int>(42);
|
||||
|
||||
wptr = sptr;
|
||||
|
||||
|
@ -103,10 +103,10 @@ void tst_qpromise_resolve::qtSharedPtr()
|
||||
QWeakPointer<Data> wptr;
|
||||
|
||||
{
|
||||
QSharedPointer<Data> sptr0(new Data(42));
|
||||
auto sptr0 = QSharedPointer<Data>::create(42);
|
||||
const QSharedPointer<Data> sptr1 = sptr0;
|
||||
|
||||
auto p0 = QPromise<QSharedPointer<Data>>::resolve(QSharedPointer<Data>(new Data(42)));
|
||||
auto p0 = QPromise<QSharedPointer<Data>>::resolve(QSharedPointer<Data>::create(42));
|
||||
auto p1 = QPromise<QSharedPointer<Data>>::resolve(sptr0);
|
||||
auto p2 = QPromise<QSharedPointer<Data>>::resolve(sptr1);
|
||||
|
||||
@ -139,10 +139,10 @@ void tst_qpromise_resolve::stdSharedPtr()
|
||||
std::weak_ptr<Data> wptr;
|
||||
|
||||
{
|
||||
std::shared_ptr<Data> sptr0(new Data(42));
|
||||
auto sptr0 = std::make_shared<Data>(42);
|
||||
const std::shared_ptr<Data> sptr1 = sptr0;
|
||||
|
||||
auto p0 = QPromise<std::shared_ptr<Data>>::resolve(std::shared_ptr<Data>(new Data(42)));
|
||||
auto p0 = QPromise<std::shared_ptr<Data>>::resolve(std::make_shared<Data>(42));
|
||||
auto p1 = QPromise<std::shared_ptr<Data>>::resolve(sptr0);
|
||||
auto p2 = QPromise<std::shared_ptr<Data>>::resolve(sptr1);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user