diff --git a/include/beman/lazy/detail/allocator_support.hpp b/include/beman/lazy/detail/allocator_support.hpp index 24d330c..fd59d88 100644 --- a/include/beman/lazy/detail/allocator_support.hpp +++ b/include/beman/lazy/detail/allocator_support.hpp @@ -46,18 +46,22 @@ struct allocator_support { } template - void* operator new(std::size_t size, A&&... a) { + static void* operator new(std::size_t size, A&&... a) { Allocator alloc{::beman::lazy::detail::find_allocator(a...)}; - void* ptr{allocator_traits::allocate(alloc, offset(size) + sizeof(Allocator))}; - new (get_allocator(ptr, size)) Allocator(alloc); + void* ptr{allocator_traits::allocate(alloc, allocator_support::offset(size) + sizeof(Allocator))}; + new (allocator_support::get_allocator(ptr, size)) Allocator(alloc); return ptr; } - void operator delete(void* ptr, std::size_t size) { - Allocator* aptr{get_allocator(ptr, size)}; + template + static void operator delete(void* ptr, std::size_t size, A&&...) { + allocator_support::operator delete(ptr, size); + } + static void operator delete(void* ptr, std::size_t size) { + Allocator* aptr{allocator_support::get_allocator(ptr, size)}; Allocator alloc{*aptr}; aptr->~Allocator(); - // alloc.deallocate(static_cast(ptr), offset(size) + sizeof(Allocator)); - allocator_traits::deallocate(alloc, static_cast(ptr), offset(size) + sizeof(Allocator)); + allocator_traits::deallocate( + alloc, static_cast(ptr), allocator_support::offset(size) + sizeof(Allocator)); } }; } // namespace beman::lazy::detail diff --git a/tests/beman/lazy/allocator_support.test.cpp b/tests/beman/lazy/allocator_support.test.cpp index 89bc114..8720f0a 100644 --- a/tests/beman/lazy/allocator_support.test.cpp +++ b/tests/beman/lazy/allocator_support.test.cpp @@ -51,6 +51,6 @@ int main() { assert(resource.outstanding != 0u); ptr->~type(); assert(resource.outstanding != 0u); - type::operator delete(ptr, sizeof(type)); + type::operator delete(ptr, sizeof(type), std::allocator_arg, &resource); assert(resource.outstanding == 0u); }