Luna/libluna/include/luna/Alloc.h
apio 77887eed80
All checks were successful
continuous-integration/drone/push Build is passing
luna -> libluna
2023-02-27 15:22:39 +01:00

29 lines
605 B
C++

#pragma once
#include <luna/Heap.h>
#include <luna/PlacementNew.h>
#include <luna/Result.h>
template <typename T, class... Args> [[nodiscard]] Result<T*> make(Args... args)
{
T* const result = (T*)TRY(malloc_impl(sizeof(T)));
new (result) T(args...);
return result;
}
template <typename T> [[nodiscard]] Result<T*> make_array(usize count)
{
T* const result = (T*)TRY(calloc_impl(count, sizeof(T)));
new (result) T[count];
return result;
}
template <typename T> void destroy(T* item)
{
delete item;
}
template <typename T> void destroy_array(T* item)
{
delete[] item;
}