summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qsharedpointer_impl.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/tools/qsharedpointer_impl.h')
-rw-r--r--src/corelib/tools/qsharedpointer_impl.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/corelib/tools/qsharedpointer_impl.h b/src/corelib/tools/qsharedpointer_impl.h
index 6f3e577e55..6393cc3970 100644
--- a/src/corelib/tools/qsharedpointer_impl.h
+++ b/src/corelib/tools/qsharedpointer_impl.h
@@ -62,6 +62,10 @@ QT_END_HEADER
#include <QtCore/qobject.h> // for qobject_cast
#include <QtCore/qhash.h> // for qHash
+#if defined(Q_COMPILER_RVALUE_REFS) && defined(Q_COMPILER_VARIADIC_TEMPLATES)
+# include <utility> // for std::forward
+#endif
+
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
@@ -389,6 +393,28 @@ public:
QWeakPointer<T> toWeakRef() const;
+#if defined(Q_COMPILER_RVALUE_REFS) && defined(Q_COMPILER_VARIADIC_TEMPLATES)
+ template <typename... Args>
+ static QSharedPointer<T> create(Args && ...arguments)
+ {
+ typedef QtSharedPointer::ExternalRefCountWithContiguousData<T> Private;
+# ifdef QT_SHAREDPOINTER_TRACK_POINTERS
+ typename Private::DestroyerFn destroy = &Private::safetyCheckDeleter;
+# else
+ typename Private::DestroyerFn destroy = &Private::deleter;
+# endif
+ QSharedPointer<T> result(Qt::Uninitialized);
+ result.d = Private::create(&result.value, destroy);
+
+ // now initialize the data
+ new (result.data()) T(std::forward<Args>(arguments)...);
+ result.d->setQObjectShared(result.value, true);
+# ifdef QT_SHAREDPOINTER_TRACK_POINTERS
+ internalSafetyCheckAdd(result.d, result.value);
+# endif
+ return result;
+ }
+#else
static inline QSharedPointer<T> create()
{
typedef QtSharedPointer::ExternalRefCountWithContiguousData<T> Private;
@@ -408,6 +434,7 @@ public:
result.d->setQObjectShared(result.value, true);
return result;
}
+#endif
private:
explicit QSharedPointer(Qt::Initialization) {}