summaryrefslogtreecommitdiff
path: root/boost/functional/factory.hpp
diff options
context:
space:
mode:
authorDongHun Kwak <dh0128.kwak@samsung.com>2019-12-05 15:12:59 +0900
committerDongHun Kwak <dh0128.kwak@samsung.com>2019-12-05 15:12:59 +0900
commitb8cf34c691623e4ec329053cbbf68522a855882d (patch)
tree34da08632a99677f6b79ecb65e5b655a5b69a67f /boost/functional/factory.hpp
parent3fdc3e5ee96dca5b11d1694975a65200787eab86 (diff)
downloadboost-b8cf34c691623e4ec329053cbbf68522a855882d.tar.gz
boost-b8cf34c691623e4ec329053cbbf68522a855882d.tar.bz2
boost-b8cf34c691623e4ec329053cbbf68522a855882d.zip
Imported Upstream version 1.67.0upstream/1.67.0
Diffstat (limited to 'boost/functional/factory.hpp')
-rw-r--r--boost/functional/factory.hpp51
1 files changed, 43 insertions, 8 deletions
diff --git a/boost/functional/factory.hpp b/boost/functional/factory.hpp
index 67fee71d6c..92f67d9b60 100644
--- a/boost/functional/factory.hpp
+++ b/boost/functional/factory.hpp
@@ -12,6 +12,7 @@
# include <boost/preprocessor/iteration/iterate.hpp>
# include <boost/preprocessor/repetition/enum_params.hpp>
# include <boost/preprocessor/repetition/enum_binary_params.hpp>
+# include <boost/preprocessor/repetition/enum_trailing_params.hpp>
# include <new>
# include <boost/pointee.hpp>
@@ -74,15 +75,26 @@ namespace boost
template< class Pointer, class Allocator, factory_alloc_propagation AP >
class factory
+#if defined(BOOST_NO_CXX11_ALLOCATOR)
: private Allocator::template rebind< typename boost::pointee<
typename boost::remove_cv<Pointer>::type >::type >::other
+#else
+ : private std::allocator_traits<Allocator>::template rebind_alloc<
+ typename boost::pointee< typename boost::remove_cv<Pointer>::type >::type >
+#endif
{
public:
typedef typename boost::remove_cv<Pointer>::type result_type;
typedef typename boost::pointee<result_type>::type value_type;
+#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>
+ allocator_type;
+ typedef std::allocator_traits<allocator_type> allocator_traits;
+#endif
explicit factory(allocator_type const & a = allocator_type())
: allocator_type(a)
@@ -105,9 +117,16 @@ namespace boost
void operator()(value_type* ptr) const
{
- if (!! ptr) ptr->~value_type();
- const_cast<allocator_type*>(static_cast<allocator_type const*>(
- this))->deallocate(ptr,1);
+ if (!! ptr) {
+#if defined(BOOST_NO_CXX11_ALLOCATOR)
+ ptr->~value_type();
+ const_cast<allocator_type*>(static_cast<allocator_type const*>(
+ this))->deallocate(ptr,1);
+#else
+ allocator_traits::destroy(this->get_allocator(), ptr);
+ allocator_traits::deallocate(this->get_allocator(),ptr,1);
+#endif
+ }
}
};
@@ -162,14 +181,30 @@ 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>() );
+ {
+#if defined(BOOST_NO_CXX11_ALLOCATOR)
+ new(memory) value_type(BOOST_PP_ENUM_PARAMS(N,a));
+#else
+ allocator_traits::construct(this->get_allocator(), memory
+ BOOST_PP_ENUM_TRAILING_PARAMS(N,a));
+#endif
}
- 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;
+ }
+
+ return make_pointer(memory, boost::non_type<factory_alloc_propagation,AP>());
}
# endif
# undef N