diff options
Diffstat (limited to 'src/corelib/tools/qsharedpointer_impl.h')
-rw-r--r-- | src/corelib/tools/qsharedpointer_impl.h | 38 |
1 files changed, 32 insertions, 6 deletions
diff --git a/src/corelib/tools/qsharedpointer_impl.h b/src/corelib/tools/qsharedpointer_impl.h index 881c60b6fd..5e30cf3ecb 100644 --- a/src/corelib/tools/qsharedpointer_impl.h +++ b/src/corelib/tools/qsharedpointer_impl.h @@ -46,14 +46,17 @@ #endif #if 0 +#pragma qt_sync_skip_header_check +#pragma qt_sync_stop_processing +#endif + +#if 0 // These macros are duplicated here to make syncqt not complain a about // this header, as we have a "qt_sync_stop_processing" below, which in turn // is here because this file contains a template mess and duplicates the // classes found in qsharedpointer.h -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE QT_END_NAMESPACE -QT_END_HEADER #pragma qt_sync_stop_processing #endif @@ -62,7 +65,9 @@ QT_END_HEADER #include <QtCore/qobject.h> // for qobject_cast #include <QtCore/qhash.h> // for qHash -QT_BEGIN_HEADER +#if defined(Q_COMPILER_RVALUE_REFS) && defined(Q_COMPILER_VARIADIC_TEMPLATES) +# include <utility> // for std::forward +#endif QT_BEGIN_NAMESPACE @@ -389,6 +394,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 +435,7 @@ public: result.d->setQObjectShared(result.value, true); return result; } +#endif private: explicit QSharedPointer(Qt::Initialization) {} @@ -616,7 +644,7 @@ private: public: #else template <class X> friend class QSharedPointer; - friend class QPointerBase; + template <class X> friend class QPointer; #endif template <class X> @@ -862,6 +890,4 @@ template<typename T> Q_DECLARE_TYPEINFO_BODY(QSharedPointer<T>, Q_MOVABLE_TYPE); QT_END_NAMESPACE -QT_END_HEADER - #endif |