From 6d69512c6ff58ee8a7c1266257db5bf94cc91886 Mon Sep 17 00:00:00 2001 From: Steven Le Rouzic Date: Tue, 17 Dec 2024 23:30:44 +0100 Subject: Refactor a bunch of memory utilities --- asl/box.hpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'asl/box.hpp') 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) - { - m_ptr->~T(); - } + destruct(m_ptr); m_alloc.dealloc(m_ptr, layout::of()); m_ptr = nullptr; } @@ -92,7 +89,7 @@ constexpr box make_box_in(Allocator allocator, Args&&... args) requires constructible_from { void* raw_ptr = allocator.alloc(layout::of()); - T* ptr = new (raw_ptr) T(ASL_FWD(args)...); + auto* ptr = construct_at(raw_ptr, ASL_FWD(args)...); return box(ptr, ASL_MOVE(allocator)); } @@ -102,7 +99,7 @@ constexpr box make_box(Args&&... args) { Allocator allocator{}; void* raw_ptr = allocator.alloc(layout::of()); - T* ptr = new (raw_ptr) T{ ASL_FWD(args)... }; + auto* ptr = construct_at(raw_ptr, ASL_FWD(args)...); return box(ptr, ASL_MOVE(allocator)); } -- cgit