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
Giuseppe D'Angelo 2020-11-01 15:11:02 +01:00
parent 37808ee55a
commit dda6a7497e
1 changed files with 13 additions and 3 deletions

View File

@ -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;