From 65a65568003d6e63f8d6b2bcc88d7a9dc8a521d5 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Sun, 17 Dec 2017 12:05:54 +0000 Subject: [PATCH] Use alloator_traits for allocate/deallocate --- include/boost/functional/factory.hpp | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/include/boost/functional/factory.hpp b/include/boost/functional/factory.hpp index 94c55af..70a6f9c 100644 --- a/include/boost/functional/factory.hpp +++ b/include/boost/functional/factory.hpp @@ -88,10 +88,12 @@ namespace boost #if defined(BOOST_NO_CXX11_ALLOCATOR) typedef typename Allocator::template rebind::other + allocator_type; #else typedef typename std::allocator_traits::template rebind_alloc -#endif allocator_type; + typedef std::allocator_traits 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(static_cast( 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() ); } - 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