[ox/std] Add safeDelete functions
This commit is contained in:
parent
5faafad54c
commit
af97a834c0
17
deps/ox/src/ox/std/memory.hpp
vendored
17
deps/ox/src/ox/std/memory.hpp
vendored
@ -37,10 +37,25 @@ struct allocator {
|
||||
|
||||
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>
|
||||
struct DefaultDelete {
|
||||
constexpr void operator()(T *p) noexcept {
|
||||
delete p;
|
||||
safeDelete(p);
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user