diff --git a/include/boost/smart_ptr/allocate_shared_array.hpp b/include/boost/smart_ptr/allocate_shared_array.hpp index 6257c55..b43b43d 100644 --- a/include/boost/smart_ptr/allocate_shared_array.hpp +++ b/include/boost/smart_ptr/allocate_shared_array.hpp @@ -350,37 +350,36 @@ sp_array_default(T* storage, std::size_t size) } #endif -template +template struct sp_less_align { enum { - value = (boost::alignment_of::value) < - (boost::alignment_of::value) + value = (boost::alignment_of::value) < N }; }; -template -BOOST_CONSTEXPR inline std::size_t -sp_objects(std::size_t size) BOOST_NOEXCEPT -{ - return size / sizeof(T); -} - -template +template BOOST_CONSTEXPR inline -typename sp_enable::value, std::size_t>::type +typename sp_enable::value, std::size_t>::type sp_align(std::size_t size) BOOST_NOEXCEPT { - return (sizeof(T) * size + sizeof(U) - 1) & ~(sizeof(U) - 1); + return (sizeof(T) * size + N - 1) & ~(N - 1); } -template +template BOOST_CONSTEXPR inline -typename sp_enable::value, std::size_t>::type +typename sp_enable::value, std::size_t>::type sp_align(std::size_t size) BOOST_NOEXCEPT { return sizeof(T) * size; } +template +BOOST_CONSTEXPR inline std::size_t +sp_types(std::size_t size) BOOST_NOEXCEPT +{ + return (size + sizeof(T) - 1) / sizeof(T); +} + template class sp_size_array_deleter { public: @@ -667,19 +666,17 @@ public: value_type* allocate(std::size_t count) { type_allocator allocator(allocator_); - std::size_t head = sp_align(count); - std::size_t tail = sp_align(size_); - std::size_t size = sp_objects(head + tail); + std::size_t node = sp_align(count); + std::size_t size = sp_types(node + sizeof(T) * size_); type* address = allocator.allocate(size); - *result_ = address + sp_objects(head); + *result_ = reinterpret_cast(address) + node; return reinterpret_cast(address); } void deallocate(value_type* value, std::size_t count) { type_allocator allocator(allocator_); - std::size_t head = sp_align(count); - std::size_t tail = sp_align(size_); - std::size_t size = sp_objects(head + tail); + std::size_t node = sp_align(count); + std::size_t size = sp_types(node + sizeof(T) * size_); allocator.deallocate(reinterpret_cast(value), size); }