diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2014-04-03 09:36:03 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-04-07 12:11:39 +0200 |
commit | 89fb2271f377d1194f3311124daef97504e6ead9 (patch) | |
tree | e64f09463e7ca129e49f8199961dab9ff7284dba /src/corelib/tools/qsharedpointer_impl.h | |
parent | 509428decc0bf8407c63581f16b4ee27b2cfda1d (diff) |
QSharedPointer: allow one create() argument in C++98, too
Survey says that most uses of QSharedPointer(T*) in Qt that could benefit from
variadic create() pass only a single argument. In order to prevent all such
uses from #ifdef'ing on the complex condition that enables the variadic version,
provide a single-argument version (for lvalues only, obviously) for C++98, too.
Change-Id: I22ad251a20bbf80867cc31eaa3bcec677bde4359
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools/qsharedpointer_impl.h')
-rw-r--r-- | src/corelib/tools/qsharedpointer_impl.h | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/corelib/tools/qsharedpointer_impl.h b/src/corelib/tools/qsharedpointer_impl.h index f70e398cfe..f3df32469f 100644 --- a/src/corelib/tools/qsharedpointer_impl.h +++ b/src/corelib/tools/qsharedpointer_impl.h @@ -441,6 +441,27 @@ public: result.d->setQObjectShared(result.value, true); return result; } + + template <typename Arg> + static inline QSharedPointer create(const Arg &arg) + { + 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 result(Qt::Uninitialized); + result.d = Private::create(&result.value, destroy); + + // now initialize the data + new (result.data()) T(arg); +# ifdef QT_SHAREDPOINTER_TRACK_POINTERS + internalSafetyCheckAdd(result.d, result.value); +# endif + result.d->setQObjectShared(result.value, true); + return result; + } #endif private: |