diff --git a/include/boost/smart_ptr/allocate_local_shared_array.hpp b/include/boost/smart_ptr/allocate_local_shared_array.hpp index c1c7373..8080144 100644 --- a/include/boost/smart_ptr/allocate_local_shared_array.hpp +++ b/include/boost/smart_ptr/allocate_local_shared_array.hpp @@ -172,22 +172,8 @@ inline typename enable_if_::value, local_shared_ptr >::type allocate_local_shared_noinit(const A& allocator, std::size_t count) { - typedef typename remove_extent::type type; - typedef typename detail::sp_array_scalar::type scalar; - typedef typename detail::sp_bind_allocator::type other; - typedef detail::lsp_array_state state; - typedef detail::sp_array_base base; - std::size_t size = count * detail::sp_array_count::value; - detail::sp_array_result result(allocator, size); - base* node = result.get(); - scalar* start = detail::sp_array_start(node); - ::new(static_cast(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(detail::lsp_internal_constructor_tag(), - reinterpret_cast(start), &local); + return boost::allocate_local_shared(boost::noinit_adaptor(allocator), + count); } template @@ -195,24 +181,8 @@ inline typename enable_if_::value, local_shared_ptr >::type allocate_local_shared_noinit(const A& allocator) { - typedef typename remove_extent::type type; - typedef typename detail::sp_array_scalar::type scalar; - typedef typename detail::sp_bind_allocator::type other; - enum { - size = detail::sp_array_count::value - }; - typedef detail::lsp_size_array_state state; - typedef detail::sp_array_base base; - detail::sp_array_result result(allocator, size); - base* node = result.get(); - scalar* start = detail::sp_array_start(node); - ::new(static_cast(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(detail::lsp_internal_constructor_tag(), - reinterpret_cast(start), &local); + return boost::allocate_local_shared(boost:: + noinit_adaptor(allocator)); } } /* boost */ diff --git a/include/boost/smart_ptr/allocate_shared_array.hpp b/include/boost/smart_ptr/allocate_shared_array.hpp index 3da4c19..e412749 100644 --- a/include/boost/smart_ptr/allocate_shared_array.hpp +++ b/include/boost/smart_ptr/allocate_shared_array.hpp @@ -8,14 +8,12 @@ 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 #include #include #include #include #include -#include -#include -#include #include #include #include @@ -70,33 +68,27 @@ sp_objects(std::size_t size) BOOST_SP_NOEXCEPT return (size + sizeof(T) - 1) / sizeof(T); } -template -inline typename boost::enable_if_::value>::type -sp_array_destroy(A&, T*, std::size_t) BOOST_SP_NOEXCEPT { } - -template -inline typename boost::enable_if_::value>::type -sp_array_destroy(A&, T* ptr, std::size_t size) -{ - while (size > 0) { - ptr[--size].~T(); - } -} - #if !defined(BOOST_NO_CXX11_ALLOCATOR) -template -inline typename boost::enable_if_::type +template +inline void sp_array_destroy(A& allocator, T* ptr, std::size_t size) { while (size > 0) { std::allocator_traits::destroy(allocator, ptr + --size); } } +#else +template +inline void +sp_array_destroy(A&, T* ptr, std::size_t size) +{ + while (size > 0) { + ptr[--size].~T(); + } +} #endif -template +template class sp_destroyer { public: sp_destroyer(A& allocator, T* ptr) BOOST_SP_NOEXCEPT @@ -105,7 +97,7 @@ public: size_(0) { } ~sp_destroyer() { - sp_array_destroy(allocator_, ptr_, size_); + sp_array_destroy(allocator_, ptr_, size_); } std::size_t& size() BOOST_SP_NOEXCEPT { @@ -121,103 +113,66 @@ private: std::size_t size_; }; -template -inline typename boost::enable_if_::value && - boost::has_trivial_assign::value && - boost::has_trivial_destructor::value>::type -sp_array_construct(A&, T* ptr, std::size_t size) -{ - for (std::size_t i = 0; i < size; ++i) { - ptr[i] = T(); - } -} - -template -inline typename boost::enable_if_::value && - boost::has_trivial_assign::value && - boost::has_trivial_destructor::value>::type -sp_array_construct(A&, T* ptr, std::size_t size, const T* list, - std::size_t count) -{ - for (std::size_t i = 0; i < size; ++i) { - ptr[i] = list[i % count]; - } -} - -template -inline typename boost::enable_if_::value && - boost::has_trivial_assign::value && - boost::has_trivial_destructor::value)>::type -sp_array_construct(A& none, T* ptr, std::size_t size) -{ - sp_destroyer hold(none, ptr); - for (std::size_t& i = hold.size(); i < size; ++i) { - ::new(static_cast(ptr + i)) T(); - } - hold.size() = 0; -} - -template -inline typename boost::enable_if_::value && - boost::has_trivial_assign::value && - boost::has_trivial_destructor::value)>::type -sp_array_construct(A& none, T* ptr, std::size_t size, const T* list, - std::size_t count) -{ - sp_destroyer hold(none, ptr); - for (std::size_t& i = hold.size(); i < size; ++i) { - ::new(static_cast(ptr + i)) T(list[i % count]); - } - hold.size() = 0; -} - #if !defined(BOOST_NO_CXX11_ALLOCATOR) -template -inline typename boost::enable_if_::type +template +inline void sp_array_construct(A& allocator, T* ptr, std::size_t size) { - sp_destroyer hold(allocator, ptr); + sp_destroyer hold(allocator, ptr); for (std::size_t& i = hold.size(); i < size; ++i) { std::allocator_traits::construct(allocator, ptr + i); } hold.size() = 0; } -template -inline typename boost::enable_if_::type +template +inline void sp_array_construct(A& allocator, T* ptr, std::size_t size, const T* list, std::size_t count) { - sp_destroyer hold(allocator, ptr); + sp_destroyer hold(allocator, ptr); for (std::size_t& i = hold.size(); i < size; ++i) { std::allocator_traits::construct(allocator, ptr + i, list[i % count]); } hold.size() = 0; } -#endif - +#else template -inline typename - boost::enable_if_::value>::type -sp_array_default(A&, T*, std::size_t) BOOST_SP_NOEXCEPT { } - -template -inline typename - boost::enable_if_::value>::type -sp_array_default(A& none, T* ptr, std::size_t size) +inline void +sp_array_construct(A& none, T* ptr, std::size_t size) { - sp_destroyer hold(none, ptr); + sp_destroyer hold(none, ptr); + for (std::size_t& i = hold.size(); i < size; ++i) { + ::new(static_cast(ptr + i)) T(); + } + hold.size() = 0; +} + +template +inline void +sp_array_construct(boost::noinit_adaptor& none, T* ptr, std::size_t size) +{ + sp_destroyer, T> hold(none, ptr); for (std::size_t& i = hold.size(); i < size; ++i) { ::new(static_cast(ptr + i)) T; } hold.size() = 0; } +template +inline void +sp_array_construct(A& none, T* ptr, std::size_t size, const T* list, + std::size_t count) +{ + sp_destroyer hold(none, ptr); + for (std::size_t& i = hold.size(); i < size; ++i) { + ::new(static_cast(ptr + i)) T(list[i % count]); + } + hold.size() = 0; +} +#endif + template class sp_array_state { public: @@ -262,29 +217,6 @@ private: A allocator_; }; -#if !defined(BOOST_NO_CXX11_ALLOCATOR) -template -struct sp_use_construct { - enum { - value = true - }; -}; - -template -struct sp_use_construct > { - enum { - value = false - }; -}; -#else -template -struct sp_use_construct { - enum { - value = false - }; -}; -#endif - template struct sp_array_alignment { enum { @@ -347,9 +279,7 @@ private: std::size_t size_; }; -struct sp_default { }; - -template::value> +template class BOOST_SYMBOL_VISIBLE sp_array_base : public sp_counted_base { typedef typename T::type allocator; @@ -360,29 +290,23 @@ public: template sp_array_base(const A& other, std::size_t size, type* start) : state_(other, size) { - sp_array_construct(state_.allocator(), start, state_.size()); + sp_array_construct(state_.allocator(), start, state_.size()); } template sp_array_base(const A& other, std::size_t size, const type* list, std::size_t count, type* start) : state_(other, size) { - sp_array_construct(state_.allocator(), start, state_.size(), list, + sp_array_construct(state_.allocator(), start, state_.size(), list, count); } - template - sp_array_base(sp_default, const A& other, std::size_t size, type* start) - : state_(other, size) { - sp_array_default(state_.allocator(), start, state_.size()); - } - T& state() BOOST_SP_NOEXCEPT { return state_; } virtual void dispose() BOOST_SP_NOEXCEPT { - sp_array_destroy(state_.allocator(), + sp_array_destroy(state_.allocator(), sp_array_start(this), state_.size()); } @@ -533,42 +457,15 @@ template inline typename enable_if_::value, shared_ptr >::type allocate_shared_noinit(const A& allocator, std::size_t count) { - typedef typename remove_extent::type type; - typedef typename detail::sp_array_scalar::type scalar; - typedef typename detail::sp_bind_allocator::type other; - typedef detail::sp_array_state state; - typedef detail::sp_array_base base; - std::size_t size = count * detail::sp_array_count::value; - detail::sp_array_result result(allocator, size); - detail::sp_counted_base* node = result.get(); - scalar* start = detail::sp_array_start(node); - ::new(static_cast(node)) base(detail::sp_default(), allocator, - size, start); - result.release(); - return shared_ptr(detail::sp_internal_constructor_tag(), - reinterpret_cast(start), detail::shared_count(node)); + return boost::allocate_shared(boost::noinit_adaptor(allocator), + count); } template inline typename enable_if_::value, shared_ptr >::type allocate_shared_noinit(const A& allocator) { - typedef typename remove_extent::type type; - typedef typename detail::sp_array_scalar::type scalar; - typedef typename detail::sp_bind_allocator::type other; - enum { - size = detail::sp_array_count::value - }; - typedef detail::sp_size_array_state state; - typedef detail::sp_array_base base; - detail::sp_array_result result(allocator, size); - detail::sp_counted_base* node = result.get(); - scalar* start = detail::sp_array_start(node); - ::new(static_cast(node)) base(detail::sp_default(), allocator, - size, start); - result.release(); - return shared_ptr(detail::sp_internal_constructor_tag(), - reinterpret_cast(start), detail::shared_count(node)); + return boost::allocate_shared(boost::noinit_adaptor(allocator)); } } /* boost */ diff --git a/include/boost/smart_ptr/make_local_shared_array.hpp b/include/boost/smart_ptr/make_local_shared_array.hpp index 1d50102..cbc6a0f 100644 --- a/include/boost/smart_ptr/make_local_shared_array.hpp +++ b/include/boost/smart_ptr/make_local_shared_array.hpp @@ -9,6 +9,7 @@ Distributed under the Boost Software License, Version 1.0. #ifndef BOOST_SMART_PTR_MAKE_LOCAL_SHARED_ARRAY_HPP #define BOOST_SMART_PTR_MAKE_LOCAL_SHARED_ARRAY_HPP +#include #include namespace boost { @@ -18,7 +19,7 @@ inline typename enable_if_::value, local_shared_ptr >::type make_local_shared() { - return boost::allocate_local_shared(std::allocator(boost::default_allocator::type>()); } @@ -27,7 +28,7 @@ inline typename enable_if_::value, local_shared_ptr >::type make_local_shared(const typename remove_extent::type& value) { - return boost::allocate_local_shared(std::allocator(boost::default_allocator::type>(), value); } @@ -36,7 +37,7 @@ inline typename enable_if_::value, local_shared_ptr >::type make_local_shared(std::size_t size) { - return boost::allocate_local_shared(std::allocator(boost::default_allocator::type>(), size); } @@ -46,7 +47,7 @@ inline typename enable_if_::value, make_local_shared(std::size_t size, const typename remove_extent::type& value) { - return boost::allocate_local_shared(std::allocator(boost::default_allocator::type>(), size, value); } @@ -55,8 +56,8 @@ inline typename enable_if_::value, local_shared_ptr >::type make_local_shared_noinit() { - return boost::allocate_local_shared_noinit(std::allocator::type>()); + return boost::allocate_local_shared_noinit(boost:: + default_allocator::type>()); } template @@ -64,8 +65,8 @@ inline typename enable_if_::value, local_shared_ptr >::type make_local_shared_noinit(std::size_t size) { - return boost::allocate_local_shared_noinit(std::allocator::type>(), size); + return boost::allocate_local_shared_noinit(boost:: + default_allocator::type>(), size); } } /* boost */ diff --git a/include/boost/smart_ptr/make_shared_array.hpp b/include/boost/smart_ptr/make_shared_array.hpp index 1b40c4d..ce4b59f 100644 --- a/include/boost/smart_ptr/make_shared_array.hpp +++ b/include/boost/smart_ptr/make_shared_array.hpp @@ -8,6 +8,7 @@ Distributed under the Boost Software License, Version 1.0. #ifndef BOOST_SMART_PTR_MAKE_SHARED_ARRAY_HPP #define BOOST_SMART_PTR_MAKE_SHARED_ARRAY_HPP +#include #include namespace boost { @@ -16,7 +17,7 @@ template inline typename enable_if_::value, shared_ptr >::type make_shared() { - return boost::allocate_shared(std::allocator(boost::default_allocator::type>()); } @@ -24,7 +25,7 @@ template inline typename enable_if_::value, shared_ptr >::type make_shared(const typename remove_extent::type& value) { - return boost::allocate_shared(std::allocator(boost::default_allocator::type>(), value); } @@ -32,7 +33,7 @@ template inline typename enable_if_::value, shared_ptr >::type make_shared(std::size_t size) { - return boost::allocate_shared(std::allocator(boost::default_allocator::type>(), size); } @@ -40,7 +41,7 @@ template inline typename enable_if_::value, shared_ptr >::type make_shared(std::size_t size, const typename remove_extent::type& value) { - return boost::allocate_shared(std::allocator(boost::default_allocator::type>(), size, value); } @@ -48,7 +49,7 @@ template inline typename enable_if_::value, shared_ptr >::type make_shared_noinit() { - return boost::allocate_shared_noinit(std::allocator(boost::default_allocator::type>()); } @@ -56,7 +57,7 @@ template inline typename enable_if_::value, shared_ptr >::type make_shared_noinit(std::size_t size) { - return boost::allocate_shared_noinit(std::allocator(boost::default_allocator::type>(), size); }