[ox/std] Add safeDelete functions

This commit is contained in:
Gary Talent 2022-02-21 01:57:52 -06:00
parent 5faafad54c
commit af97a834c0

View File

@ -37,10 +37,25 @@ struct allocator {
namespace ox { namespace ox {
/*
* safeDelete exists because deleting an incomplete type will simply
* free the memory without running the destructor.
*/
template<typename T>
void safeDelete(T *val) requires(sizeof(T) >= 1) {
delete val;
}
template<typename T>
void safeDeleteArray(T *val) requires(sizeof(T) >= 1) {
delete[] val;
}
template<typename T> template<typename T>
struct DefaultDelete { struct DefaultDelete {
constexpr void operator()(T *p) noexcept { constexpr void operator()(T *p) noexcept {
delete p; safeDelete(p);
} }
}; };