[+] std::pmr requirements

This commit is contained in:
Reece Wilson 2024-04-20 22:37:52 +01:00
parent f2acc55b42
commit 8e3a0efa68

View File

@ -262,6 +262,7 @@ namespace Aurora::Memory
static void *__FAlloc(Types::size_t length, Types::size_t align);
static void __Free(void *buffer);
static AuUInt __SizeOf(void *pHead);
template <class T>
struct BaseAuroraRuntimeAllocator
@ -273,23 +274,115 @@ namespace Aurora::Memory
constexpr BaseAuroraRuntimeAllocator()
{}
template <class U> constexpr BaseAuroraRuntimeAllocator(const BaseAuroraRuntimeAllocator <U> &) noexcept
template <class U>
constexpr BaseAuroraRuntimeAllocator(const BaseAuroraRuntimeAllocator <U> &) noexcept
{
}
inline constexpr T* allocate(Types::size_t n)
void *allocate_bytes(std::size_t nbytes,
std::size_t alignment = alignof(std::max_align_t))
{
if (auto p = (__FAlloc(n * sizeof(T), alignof(T))))
if (auto pRet = __FAlloc(nbytes, alignment))
{
return AuReinterpretCast<T*>(p);
return pRet;
}
else
{
throw std::bad_alloc();
}
}
inline constexpr void deallocate(T *p, std::size_t n) noexcept
void deallocate_bytes(void *p,
std::size_t nbytes,
std::size_t alignment = alignof(std::max_align_t))
{
__Free(p);
return __Free(p);
}
#if defined(AU_LANG_CPP_23)
constexpr std::allocation_result<T *> allocate_at_least(const size_t count)
{
auto pThat = this->allocate(count);
return { (T *)pThat, __SizeOf(pThat) / sizeof(T) };
}
#endif
template <class U, class... Args >
void construct(U *p, Args&&... args)
{
if constexpr (AuIsClass_v<U>)
{
new ((void *)p) U(AuForward<Args &&>(args)...);
}
}
template <class U, class... Args >
void construct_at(U *p, Args&&... args)
{
if constexpr (AuIsClass_v<U>)
{
new ((void *)p) U(AuForward<Args &&>(args)...);
}
}
constexpr void deallocate(const T *pType,
const size_t count)
{
this->deallocate_bytes((void *)pType, 0, 0);
}
constexpr AU_ALLOC T *allocate(const size_t count)
{
if (!count)
{
return nullptr;
}
return (T *)this->allocate_bytes(count * sizeof(T), alignof(T));
}
template <class U>
U *allocate_object(std::size_t n = 1)
{
return (U *)this->allocate_bytes(sizeof(U) * n, alignof(U));
}
template <class U>
void deallocate_object(U *p, std::size_t n = 1)
{
this->deallocate_bytes(p, 0, 0);
}
template <class U, class... CtorArgs>
U *new_object(CtorArgs&&... args)
{
U *p = this->allocate_object<U>();
if constexpr (AuIsClass_v<U> &&
!AuIsTriviallyConstructible_v<U, CtorArgs>)
{
try
{
this->construct(p, AuForward<CtorArgs>(args)...);
}
catch (...)
{
this->deallocate_object(p);
throw;
}
}
return p;
}
template <class U>
void delete_object(U *p)
{
if constexpr (AuIsClass_v<U> &&
!AuIsTriviallyDestructible_v<U>)
{
p->~U();
}
this->deallocate_object(p);
}
inline bool operator==(const BaseAuroraRuntimeAllocator &op)