mirror of
https://github.com/boostorg/functional.git
synced 2025-07-30 04:27:18 +02:00
Use alloator_traits for allocate/deallocate
This commit is contained in:
@ -88,10 +88,12 @@ namespace boost
|
|||||||
|
|
||||||
#if defined(BOOST_NO_CXX11_ALLOCATOR)
|
#if defined(BOOST_NO_CXX11_ALLOCATOR)
|
||||||
typedef typename Allocator::template rebind<value_type>::other
|
typedef typename Allocator::template rebind<value_type>::other
|
||||||
|
allocator_type;
|
||||||
#else
|
#else
|
||||||
typedef typename std::allocator_traits<Allocator>::template rebind_alloc<value_type>
|
typedef typename std::allocator_traits<Allocator>::template rebind_alloc<value_type>
|
||||||
#endif
|
|
||||||
allocator_type;
|
allocator_type;
|
||||||
|
typedef std::allocator_traits<allocator_type> allocator_traits;
|
||||||
|
#endif
|
||||||
|
|
||||||
explicit factory(allocator_type const & a = allocator_type())
|
explicit factory(allocator_type const & a = allocator_type())
|
||||||
: allocator_type(a)
|
: allocator_type(a)
|
||||||
@ -115,8 +117,12 @@ namespace boost
|
|||||||
void operator()(value_type* ptr) const
|
void operator()(value_type* ptr) const
|
||||||
{
|
{
|
||||||
if (!! ptr) ptr->~value_type();
|
if (!! ptr) ptr->~value_type();
|
||||||
|
#if defined(BOOST_NO_CXX11_ALLOCATOR)
|
||||||
const_cast<allocator_type*>(static_cast<allocator_type const*>(
|
const_cast<allocator_type*>(static_cast<allocator_type const*>(
|
||||||
this))->deallocate(ptr,1);
|
this))->deallocate(ptr,1);
|
||||||
|
#else
|
||||||
|
allocator_traits::deallocate(this->get_allocator(),ptr,1);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -171,14 +177,25 @@ namespace boost
|
|||||||
# endif
|
# endif
|
||||||
inline result_type operator()(BOOST_PP_ENUM_BINARY_PARAMS(N,T,& a)) const
|
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);
|
value_type* memory = this->get_allocator().allocate(1);
|
||||||
|
#else
|
||||||
|
value_type* memory = allocator_traits::allocate(this->get_allocator(), 1);
|
||||||
|
#endif
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return make_pointer(
|
return make_pointer(
|
||||||
new(memory) value_type(BOOST_PP_ENUM_PARAMS(N,a)),
|
new(memory) value_type(BOOST_PP_ENUM_PARAMS(N,a)),
|
||||||
boost::non_type<factory_alloc_propagation,AP>() );
|
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
|
# endif
|
||||||
# undef N
|
# undef N
|
||||||
|
Reference in New Issue
Block a user