Fixes for VC2005 and replaced some remaining placement news/destroys with allocator traits

[SVN r76262]
This commit is contained in:
Ion Gaztañaga
2012-01-01 18:48:00 +00:00
parent 3f3a63d92a
commit ccff43c8fb
5 changed files with 67 additions and 145 deletions

View File

@@ -1069,7 +1069,10 @@ class deque : protected deque_base<T, A>
{
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<T, A>
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<T, A>
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 <class Integer>
@@ -1827,7 +1841,10 @@ class deque : protected deque_base<T, A>
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<T, A>
// 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;

View File

@@ -50,130 +50,7 @@ inline void construct_in_place(A &a, T *dest, emplace_iterator<U, EF, D> ei)
{
ei.construct_in_place(a, dest);
}
/*
template<class InIt, class OutIt>
struct optimize_assign
{
static const bool value = false;
};
template<class T>
struct optimize_assign<const T*, T*>
{
static const bool value = boost::has_trivial_assign<T>::value;
};
template<class T>
struct optimize_assign<T*, T*>
: public optimize_assign<const T*, T*>
{};
template<class InIt, class OutIt>
struct optimize_copy
{
static const bool value = false;
};
template<class T>
struct optimize_copy<const T*, T*>
{
static const bool value = boost::has_trivial_copy<T>::value;
};
template<class T>
struct optimize_copy<T*, T*>
: public optimize_copy<const T*, T*>
{};
template<class InIt, class OutIt> inline
OutIt copy_n_dispatch(InIt first, typename std::iterator_traits<InIt>::difference_type length, OutIt dest, container_detail::bool_<false>)
{
for (; length--; ++dest, ++first)
*dest = *first;
return dest;
}
template<class T> inline
T *copy_n_dispatch(const T *first, typename std::iterator_traits<const T*>::difference_type length, T *dest, container_detail::bool_<true>)
{
std::size_t size = length*sizeof(T);
return (static_cast<T*>(std::memmove(dest, first, size))) + size;
}
template<class InIt, class OutIt> inline
OutIt copy_n(InIt first, typename std::iterator_traits<InIt>::difference_type length, OutIt dest)
{
const bool do_optimized_assign = optimize_assign<InIt, OutIt>::value;
return copy_n_dispatch(first, length, dest, container_detail::bool_<do_optimized_assign>());
}
template<class InIt, class FwdIt> inline
FwdIt uninitialized_copy_n_dispatch
(InIt first,
typename std::iterator_traits<InIt>::difference_type count,
FwdIt dest, container_detail::bool_<false>)
{
typedef typename std::iterator_traits<FwdIt>::value_type value_type;
//Save initial destination position
FwdIt dest_init = dest;
typename std::iterator_traits<InIt>::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<class T> inline
T *uninitialized_copy_n_dispatch(const T *first, typename std::iterator_traits<const T*>::difference_type length, T *dest, container_detail::bool_<true>)
{
std::size_t size = length*sizeof(T);
return (static_cast<T*>(std::memmove(dest, first, size))) + size;
}
template<class InIt, class FwdIt> inline
FwdIt uninitialized_copy_n
(InIt first,
typename std::iterator_traits<InIt>::difference_type count,
FwdIt dest)
{
const bool do_optimized_copy = optimize_copy<InIt, FwdIt>::value;
return uninitialized_copy_n_dispatch(first, count, dest, container_detail::bool_<do_optimized_copy>());
}
// 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 <class InpIt1, class InpIt2, class FwdIt>
FwdIt uninitialized_copy_copy
(InpIt1 first1, InpIt1 last1, InpIt2 first2, InpIt2 last2, FwdIt result)
{
typedef typename std::iterator_traits<FwdIt>::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 {

View File

@@ -446,7 +446,7 @@ class stable_vector
template<class AllocatorVersion>
node_type_ptr_t allocate_one(AllocatorVersion,
typename boost::container::container_detail::enable_if_c
<boost::container::container_detail::is_same<AllocatorVersion, allocator_v2>
<!boost::container::container_detail::is_same<AllocatorVersion, allocator_v1>
::value>::type * = 0)
{ return node_alloc().allocate_one(); }
@@ -463,7 +463,7 @@ class stable_vector
template<class AllocatorVersion>
void deallocate_one(node_type_ptr_t p, AllocatorVersion,
typename boost::container::container_detail::enable_if_c
<boost::container::container_detail::is_same<AllocatorVersion, allocator_v2>
<!boost::container::container_detail::is_same<AllocatorVersion, allocator_v1>
::value>::type * = 0)
{ node_alloc().deallocate_one(p); }
@@ -1316,7 +1316,7 @@ class stable_vector
template<class AllocatorVersion>
void clear_pool(AllocatorVersion,
typename boost::container::container_detail::enable_if_c
<boost::container::container_detail::is_same<AllocatorVersion, allocator_v2>
<!boost::container::container_detail::is_same<AllocatorVersion, allocator_v1>
::value>::type * = 0)
{
if(!impl.empty() && impl.back()){
@@ -1355,7 +1355,7 @@ class stable_vector
template<class AllocatorVersion>
void add_to_pool(size_type n, AllocatorVersion,
typename boost::container::container_detail::enable_if_c
<boost::container::container_detail::is_same<AllocatorVersion, allocator_v2>
<!boost::container::container_detail::is_same<AllocatorVersion, allocator_v1>
::value>::type * = 0)
{
void_ptr &pool_first_ref = impl.end()[-2];
@@ -1473,7 +1473,7 @@ class stable_vector
template<class AllocatorVersion>
iterator priv_erase(const_iterator first, const_iterator last, AllocatorVersion,
typename boost::container::container_detail::enable_if_c
<boost::container::container_detail::is_same<AllocatorVersion, allocator_v2>
<!boost::container::container_detail::is_same<AllocatorVersion, allocator_v1>
::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<node_allocator_type>::
destroy(this->node_alloc(), container_detail::to_raw_pointer(n));
this->put_in_pool(n);
}

View File

@@ -127,7 +127,10 @@ class basic_string_base
{
if(!this->is_short()){
this->deallocate_block();
static_cast<long_t*>(static_cast<void*>(&this->members_.m_repr.r))->~long_t();
allocator_traits_type::destroy
( this->alloc()
, static_cast<long_t*>(static_cast<void*>(&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<long_t*>(static_cast<void*>(&this->members_.m_repr.r))->~long_t();
allocator_traits_type::destroy
( this->alloc()
, static_cast<long_t*>(static_cast<void*>(&this->members_.m_repr.r))
);
}
else{
new(static_cast<void*>(&this->members_.m_repr.r))long_t();
allocator_traits_type::construct
( this->alloc()
, static_cast<long_t*>(static_cast<void*>(&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)
{

View File

@@ -1328,7 +1328,7 @@ class vector : private container_detail::vector_alloc_holder<A>
template<class AllocVersion>
void priv_shrink_to_fit(AllocVersion
, typename container_detail::enable_if_c<
container_detail::is_same<AllocVersion, allocator_v2>::value >::type * = 0)
!container_detail::is_same<AllocVersion, allocator_v1>::value >::type * = 0)
{
if(this->members_.m_capacity){
if(!size()){