Use alloator_traits for allocate/deallocate

This commit is contained in:
Daniel James
2017-12-17 12:05:54 +00:00
parent 270d59be4e
commit 65a6556800

View File

@ -88,10 +88,12 @@ namespace boost
#if defined(BOOST_NO_CXX11_ALLOCATOR)
typedef typename Allocator::template rebind<value_type>::other
allocator_type;
#else
typedef typename std::allocator_traits<Allocator>::template rebind_alloc<value_type>
#endif
allocator_type;
typedef std::allocator_traits<allocator_type> allocator_traits;
#endif
explicit factory(allocator_type const & a = allocator_type())
: allocator_type(a)
@ -115,8 +117,12 @@ namespace boost
void operator()(value_type* ptr) const
{
if (!! ptr) ptr->~value_type();
#if defined(BOOST_NO_CXX11_ALLOCATOR)
const_cast<allocator_type*>(static_cast<allocator_type const*>(
this))->deallocate(ptr,1);
#else
allocator_traits::deallocate(this->get_allocator(),ptr,1);
#endif
}
};
@ -171,14 +177,25 @@ namespace boost
# endif
inline result_type operator()(BOOST_PP_ENUM_BINARY_PARAMS(N,T,& a)) const
{
#if defined(BOOST_NO_CXX11_ALLOCATOR)
value_type* memory = this->get_allocator().allocate(1);
#else
value_type* memory = allocator_traits::allocate(this->get_allocator(), 1);
#endif
try
{
{
return make_pointer(
new(memory) value_type(BOOST_PP_ENUM_PARAMS(N,a)),
boost::non_type<factory_alloc_propagation,AP>() );
}
catch (...) { this->get_allocator().deallocate(memory,1); throw; }
catch (...) {
#if defined(BOOST_NO_CXX11_ALLOCATOR)
this->get_allocator().deallocate(memory,1);
#else
allocator_traits::deallocate(this->get_allocator(), memory, 1);
#endif
throw;
}
}
# endif
# undef N