apio
df77fc8de8
Placement new on arrays is a bit unreliable and could cause out-of-bounds data accesses.
17 lines
347 B
C++
17 lines
347 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> void destroy(T* item)
|
|
{
|
|
delete item;
|
|
}
|