ksys: Document safeDelete and safeDeleteArray

This commit is contained in:
Léo Lam 2022-02-09 02:59:34 +01:00
parent ce1b6900ab
commit 808b21530a
No known key found for this signature in database
GPG Key ID: 0DF30F9081000741
1 changed files with 6 additions and 0 deletions

View File

@ -4,6 +4,9 @@
namespace ksys::util {
/// Deletes an object that was allocatd with a new expression and sets the pointer to nullptr,
/// preventing it from being accidentally reused.
/// It is safe for the pointer to be already nullptr.
template <typename T>
inline void safeDelete(T*& pointer) {
if (pointer)
@ -11,6 +14,9 @@ inline void safeDelete(T*& pointer) {
pointer = nullptr;
}
/// Deletes an array that was allocatd with a new[] expression and sets the pointer to nullptr,
/// preventing it from being accidentally reused.
/// It is safe for the pointer to be already nullptr.
template <typename T>
inline void safeDeleteArray(T*& pointer) {
if (pointer)