From 9653420a87c85ca5b28de8a6e0e2dfcd724ad37e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dietmar=20K=C3=BChl?= Date: Thu, 23 Jan 2025 22:27:52 +0000 Subject: [PATCH] added special treatment for std::allocator --- .../beman/lazy/detail/allocator_support.hpp | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/include/beman/lazy/detail/allocator_support.hpp b/include/beman/lazy/detail/allocator_support.hpp index fd59d88..996b0ab 100644 --- a/include/beman/lazy/detail/allocator_support.hpp +++ b/include/beman/lazy/detail/allocator_support.hpp @@ -6,10 +6,10 @@ #include #include +#include +#include #include #include -#include -#include // ---------------------------------------------------------------------------- @@ -47,21 +47,30 @@ struct allocator_support { template static void* operator new(std::size_t size, A&&... a) { - Allocator alloc{::beman::lazy::detail::find_allocator(a...)}; - void* ptr{allocator_traits::allocate(alloc, allocator_support::offset(size) + sizeof(Allocator))}; - new (allocator_support::get_allocator(ptr, size)) Allocator(alloc); - return ptr; + if constexpr (::std::same_as>) { + return ::operator new(size); + + } else { + Allocator alloc{::beman::lazy::detail::find_allocator(a...)}; + void* ptr{allocator_traits::allocate(alloc, allocator_support::offset(size) + sizeof(Allocator))}; + new (allocator_support::get_allocator(ptr, size)) Allocator(alloc); + return ptr; + } } 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(); - allocator_traits::deallocate( - alloc, static_cast(ptr), allocator_support::offset(size) + sizeof(Allocator)); + if constexpr (::std::same_as>) { + ::operator delete(ptr, size); + } else { + Allocator* aptr{allocator_support::get_allocator(ptr, size)}; + Allocator alloc{*aptr}; + aptr->~Allocator(); + allocator_traits::deallocate( + alloc, static_cast(ptr), allocator_support::offset(size) + sizeof(Allocator)); + } } }; } // namespace beman::lazy::detail