summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/tools/qsharedpointer.cpp9
-rw-r--r--src/corelib/tools/qsharedpointer.h1
-rw-r--r--src/corelib/tools/qsharedpointer_impl.h1
-rw-r--r--tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp14
4 files changed, 25 insertions, 0 deletions
diff --git a/src/corelib/tools/qsharedpointer.cpp b/src/corelib/tools/qsharedpointer.cpp
index af09ef6f40..7f1e9ed798 100644
--- a/src/corelib/tools/qsharedpointer.cpp
+++ b/src/corelib/tools/qsharedpointer.cpp
@@ -577,6 +577,15 @@
*/
/*!
+ \fn T *QSharedPointer::get() const
+ \since 5.11
+
+ Same as data().
+
+ This function is provided for API compatibility with \c{std::shared_ptr}.
+*/
+
+/*!
\fn T &QSharedPointer::operator *() const
Provides access to the shared pointer's members.
diff --git a/src/corelib/tools/qsharedpointer.h b/src/corelib/tools/qsharedpointer.h
index 3b86eb238b..98b38b97d3 100644
--- a/src/corelib/tools/qsharedpointer.h
+++ b/src/corelib/tools/qsharedpointer.h
@@ -59,6 +59,7 @@ class QSharedPointer
public:
// basic accessor functions
T *data() const;
+ T *get() const;
bool isNull() const;
operator bool() const;
bool operator!() const;
diff --git a/src/corelib/tools/qsharedpointer_impl.h b/src/corelib/tools/qsharedpointer_impl.h
index 15573c5588..9e1a5c7c62 100644
--- a/src/corelib/tools/qsharedpointer_impl.h
+++ b/src/corelib/tools/qsharedpointer_impl.h
@@ -303,6 +303,7 @@ public:
typedef qptrdiff difference_type;
T *data() const Q_DECL_NOTHROW { return value; }
+ T *get() const Q_DECL_NOTHROW { return value; }
bool isNull() const Q_DECL_NOTHROW { return !data(); }
operator RestrictedBool() const Q_DECL_NOTHROW { return isNull() ? Q_NULLPTR : &QSharedPointer::value; }
bool operator !() const Q_DECL_NOTHROW { return isNull(); }
diff --git a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp
index 442d4d089c..c684af5418 100644
--- a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp
+++ b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp
@@ -272,6 +272,7 @@ void tst_QSharedPointer::basics()
QCOMPARE(!ptr, isNull);
QCOMPARE(ptr.data(), aData);
+ QCOMPARE(ptr.get(), aData);
QCOMPARE(ptr.operator->(), aData);
if (!isNull) {
Data &dataReference = *ptr;
@@ -316,6 +317,7 @@ void tst_QSharedPointer::basics()
QCOMPARE(copy.isNull(), isNull);
QCOMPARE(copy.data(), aData);
+ QCOMPARE(copy.get(), aData);
QVERIFY(copy == aData);
}
QVERIFY(!refCountData(ptr) || refCountData(ptr)->weakref.load() == 1);
@@ -349,6 +351,7 @@ void tst_QSharedPointer::basics()
QVERIFY(strong == weak);
QVERIFY(strong == ptr);
QCOMPARE(strong.data(), aData);
+ QCOMPARE(strong.get(), aData);
}
QVERIFY(!refCountData(ptr) || refCountData(ptr)->weakref.load() == 1);
QVERIFY(!refCountData(ptr) || refCountData(ptr)->strongref.load() == 1);
@@ -362,11 +365,14 @@ void tst_QSharedPointer::operators()
QSharedPointer<char> p2(new char);
qptrdiff diff = p2.data() - p1.data();
QVERIFY(p1.data() != p2.data());
+ QVERIFY(p1.get() != p2.get());
QVERIFY(diff != 0);
// operator-
QCOMPARE(p2 - p1.data(), diff);
+ QCOMPARE(p2 - p1.get(), diff);
QCOMPARE(p2.data() - p1, diff);
+ QCOMPARE(p2.get() - p1, diff);
QCOMPARE(p2 - p1, diff);
QCOMPARE(p1 - p2, -diff);
QCOMPARE(p1 - p1, qptrdiff(0));
@@ -374,7 +380,9 @@ void tst_QSharedPointer::operators()
// operator<
QVERIFY(p1 < p2.data());
+ QVERIFY(p1 < p2.get());
QVERIFY(p1.data() < p2);
+ QVERIFY(p1.get() < p2);
QVERIFY(p1 < p2);
QVERIFY(!(p2 < p1));
QVERIFY(!(p2 < p2));
@@ -382,7 +390,9 @@ void tst_QSharedPointer::operators()
// qHash
QCOMPARE(qHash(p1), qHash(p1.data()));
+ QCOMPARE(qHash(p1), qHash(p1.get()));
QCOMPARE(qHash(p2), qHash(p2.data()));
+ QCOMPARE(qHash(p2), qHash(p2.get()));
}
void tst_QSharedPointer::nullptrOps()
@@ -396,11 +406,13 @@ void tst_QSharedPointer::nullptrOps()
QVERIFY(nullptr == p1);
QVERIFY(!p1);
QVERIFY(!p1.data());
+ QVERIFY(!p1.get());
QVERIFY(p2 == null);
QVERIFY(p2 == nullptr);
QVERIFY(nullptr == p2);
QVERIFY(!p2);
QVERIFY(!p2.data());
+ QVERIFY(!p2.get());
QVERIFY(p1 == p2);
QSharedPointer<char> p3 = p1;
@@ -409,6 +421,7 @@ void tst_QSharedPointer::nullptrOps()
QVERIFY(p3 == nullptr);
QVERIFY(nullptr == p3);
QVERIFY(!p3.data());
+ QVERIFY(!p3.get());
p3 = nullptr;
@@ -421,6 +434,7 @@ void tst_QSharedPointer::nullptrOps()
QSharedPointer<char> p4(new char);
QVERIFY(p4);
QVERIFY(p4.data());
+ QVERIFY(p4.get());
QVERIFY(p4 != nullptr);
QVERIFY(nullptr != p4);
QVERIFY(p4 != p1);