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>
This commit is contained in:
parent
509428decc
commit
89fb2271f3
@ -630,9 +630,15 @@
|
||||
This function will attempt to call a constructor for type \tt T that can
|
||||
accept all the arguments passed. Arguments will be perfectly-forwarded.
|
||||
|
||||
\note This function is only available with a C++11 compiler that supports
|
||||
perfect forwarding of an arbitrary number of arguments. If the compiler
|
||||
does not support the necessary C++11 features, you must use the overload
|
||||
\note This function is only fully available with a C++11 compiler that
|
||||
supports perfect forwarding of an arbitrary number of arguments.
|
||||
|
||||
If the compiler does not support the necessary C++11 features,
|
||||
then a restricted version is available since Qt 5.4: you may pass
|
||||
one (but just one) argument, and it will always be passed by const
|
||||
reference.
|
||||
|
||||
If you target Qt before version 5.4, you must use the overload
|
||||
that calls the default constructor.
|
||||
*/
|
||||
|
||||
|
@ -437,6 +437,27 @@ public:
|
||||
new (result.data()) T();
|
||||
# ifdef QT_SHAREDPOINTER_TRACK_POINTERS
|
||||
internalSafetyCheckAdd(result.d, result.value);
|
||||
# endif
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user