Use unique_ptr to manage SDL pointers

This commit is contained in:
Lexi / Zoe 2025-11-21 01:09:05 +01:00
parent 5c3e0e3a86
commit 4277f4c818
Signed by: binaryDiv
GPG key ID: F8D4956E224DA232
8 changed files with 128 additions and 129 deletions

21
src/utils/memory.cppm Normal file
View file

@ -0,0 +1,21 @@
module;
export module utils.memory;
export namespace utils
{
/**
* Template to generate deleters for `std::unique_ptr` from functions, e.g. to free SDL resources.
*
* @tparam delete_func Function that takes a pointer to a resource and deletes the resource.
*/
template <auto delete_func>
struct FuncDeleter
{
template <typename T>
constexpr void operator()(T* ptr) const noexcept
{
delete_func(ptr);
}
};
}