Use operator_new_allocate/operator_delete_deallocate for test allocators

This commit is contained in:
Ion Gaztañaga
2025-10-26 22:23:04 +01:00
parent cae7d2c306
commit 0db85fbb77
2 changed files with 12 additions and 31 deletions

View File

@@ -13,6 +13,7 @@
#include <boost/container/uses_allocator.hpp>
#include <boost/container/detail/mpl.hpp>
#include <boost/container/detail/operator_new_helpers.hpp>
#include <boost/move/core.hpp>
template<class T, unsigned int Id, bool HasTrueTypes = false>
@@ -69,17 +70,10 @@ class propagation_test_allocator
{ return std::size_t(-1); }
value_type* allocate(std::size_t count)
{ return static_cast<value_type*>(::operator new(count * sizeof(value_type))); }
{ return boost::container::dtl::operator_new_allocate<value_type>(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<T>(ptr, n); }
bool m_move_contructed;
bool m_move_assigned;

View File

@@ -31,6 +31,7 @@
#include <boost/container/detail/multiallocation_chain.hpp>
#include <boost/container/detail/type_traits.hpp>
#include <boost/container/detail/version_type.hpp>
#include <boost/container/detail/operator_new_helpers.hpp>
#include <boost/move/utility_core.hpp>
#include <boost/move/adl_move_swap.hpp>
@@ -59,18 +60,11 @@ class simple_allocator
simple_allocator(const simple_allocator<U> &)
{}
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<value_type>(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<T>(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<T*>(::operator new(n * sizeof(T))); }
value_type* allocate(std::size_t count)
{ return boost::container::dtl::operator_new_allocate<value_type>(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<T>(ptr, n); }
friend bool operator==(const propagation_test_allocator &a, const propagation_test_allocator &b)
{ return EqualIfEqualIds ? a.id_ == b.id_ : true; }