Luna/libluna/include/luna/Alloc.h

17 lines
347 B
C
Raw Normal View History

2022-12-06 15:41:22 +00:00
#pragma once
#include <luna/Heap.h>
#include <luna/PlacementNew.h>
2022-12-06 15:41:22 +00:00
#include <luna/Result.h>
template <typename T, class... Args> [[nodiscard]] Result<T*> make(Args... args)
2022-12-06 15:41:22 +00:00
{
T* const result = (T*)TRY(malloc_impl(sizeof(T)));
new (result) T(args...);
2022-12-06 15:41:22 +00:00
return result;
}
template <typename T> void destroy(T* item)
{
delete item;
}