Use allocator access utilities

This commit is contained in:
Glen Fernandes
2020-05-21 22:28:42 -04:00
parent 1e5df9d551
commit 121312cc22
3 changed files with 19 additions and 53 deletions

View File

@ -74,7 +74,7 @@ inline typename enable_if_<is_unbounded_array<T>::value,
allocate_local_shared(const A& allocator, std::size_t count)
{
typedef typename detail::sp_array_element<T>::type element;
typedef typename detail::sp_bind_allocator<A, element>::type other;
typedef typename allocator_rebind<A, element>::type other;
typedef detail::lsp_array_state<other> state;
typedef detail::sp_array_base<state> base;
detail::sp_array_result<other, base> result(allocator, count);
@ -97,7 +97,7 @@ allocate_local_shared(const A& allocator)
count = extent<T>::value
};
typedef typename detail::sp_array_element<T>::type element;
typedef typename detail::sp_bind_allocator<A, element>::type other;
typedef typename allocator_rebind<A, element>::type other;
typedef detail::lsp_size_array_state<other, count> state;
typedef detail::sp_array_base<state> base;
detail::sp_array_result<other, base> result(allocator, count);
@ -118,7 +118,7 @@ allocate_local_shared(const A& allocator, std::size_t count,
const typename remove_extent<T>::type& value)
{
typedef typename detail::sp_array_element<T>::type element;
typedef typename detail::sp_bind_allocator<A, element>::type other;
typedef typename allocator_rebind<A, element>::type other;
typedef detail::lsp_array_state<other> state;
typedef detail::sp_array_base<state> base;
detail::sp_array_result<other, base> result(allocator, count);
@ -142,7 +142,7 @@ allocate_local_shared(const A& allocator,
count = extent<T>::value
};
typedef typename detail::sp_array_element<T>::type element;
typedef typename detail::sp_bind_allocator<A, element>::type other;
typedef typename allocator_rebind<A, element>::type other;
typedef detail::lsp_size_array_state<other, count> state;
typedef detail::sp_array_base<state> base;
detail::sp_array_result<other, base> result(allocator, count);

View File

@ -8,6 +8,7 @@ Distributed under the Boost Software License, Version 1.0.
#ifndef BOOST_SMART_PTR_ALLOCATE_SHARED_ARRAY_HPP
#define BOOST_SMART_PTR_ALLOCATE_SHARED_ARRAY_HPP
#include <boost/core/allocator_access.hpp>
#include <boost/core/alloc_construct.hpp>
#include <boost/core/first_scalar.hpp>
#include <boost/smart_ptr/shared_ptr.hpp>
@ -57,18 +58,6 @@ struct sp_align_up {
};
};
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
template<class A, class T>
struct sp_bind_allocator {
typedef typename std::allocator_traits<A>::template rebind_alloc<T> type;
};
#else
template<class A, class T>
struct sp_bind_allocator {
typedef typename A::template rebind<T>::other type;
};
#endif
template<class T>
BOOST_CONSTEXPR inline std::size_t
sp_objects(std::size_t size) BOOST_SP_NOEXCEPT
@ -171,7 +160,7 @@ public:
}
private:
typename sp_bind_allocator<A, type>::type other_;
typename boost::allocator_rebind<A, type>::type other_;
std::size_t size_;
};
@ -273,7 +262,7 @@ inline typename enable_if_<is_unbounded_array<T>::value, shared_ptr<T> >::type
allocate_shared(const A& allocator, std::size_t count)
{
typedef typename detail::sp_array_element<T>::type element;
typedef typename detail::sp_bind_allocator<A, element>::type other;
typedef typename allocator_rebind<A, element>::type other;
typedef detail::sp_array_state<other> state;
typedef detail::sp_array_base<state> base;
detail::sp_array_result<other, base> result(allocator, count);
@ -293,7 +282,7 @@ allocate_shared(const A& allocator)
count = extent<T>::value
};
typedef typename detail::sp_array_element<T>::type element;
typedef typename detail::sp_bind_allocator<A, element>::type other;
typedef typename allocator_rebind<A, element>::type other;
typedef detail::sp_size_array_state<other, extent<T>::value> state;
typedef detail::sp_array_base<state> base;
detail::sp_array_result<other, base> result(allocator, count);
@ -311,7 +300,7 @@ allocate_shared(const A& allocator, std::size_t count,
const typename remove_extent<T>::type& value)
{
typedef typename detail::sp_array_element<T>::type element;
typedef typename detail::sp_bind_allocator<A, element>::type other;
typedef typename allocator_rebind<A, element>::type other;
typedef detail::sp_array_state<other> state;
typedef detail::sp_array_base<state> base;
detail::sp_array_result<other, base> result(allocator, count);
@ -332,7 +321,7 @@ allocate_shared(const A& allocator,
count = extent<T>::value
};
typedef typename detail::sp_array_element<T>::type element;
typedef typename detail::sp_bind_allocator<A, element>::type other;
typedef typename allocator_rebind<A, element>::type other;
typedef detail::sp_size_array_state<other, extent<T>::value> state;
typedef detail::sp_array_base<state> base;
detail::sp_array_result<other, base> result(allocator, count);

View File

@ -10,6 +10,7 @@ Distributed under the Boost Software License, Version 1.0.
#include <boost/smart_ptr/detail/sp_noexcept.hpp>
#include <boost/smart_ptr/detail/sp_nullptr_t.hpp>
#include <boost/core/allocator_access.hpp>
#include <boost/core/alloc_construct.hpp>
#include <boost/core/empty_value.hpp>
#include <boost/core/first_scalar.hpp>
@ -61,30 +62,6 @@ struct sp_alloc_value {
boost::remove_extent<T>::type>::type type;
};
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
template<class A, class T>
struct sp_alloc_to {
typedef typename std::allocator_traits<A>::template rebind_alloc<T> type;
};
#else
template<class A, class T>
struct sp_alloc_to {
typedef typename A::template rebind<T>::other type;
};
#endif
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
template<class A>
struct sp_alloc_type {
typedef typename std::allocator_traits<A>::pointer type;
};
#else
template<class A>
struct sp_alloc_type {
typedef typename A::pointer type;
};
#endif
template<class T, class P>
class sp_alloc_ptr {
public:
@ -296,7 +273,7 @@ operator!=(detail::sp_nullptr_t,
template<class A>
inline void
sp_alloc_clear(A& a, typename sp_alloc_type<A>::type p, std::size_t,
sp_alloc_clear(A& a, typename boost::allocator_pointer<A>::type p, std::size_t,
boost::false_type)
{
boost::alloc_destroy(a, boost::to_address(p));
@ -304,8 +281,8 @@ sp_alloc_clear(A& a, typename sp_alloc_type<A>::type p, std::size_t,
template<class A>
inline void
sp_alloc_clear(A& a, typename sp_alloc_type<A>::type p, std::size_t n,
boost::true_type)
sp_alloc_clear(A& a, typename boost::allocator_pointer<A>::type p,
std::size_t n, boost::true_type)
{
#if defined(BOOST_MSVC) && BOOST_MSVC < 1800
if (!p) {
@ -320,15 +297,15 @@ sp_alloc_clear(A& a, typename sp_alloc_type<A>::type p, std::size_t n,
template<class T, class A>
class alloc_deleter
: empty_value<typename detail::sp_alloc_to<A,
: empty_value<typename allocator_rebind<A,
typename detail::sp_alloc_value<T>::type>::type> {
typedef typename detail::sp_alloc_to<A,
typedef typename allocator_rebind<A,
typename detail::sp_alloc_value<T>::type>::type allocator;
typedef empty_value<allocator> base;
public:
typedef detail::sp_alloc_ptr<T,
typename detail::sp_alloc_type<allocator>::type> pointer;
typename allocator_pointer<allocator>::type> pointer;
explicit alloc_deleter(const allocator& a) BOOST_SP_NOEXCEPT
: base(empty_init_t(), a) { }
@ -349,7 +326,7 @@ namespace detail {
template<class T, class A>
class sp_alloc_make {
public:
typedef typename sp_alloc_to<A,
typedef typename boost::allocator_rebind<A,
typename sp_alloc_value<T>::type>::type allocator;
private:
@ -384,7 +361,7 @@ public:
}
private:
typedef typename sp_alloc_type<allocator>::type pointer;
typedef typename boost::allocator_pointer<allocator>::type pointer;
allocator a_;
std::size_t n_;