BAN: Add destructor to function if it needs to deallocate something someday

This commit is contained in:
Bananymous 2023-02-01 21:41:18 +02:00
parent 9b8de5025a
commit 99cf1c0330
1 changed files with 13 additions and 1 deletions

View File

@ -13,7 +13,7 @@ namespace BAN
class Function<Ret(Args...)>
{
public:
Function() {}
Function() = default;
Function(Ret(*function)(Args...))
{
static_assert(sizeof(CallablePointer) <= m_size);
@ -38,6 +38,11 @@ namespace BAN
new (m_storage) CallableLambda<Lambda>(lambda);
}
~Function()
{
clear();
}
Ret operator()(Args... args)
{
ASSERT(*this);
@ -52,6 +57,13 @@ namespace BAN
return false;
}
void clear()
{
if (*this)
reinterpret_cast<CallableBase*>(m_storage)->~CallableBase();
memset(m_storage, 0, m_size);
}
private:
struct CallableBase
{