29 lines
605 B
C++
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;
|
|
}
|