From 0db85fbb7749f76b3b964ac3f29f3fe911925177 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Sun, 26 Oct 2025 22:23:04 +0100 Subject: [PATCH] Use operator_new_allocate/operator_delete_deallocate for test allocators --- test/allocator_argument_tester.hpp | 12 +++--------- test/dummy_test_allocator.hpp | 31 +++++++++--------------------- 2 files changed, 12 insertions(+), 31 deletions(-) diff --git a/test/allocator_argument_tester.hpp b/test/allocator_argument_tester.hpp index 909204f..7afd293 100644 --- a/test/allocator_argument_tester.hpp +++ b/test/allocator_argument_tester.hpp @@ -13,6 +13,7 @@ #include #include +#include #include template @@ -69,17 +70,10 @@ class propagation_test_allocator { return std::size_t(-1); } value_type* allocate(std::size_t count) - { return static_cast(::operator new(count * sizeof(value_type))); } + { return boost::container::dtl::operator_new_allocate(count); } void deallocate(value_type *ptr, std::size_t n) - { - (void)n; - # if defined(__cpp_sized_deallocation) - ::operator delete((void*)ptr, n * sizeof(value_type)); - #else - ::operator delete((void*)ptr); - # endif - } + { return boost::container::dtl::operator_delete_deallocate(ptr, n); } bool m_move_contructed; bool m_move_assigned; diff --git a/test/dummy_test_allocator.hpp b/test/dummy_test_allocator.hpp index 5e4d751..7a32186 100644 --- a/test/dummy_test_allocator.hpp +++ b/test/dummy_test_allocator.hpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -59,18 +60,11 @@ class simple_allocator simple_allocator(const simple_allocator &) {} - T* allocate(std::size_t n) - { return (T*) ::operator new(sizeof(T) * n); } + value_type* allocate(std::size_t count) + { return boost::container::dtl::operator_new_allocate(count); } - void deallocate(T *ptr, std::size_t n) BOOST_NOEXCEPT_OR_NOTHROW - { - (void)n; - # if defined(__cpp_sized_deallocation) - ::operator delete((void*)ptr, n * sizeof(T)); - #else - ::operator delete((void*)ptr); - # endif - } + void deallocate(value_type *ptr, std::size_t n) + { return boost::container::dtl::operator_delete_deallocate(ptr, n); } friend bool operator==(const simple_allocator &, const simple_allocator &) { return true; } @@ -181,18 +175,11 @@ class propagation_test_allocator static void reset_unique_id(unsigned id = 0) { unique_id_ = id; } - T* allocate(std::size_t n) - { return static_cast(::operator new(n * sizeof(T))); } + value_type* allocate(std::size_t count) + { return boost::container::dtl::operator_new_allocate(count); } - void deallocate(T *ptr, std::size_t n) BOOST_NOEXCEPT_OR_NOTHROW - { - (void)n; - # if defined(__cpp_sized_deallocation) - ::operator delete((void*)ptr, n * sizeof(T)); - #else - ::operator delete((void*)ptr); - # endif - } + void deallocate(value_type *ptr, std::size_t n) + { return boost::container::dtl::operator_delete_deallocate(ptr, n); } friend bool operator==(const propagation_test_allocator &a, const propagation_test_allocator &b) { return EqualIfEqualIds ? a.id_ == b.id_ : true; }