Use unique_ptr to manage SDL pointers
This commit is contained in:
parent
5c3e0e3a86
commit
4277f4c818
8 changed files with 128 additions and 129 deletions
21
src/utils/memory.cppm
Normal file
21
src/utils/memory.cppm
Normal 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);
|
||||
}
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue