|
20 | 20 |
|
21 | 21 | #include <boost/container/detail/std_fwd.hpp> |
22 | 22 | #include <boost/container/throw_exception.hpp> |
| 23 | +#include <boost/container/detail/type_traits.hpp> |
23 | 24 |
|
24 | 25 | namespace boost { |
25 | 26 | namespace container { |
26 | 27 | namespace dtl { |
27 | 28 |
|
28 | | -template <class T> |
29 | | -T* operator_new_allocate(std::size_t count) |
| 29 | +BOOST_CONTAINER_FORCEINLINE void* operator_new_raw_allocate(const std::size_t size, const std::size_t alignment) |
30 | 30 | { |
31 | | - const std::size_t max_count = std::size_t(-1)/(2*sizeof(T)); |
32 | | - if(BOOST_UNLIKELY(count > max_count)) |
33 | | - throw_bad_alloc(); |
| 31 | + (void)alignment; |
34 | 32 | #if defined(__cpp_aligned_new) |
35 | | - BOOST_IF_CONSTEXPR(__STDCPP_DEFAULT_NEW_ALIGNMENT__ < alignof(T)) { |
36 | | - return static_cast<T*>(::operator new(count*sizeof(T), std::align_val_t(alignof(T)))); |
| 33 | + if(__STDCPP_DEFAULT_NEW_ALIGNMENT__ < alignment) { |
| 34 | + return ::operator new(size, std::align_val_t(alignment)); |
37 | 35 | } |
38 | 36 | #endif |
39 | | - return static_cast<T*>(::operator new(count*sizeof(T))); |
| 37 | + return ::operator new(size); |
40 | 38 | } |
41 | 39 |
|
42 | | -template <class T> |
43 | | -void operator_delete_deallocate(T* ptr, std::size_t n) BOOST_NOEXCEPT_OR_NOTHROW |
| 40 | +BOOST_CONTAINER_FORCEINLINE void operator_delete_raw_deallocate |
| 41 | + (void* const ptr, const std::size_t size, const std::size_t alignment) BOOST_NOEXCEPT_OR_NOTHROW |
44 | 42 | { |
45 | | - (void)n; |
| 43 | + (void)size; |
| 44 | + (void)alignment; |
46 | 45 | #ifdef __cpp_aligned_new |
47 | | - BOOST_IF_CONSTEXPR(__STDCPP_DEFAULT_NEW_ALIGNMENT__ < alignof(T)) { |
| 46 | + if(__STDCPP_DEFAULT_NEW_ALIGNMENT__ < alignment) { |
48 | 47 | # if defined(__cpp_sized_deallocation) |
49 | | - ::operator delete((void*)ptr, n * sizeof(T), std::align_val_t(alignof(T))); |
| 48 | + ::operator delete(ptr, size, std::align_val_t(alignment)); |
50 | 49 | #else |
51 | | - ::operator delete((void*)ptr, std::align_val_t(alignof(T))); |
| 50 | + ::operator delete(ptr, std::align_val_t(alignment)); |
52 | 51 | # endif |
53 | 52 | return; |
54 | 53 | } |
55 | 54 | #endif |
56 | 55 |
|
57 | 56 | # if defined(__cpp_sized_deallocation) |
58 | | - ::operator delete((void*)ptr, n * sizeof(T)); |
| 57 | + ::operator delete(ptr, size); |
59 | 58 | #else |
60 | | - ::operator delete((void*)ptr); |
| 59 | + ::operator delete(ptr); |
61 | 60 | # endif |
62 | 61 | } |
63 | 62 |
|
| 63 | +template <class T> |
| 64 | +BOOST_CONTAINER_FORCEINLINE T* operator_new_allocate(std::size_t count) |
| 65 | +{ |
| 66 | + const std::size_t max_count = std::size_t(-1)/(2*sizeof(T)); |
| 67 | + if(BOOST_UNLIKELY(count > max_count)) |
| 68 | + throw_bad_alloc(); |
| 69 | + return static_cast<T*>(operator_new_raw_allocate(count*sizeof(T), alignment_of<T>::value)); |
| 70 | +} |
| 71 | + |
| 72 | +template <class T> |
| 73 | +BOOST_CONTAINER_FORCEINLINE void operator_delete_deallocate(T* ptr, std::size_t n) BOOST_NOEXCEPT_OR_NOTHROW |
| 74 | +{ |
| 75 | + operator_delete_raw_deallocate((void*)ptr, n * sizeof(T), alignment_of<T>::value); |
| 76 | +} |
| 77 | + |
| 78 | + |
64 | 79 | } //namespace dtl { |
65 | 80 | } //namespace container { |
66 | 81 | } //namespace boost { |
|
0 commit comments