diff options
author | Steven Le Rouzic <steven.lerouzic@gmail.com> | 2024-12-17 23:30:44 +0100 |
---|---|---|
committer | Steven Le Rouzic <steven.lerouzic@gmail.com> | 2024-12-20 15:35:58 +0100 |
commit | 6d69512c6ff58ee8a7c1266257db5bf94cc91886 (patch) | |
tree | 56107a97d41993417b620b88970c8d6cf7b15127 /asl/box.hpp | |
parent | 7c9e871eb66de64e7a1861fd1faebcd5524fed96 (diff) |
Refactor a bunch of memory utilities
Diffstat (limited to 'asl/box.hpp')
-rw-r--r-- | asl/box.hpp | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/asl/box.hpp b/asl/box.hpp index 7556d76..198fada 100644 --- a/asl/box.hpp +++ b/asl/box.hpp @@ -58,10 +58,7 @@ public: {
if (m_ptr != nullptr)
{
- if constexpr (!trivially_destructible<T>)
- {
- m_ptr->~T();
- }
+ destruct(m_ptr);
m_alloc.dealloc(m_ptr, layout::of<T>());
m_ptr = nullptr;
}
@@ -92,7 +89,7 @@ constexpr box<T, Allocator> make_box_in(Allocator allocator, Args&&... args) requires constructible_from<T, Args&&...>
{
void* raw_ptr = allocator.alloc(layout::of<T>());
- T* ptr = new (raw_ptr) T(ASL_FWD(args)...);
+ auto* ptr = construct_at<T>(raw_ptr, ASL_FWD(args)...);
return box(ptr, ASL_MOVE(allocator));
}
@@ -102,7 +99,7 @@ constexpr box<T, Allocator> make_box(Args&&... args) {
Allocator allocator{};
void* raw_ptr = allocator.alloc(layout::of<T>());
- T* ptr = new (raw_ptr) T{ ASL_FWD(args)... };
+ auto* ptr = construct_at<T>(raw_ptr, ASL_FWD(args)...);
return box<T>(ptr, ASL_MOVE(allocator));
}
|