diff --git a/include/boost/container/deque.hpp b/include/boost/container/deque.hpp index d3b4732..79d03f9 100644 --- a/include/boost/container/deque.hpp +++ b/include/boost/container/deque.hpp @@ -1069,7 +1069,10 @@ class deque : protected deque_base { if (this->members_.m_finish.m_cur != this->members_.m_finish.m_first) { --this->members_.m_finish.m_cur; - container_detail::to_raw_pointer(this->members_.m_finish.m_cur)->~value_type(); + allocator_traits_type::destroy + ( this->alloc() + , container_detail::to_raw_pointer(this->members_.m_finish.m_cur) + ); } else this->priv_pop_back_aux(); @@ -1083,7 +1086,10 @@ class deque : protected deque_base void pop_front() BOOST_CONTAINER_NOEXCEPT { if (this->members_.m_start.m_cur != this->members_.m_start.m_last - 1) { - container_detail::to_raw_pointer(this->members_.m_start.m_cur)->~value_type(); + allocator_traits_type::destroy + ( this->alloc() + , container_detail::to_raw_pointer(this->members_.m_start.m_cur) + ); ++this->members_.m_start.m_cur; } else @@ -1598,14 +1604,22 @@ class deque : protected deque_base void priv_destroy_range(iterator p, iterator p2) { - for(;p != p2; ++p) - container_detail::to_raw_pointer(&*p)->~value_type(); + for(;p != p2; ++p){ + allocator_traits_type::destroy + ( this->alloc() + , container_detail::to_raw_pointer(&*p) + ); + } } void priv_destroy_range(pointer p, pointer p2) { - for(;p != p2; ++p) - container_detail::to_raw_pointer(&*p)->~value_type(); + for(;p != p2; ++p){ + allocator_traits_type::destroy + ( this->alloc() + , container_detail::to_raw_pointer(&*p) + ); + } } template @@ -1827,7 +1841,10 @@ class deque : protected deque_base this->priv_deallocate_node(this->members_.m_finish.m_first); this->members_.m_finish.priv_set_node(this->members_.m_finish.m_node - 1); this->members_.m_finish.m_cur = this->members_.m_finish.m_last - 1; - container_detail::to_raw_pointer(this->members_.m_finish.m_cur)->~value_type(); + allocator_traits_type::destroy + ( this->alloc() + , container_detail::to_raw_pointer(this->members_.m_finish.m_cur) + ); } // Called only if this->members_.m_start.m_cur == this->members_.m_start.m_last - 1. Note that @@ -1836,7 +1853,10 @@ class deque : protected deque_base // must have at least two nodes. void priv_pop_front_aux() { - container_detail::to_raw_pointer(this->members_.m_start.m_cur)->~value_type(); + allocator_traits_type::destroy + ( this->alloc() + , container_detail::to_raw_pointer(this->members_.m_start.m_cur) + ); this->priv_deallocate_node(this->members_.m_start.m_first); this->members_.m_start.priv_set_node(this->members_.m_start.m_node + 1); this->members_.m_start.m_cur = this->members_.m_start.m_first; diff --git a/include/boost/container/detail/algorithms.hpp b/include/boost/container/detail/algorithms.hpp index f0e897c..a2713f5 100644 --- a/include/boost/container/detail/algorithms.hpp +++ b/include/boost/container/detail/algorithms.hpp @@ -50,130 +50,7 @@ inline void construct_in_place(A &a, T *dest, emplace_iterator ei) { ei.construct_in_place(a, dest); } -/* -template -struct optimize_assign -{ - static const bool value = false; -}; -template -struct optimize_assign -{ - static const bool value = boost::has_trivial_assign::value; -}; - -template -struct optimize_assign - : public optimize_assign -{}; - -template -struct optimize_copy -{ - static const bool value = false; -}; - -template -struct optimize_copy -{ - static const bool value = boost::has_trivial_copy::value; -}; - -template -struct optimize_copy - : public optimize_copy -{}; - -template inline -OutIt copy_n_dispatch(InIt first, typename std::iterator_traits::difference_type length, OutIt dest, container_detail::bool_) -{ - for (; length--; ++dest, ++first) - *dest = *first; - return dest; -} - -template inline -T *copy_n_dispatch(const T *first, typename std::iterator_traits::difference_type length, T *dest, container_detail::bool_) -{ - std::size_t size = length*sizeof(T); - return (static_cast(std::memmove(dest, first, size))) + size; -} - -template inline -OutIt copy_n(InIt first, typename std::iterator_traits::difference_type length, OutIt dest) -{ - const bool do_optimized_assign = optimize_assign::value; - return copy_n_dispatch(first, length, dest, container_detail::bool_()); -} - -template inline -FwdIt uninitialized_copy_n_dispatch - (InIt first, - typename std::iterator_traits::difference_type count, - FwdIt dest, container_detail::bool_) -{ - typedef typename std::iterator_traits::value_type value_type; - //Save initial destination position - FwdIt dest_init = dest; - typename std::iterator_traits::difference_type new_count = count+1; - - BOOST_TRY{ - //Try to build objects - for (; --new_count; ++dest, ++first){ - construct_in_place(container_detail::to_raw_pointer(&*dest), first); - } - } - BOOST_CATCH(...){ - //Call destructors - new_count = count - new_count; - for (; new_count--; ++dest_init){ - container_detail::to_raw_pointer(&*dest_init)->~value_type(); - } - BOOST_RETHROW - } - BOOST_CATCH_END - return dest; -} -template inline -T *uninitialized_copy_n_dispatch(const T *first, typename std::iterator_traits::difference_type length, T *dest, container_detail::bool_) -{ - std::size_t size = length*sizeof(T); - return (static_cast(std::memmove(dest, first, size))) + size; -} - -template inline -FwdIt uninitialized_copy_n - (InIt first, - typename std::iterator_traits::difference_type count, - FwdIt dest) -{ - const bool do_optimized_copy = optimize_copy::value; - return uninitialized_copy_n_dispatch(first, count, dest, container_detail::bool_()); -} - -// uninitialized_copy_copy -// Copies [first1, last1) into [result, result + (last1 - first1)), and -// copies [first2, last2) into -// [result + (last1 - first1), result + (last1 - first1) + (last2 - first2)). -template -FwdIt uninitialized_copy_copy - (InpIt1 first1, InpIt1 last1, InpIt2 first2, InpIt2 last2, FwdIt result) -{ - typedef typename std::iterator_traits::value_type value_type; - FwdIt mid = std::uninitialized_copy(first1, last1, result); - BOOST_TRY { - return std::uninitialized_copy(first2, last2, mid); - } - BOOST_CATCH(...){ - for(;result != mid; ++result){ - container_detail::to_raw_pointer(&*result)->~value_type(); - } - BOOST_RETHROW - } - BOOST_CATCH_END -} -*/ } //namespace container { } //namespace boost { diff --git a/include/boost/container/stable_vector.hpp b/include/boost/container/stable_vector.hpp index 8c3287a..a871cee 100644 --- a/include/boost/container/stable_vector.hpp +++ b/include/boost/container/stable_vector.hpp @@ -446,7 +446,7 @@ class stable_vector template node_type_ptr_t allocate_one(AllocatorVersion, typename boost::container::container_detail::enable_if_c - + ::value>::type * = 0) { return node_alloc().allocate_one(); } @@ -463,7 +463,7 @@ class stable_vector template void deallocate_one(node_type_ptr_t p, AllocatorVersion, typename boost::container::container_detail::enable_if_c - + ::value>::type * = 0) { node_alloc().deallocate_one(p); } @@ -1316,7 +1316,7 @@ class stable_vector template void clear_pool(AllocatorVersion, typename boost::container::container_detail::enable_if_c - + ::value>::type * = 0) { if(!impl.empty() && impl.back()){ @@ -1355,7 +1355,7 @@ class stable_vector template void add_to_pool(size_type n, AllocatorVersion, typename boost::container::container_detail::enable_if_c - + ::value>::type * = 0) { void_ptr &pool_first_ref = impl.end()[-2]; @@ -1473,7 +1473,7 @@ class stable_vector template iterator priv_erase(const_iterator first, const_iterator last, AllocatorVersion, typename boost::container::container_detail::enable_if_c - + ::value>::type * = 0) { STABLE_VECTOR_CHECK_INVARIANT; @@ -1542,7 +1542,8 @@ class stable_vector void delete_node(const void_ptr &p) { node_type_ptr_t n(node_ptr_cast(p)); - n->~node_type_t(); + allocator_traits:: + destroy(this->node_alloc(), container_detail::to_raw_pointer(n)); this->put_in_pool(n); } diff --git a/include/boost/container/string.hpp b/include/boost/container/string.hpp index feb62cf..a81d930 100644 --- a/include/boost/container/string.hpp +++ b/include/boost/container/string.hpp @@ -127,7 +127,10 @@ class basic_string_base { if(!this->is_short()){ this->deallocate_block(); - static_cast(static_cast(&this->members_.m_repr.r))->~long_t(); + allocator_traits_type::destroy + ( this->alloc() + , static_cast(static_cast(&this->members_.m_repr.r)) + ); } } @@ -240,10 +243,16 @@ class basic_string_base void is_short(bool yes) { if(yes && !this->is_short()){ - static_cast(static_cast(&this->members_.m_repr.r))->~long_t(); + allocator_traits_type::destroy + ( this->alloc() + , static_cast(static_cast(&this->members_.m_repr.r)) + ); } else{ - new(static_cast(&this->members_.m_repr.r))long_t(); + allocator_traits_type::construct + ( this->alloc() + , static_cast(static_cast(&this->members_.m_repr.r)) + ); } this->members_.m_repr.s.h.is_short = yes; } @@ -314,16 +323,31 @@ class basic_string_base } void construct(pointer p, const value_type &value = value_type()) - { new((void*)container_detail::to_raw_pointer(p)) value_type(value); } + { + allocator_traits_type::construct + ( this->alloc() + , container_detail::to_raw_pointer(p) + , value + ); + } void destroy(pointer p, size_type n) { - for(; n--; ++p) - container_detail::to_raw_pointer(p)->~value_type(); + for(; n--; ++p){ + allocator_traits_type::destroy + ( this->alloc() + , container_detail::to_raw_pointer(p) + ); + } } void destroy(pointer p) - { container_detail::to_raw_pointer(p)->~value_type(); } + { + allocator_traits_type::destroy + ( this->alloc() + , container_detail::to_raw_pointer(p) + ); + } void allocate_initial_block(size_type n) { diff --git a/include/boost/container/vector.hpp b/include/boost/container/vector.hpp index 01483f9..186bee5 100644 --- a/include/boost/container/vector.hpp +++ b/include/boost/container/vector.hpp @@ -1328,7 +1328,7 @@ class vector : private container_detail::vector_alloc_holder template void priv_shrink_to_fit(AllocVersion , typename container_detail::enable_if_c< - container_detail::is_same::value >::type * = 0) + !container_detail::is_same::value >::type * = 0) { if(this->members_.m_capacity){ if(!size()){