summaryrefslogtreecommitdiff
path: root/boost/smart_ptr/allocate_local_shared_array.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/smart_ptr/allocate_local_shared_array.hpp')
-rw-r--r--boost/smart_ptr/allocate_local_shared_array.hpp113
1 files changed, 35 insertions, 78 deletions
diff --git a/boost/smart_ptr/allocate_local_shared_array.hpp b/boost/smart_ptr/allocate_local_shared_array.hpp
index c1c7373738..0890849134 100644
--- a/boost/smart_ptr/allocate_local_shared_array.hpp
+++ b/boost/smart_ptr/allocate_local_shared_array.hpp
@@ -72,21 +72,19 @@ inline typename enable_if_<is_unbounded_array<T>::value,
local_shared_ptr<T> >::type
allocate_local_shared(const A& allocator, std::size_t count)
{
- typedef typename remove_extent<T>::type type;
- typedef typename detail::sp_array_scalar<T>::type scalar;
- typedef typename detail::sp_bind_allocator<A, scalar>::type other;
+ typedef typename detail::sp_array_element<T>::type element;
+ typedef typename detail::sp_bind_allocator<A, element>::type other;
typedef detail::lsp_array_state<other> state;
typedef detail::sp_array_base<state> base;
- std::size_t size = count * detail::sp_array_count<type, scalar>::value;
- detail::sp_array_result<other, base> result(allocator, size);
+ detail::sp_array_result<other, base> result(allocator, count);
base* node = result.get();
- scalar* start = detail::sp_array_start<base, scalar>(node);
- ::new(static_cast<void*>(node)) base(allocator, size, start);
+ element* start = detail::sp_array_start<element>(node);
+ ::new(static_cast<void*>(node)) base(allocator, start, count);
detail::lsp_array_base& local = node->state().base();
local.set(node);
result.release();
- return local_shared_ptr<T>(detail::lsp_internal_constructor_tag(),
- reinterpret_cast<type*>(start), &local);
+ return local_shared_ptr<T>(detail::lsp_internal_constructor_tag(), start,
+ &local);
}
template<class T, class A>
@@ -94,23 +92,22 @@ inline typename enable_if_<is_bounded_array<T>::value,
local_shared_ptr<T> >::type
allocate_local_shared(const A& allocator)
{
- typedef typename remove_extent<T>::type type;
- typedef typename detail::sp_array_scalar<T>::type scalar;
- typedef typename detail::sp_bind_allocator<A, scalar>::type other;
enum {
- size = detail::sp_array_count<T, scalar>::value
+ count = extent<T>::value
};
- typedef detail::lsp_size_array_state<other, size> state;
+ typedef typename detail::sp_array_element<T>::type element;
+ typedef typename detail::sp_bind_allocator<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, size);
+ detail::sp_array_result<other, base> result(allocator, count);
base* node = result.get();
- scalar* start = detail::sp_array_start<base, scalar>(node);
- ::new(static_cast<void*>(node)) base(allocator, size, start);
+ element* start = detail::sp_array_start<element>(node);
+ ::new(static_cast<void*>(node)) base(allocator, start, count);
detail::lsp_array_base& local = node->state().base();
local.set(node);
result.release();
- return local_shared_ptr<T>(detail::lsp_internal_constructor_tag(),
- reinterpret_cast<type*>(start), &local);
+ return local_shared_ptr<T>(detail::lsp_internal_constructor_tag(), start,
+ &local);
}
template<class T, class A>
@@ -119,25 +116,19 @@ inline typename enable_if_<is_unbounded_array<T>::value,
allocate_local_shared(const A& allocator, std::size_t count,
const typename remove_extent<T>::type& value)
{
- typedef typename remove_extent<T>::type type;
- typedef typename detail::sp_array_scalar<T>::type scalar;
- typedef typename detail::sp_bind_allocator<A, scalar>::type other;
+ typedef typename detail::sp_array_element<T>::type element;
+ typedef typename detail::sp_bind_allocator<A, element>::type other;
typedef detail::lsp_array_state<other> state;
typedef detail::sp_array_base<state> base;
- enum {
- total = detail::sp_array_count<type, scalar>::value
- };
- std::size_t size = count * total;
- detail::sp_array_result<other, base> result(allocator, size);
+ detail::sp_array_result<other, base> result(allocator, count);
base* node = result.get();
- scalar* start = detail::sp_array_start<base, scalar>(node);
- ::new(static_cast<void*>(node)) base(allocator, size,
- reinterpret_cast<const scalar*>(&value), total, start);
+ element* start = detail::sp_array_start<element>(node);
+ ::new(static_cast<void*>(node)) base(allocator, start, count, value);
detail::lsp_array_base& local = node->state().base();
local.set(node);
result.release();
- return local_shared_ptr<T>(detail::lsp_internal_constructor_tag(),
- reinterpret_cast<type*>(start), &local);
+ return local_shared_ptr<T>(detail::lsp_internal_constructor_tag(), start,
+ &local);
}
template<class T, class A>
@@ -146,25 +137,22 @@ inline typename enable_if_<is_bounded_array<T>::value,
allocate_local_shared(const A& allocator,
const typename remove_extent<T>::type& value)
{
- typedef typename remove_extent<T>::type type;
- typedef typename detail::sp_array_scalar<T>::type scalar;
- typedef typename detail::sp_bind_allocator<A, scalar>::type other;
enum {
- size = detail::sp_array_count<T, scalar>::value
+ count = extent<T>::value
};
- typedef detail::lsp_size_array_state<other, size> state;
+ typedef typename detail::sp_array_element<T>::type element;
+ typedef typename detail::sp_bind_allocator<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, size);
+ detail::sp_array_result<other, base> result(allocator, count);
base* node = result.get();
- scalar* start = detail::sp_array_start<base, scalar>(node);
- ::new(static_cast<void*>(node)) base(allocator, size,
- reinterpret_cast<const scalar*>(&value),
- detail::sp_array_count<type, scalar>::value, start);
+ element* start = detail::sp_array_start<element>(node);
+ ::new(static_cast<void*>(node)) base(allocator, start, count, value);
detail::lsp_array_base& local = node->state().base();
local.set(node);
result.release();
- return local_shared_ptr<T>(detail::lsp_internal_constructor_tag(),
- reinterpret_cast<type*>(start), &local);
+ return local_shared_ptr<T>(detail::lsp_internal_constructor_tag(), start,
+ &local);
}
template<class T, class A>
@@ -172,22 +160,8 @@ inline typename enable_if_<is_unbounded_array<T>::value,
local_shared_ptr<T> >::type
allocate_local_shared_noinit(const A& allocator, std::size_t count)
{
- typedef typename remove_extent<T>::type type;
- typedef typename detail::sp_array_scalar<T>::type scalar;
- typedef typename detail::sp_bind_allocator<A, scalar>::type other;
- typedef detail::lsp_array_state<other> state;
- typedef detail::sp_array_base<state, false> base;
- std::size_t size = count * detail::sp_array_count<type, scalar>::value;
- detail::sp_array_result<other, base> result(allocator, size);
- base* node = result.get();
- scalar* start = detail::sp_array_start<base, scalar>(node);
- ::new(static_cast<void*>(node)) base(detail::sp_default(), allocator,
- size, start);
- detail::lsp_array_base& local = node->state().base();
- local.set(node);
- result.release();
- return local_shared_ptr<T>(detail::lsp_internal_constructor_tag(),
- reinterpret_cast<type*>(start), &local);
+ return boost::allocate_local_shared<T>(boost::noinit_adapt(allocator),
+ count);
}
template<class T, class A>
@@ -195,24 +169,7 @@ inline typename enable_if_<is_bounded_array<T>::value,
local_shared_ptr<T> >::type
allocate_local_shared_noinit(const A& allocator)
{
- typedef typename remove_extent<T>::type type;
- typedef typename detail::sp_array_scalar<T>::type scalar;
- typedef typename detail::sp_bind_allocator<A, scalar>::type other;
- enum {
- size = detail::sp_array_count<T, scalar>::value
- };
- typedef detail::lsp_size_array_state<other, size> state;
- typedef detail::sp_array_base<state, false> base;
- detail::sp_array_result<other, base> result(allocator, size);
- base* node = result.get();
- scalar* start = detail::sp_array_start<base, scalar>(node);
- ::new(static_cast<void*>(node)) base(detail::sp_default(), allocator,
- size, start);
- detail::lsp_array_base& local = node->state().base();
- local.set(node);
- result.release();
- return local_shared_ptr<T>(detail::lsp_internal_constructor_tag(),
- reinterpret_cast<type*>(start), &local);
+ return boost::allocate_local_shared<T>(boost::noinit_adapt(allocator));
}
} /* boost */