QScopedPointer helper deletes: add operator()
To make them compatible with unique_ptr. Drive-by, * add missing noexcept * turn a `if (p) free(p)` into just `free(p)`. Change-Id: I234dad6f6b953202dbc537875b94f653a09910fb Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>bb10
parent
37808ee55a
commit
dda6a7497e
|
|
@ -49,7 +49,7 @@ QT_BEGIN_NAMESPACE
|
|||
template <typename T>
|
||||
struct QScopedPointerDeleter
|
||||
{
|
||||
static inline void cleanup(T *pointer)
|
||||
static inline void cleanup(T *pointer) noexcept
|
||||
{
|
||||
// Enforce a complete type.
|
||||
// If you get a compile error here, read the section on forward declared
|
||||
|
|
@ -59,12 +59,16 @@ struct QScopedPointerDeleter
|
|||
|
||||
delete pointer;
|
||||
}
|
||||
void operator()(T *pointer) const noexcept
|
||||
{
|
||||
cleanup(pointer);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct QScopedPointerArrayDeleter
|
||||
{
|
||||
static inline void cleanup(T *pointer)
|
||||
static inline void cleanup(T *pointer) noexcept
|
||||
{
|
||||
// Enforce a complete type.
|
||||
// If you get a compile error here, read the section on forward declared
|
||||
|
|
@ -74,11 +78,16 @@ struct QScopedPointerArrayDeleter
|
|||
|
||||
delete[] pointer;
|
||||
}
|
||||
void operator()(T *pointer) const noexcept
|
||||
{
|
||||
cleanup(pointer);
|
||||
}
|
||||
};
|
||||
|
||||
struct QScopedPointerPodDeleter
|
||||
{
|
||||
static inline void cleanup(void *pointer) { if (pointer) free(pointer); }
|
||||
static inline void cleanup(void *pointer) noexcept { free(pointer); }
|
||||
void operator()(void *pointer) const noexcept { cleanup(pointer); }
|
||||
};
|
||||
|
||||
#ifndef QT_NO_QOBJECT
|
||||
|
|
@ -86,6 +95,7 @@ template <typename T>
|
|||
struct QScopedPointerObjectDeleteLater
|
||||
{
|
||||
static inline void cleanup(T *pointer) { if (pointer) pointer->deleteLater(); }
|
||||
void operator()(T *pointer) const { cleanup(pointer); }
|
||||
};
|
||||
|
||||
class QObject;
|
||||
|
|
|
|||
Loading…
Reference in New Issue