46 lines
928 B
C++
46 lines
928 B
C++
#pragma once
|
|
#include <luna/Result.h>
|
|
|
|
namespace std
|
|
{
|
|
struct nothrow_t
|
|
{
|
|
explicit nothrow_t() = default;
|
|
};
|
|
|
|
extern const nothrow_t nothrow;
|
|
|
|
enum class align_val_t : usize
|
|
{
|
|
};
|
|
};
|
|
|
|
[[nodiscard]] void* raw_malloc(usize);
|
|
void raw_free(void*);
|
|
|
|
void* operator new(usize size, const std::nothrow_t&) noexcept;
|
|
void* operator new[](usize size, const std::nothrow_t&) noexcept;
|
|
|
|
template <typename T, class... Args> [[nodiscard]] Result<T*> make(Args... args)
|
|
{
|
|
T* const result = new (std::nothrow) T(args...);
|
|
if (!result) return err(ENOMEM);
|
|
return result;
|
|
}
|
|
|
|
template <typename T> [[nodiscard]] Result<T*> make_array(usize count)
|
|
{
|
|
T* const result = new (std::nothrow) T[count];
|
|
if (!result) return err(ENOMEM);
|
|
return result;
|
|
}
|
|
|
|
template <typename T> void destroy(T* item)
|
|
{
|
|
delete item;
|
|
}
|
|
|
|
template <typename T> void destroy_array(T* item)
|
|
{
|
|
delete[] item;
|
|
} |