diff --git a/include/boost/smart_ptr/allocate_local_shared_array.hpp b/include/boost/smart_ptr/allocate_local_shared_array.hpp index 7591ba6..c1c7373 100644 --- a/include/boost/smart_ptr/allocate_local_shared_array.hpp +++ b/include/boost/smart_ptr/allocate_local_shared_array.hpp @@ -1,5 +1,5 @@ /* -Copyright 2017 Glen Joseph Fernandes +Copyright 2017-2019 Glen Joseph Fernandes (glenjofe@gmail.com) Distributed under the Boost Software License, Version 1.0. @@ -14,22 +14,6 @@ Distributed under the Boost Software License, Version 1.0. namespace boost { namespace detail { -template -struct lsp_if_array { }; - -template -struct lsp_if_array { - typedef boost::local_shared_ptr type; -}; - -template -struct lsp_if_size_array { }; - -template -struct lsp_if_size_array { - typedef boost::local_shared_ptr type; -}; - class BOOST_SYMBOL_VISIBLE lsp_array_base : public local_counted_base { public: @@ -84,15 +68,16 @@ private: } /* detail */ template -inline typename detail::lsp_if_array::type +inline typename enable_if_::value, + local_shared_ptr >::type allocate_local_shared(const A& allocator, std::size_t count) { - typedef typename detail::sp_array_element::type type; + 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; + 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); @@ -105,15 +90,16 @@ allocate_local_shared(const A& allocator, std::size_t count) } template -inline typename detail::lsp_if_size_array::type +inline typename enable_if_::value, + local_shared_ptr >::type allocate_local_shared(const A& allocator) { - enum { - size = detail::sp_array_count::value - }; - typedef typename detail::sp_array_element::type type; + 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); @@ -128,22 +114,25 @@ allocate_local_shared(const A& allocator) } template -inline typename detail::lsp_if_array::type +inline typename enable_if_::value, + local_shared_ptr >::type allocate_local_shared(const A& allocator, std::size_t count, - const typename detail::sp_array_element::type& value) + const typename remove_extent::type& value) { - typedef typename detail::sp_array_element::type type; + 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; + enum { + total = detail::sp_array_count::value + }; + std::size_t size = count * total; detail::sp_array_result result(allocator, size); base* node = result.get(); scalar* start = detail::sp_array_start(node); ::new(static_cast(node)) base(allocator, size, - reinterpret_cast(&value), - detail::sp_array_count::value, start); + reinterpret_cast(&value), total, start); detail::lsp_array_base& local = node->state().base(); local.set(node); result.release(); @@ -152,16 +141,17 @@ allocate_local_shared(const A& allocator, std::size_t count, } template -inline typename detail::lsp_if_size_array::type +inline typename enable_if_::value, + local_shared_ptr >::type allocate_local_shared(const A& allocator, - const typename detail::sp_array_element::type& value) + const typename remove_extent::type& value) { - enum { - size = detail::sp_array_count::value - }; - typedef typename detail::sp_array_element::type type; + 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); @@ -169,7 +159,7 @@ allocate_local_shared(const A& allocator, scalar* start = detail::sp_array_start(node); ::new(static_cast(node)) base(allocator, size, reinterpret_cast(&value), - detail::sp_array_count::value, start); + detail::sp_array_count::value, start); detail::lsp_array_base& local = node->state().base(); local.set(node); result.release(); @@ -178,15 +168,16 @@ allocate_local_shared(const A& allocator, } template -inline typename detail::lsp_if_array::type +inline typename enable_if_::value, + local_shared_ptr >::type allocate_local_shared_noinit(const A& allocator, std::size_t count) { - typedef typename detail::sp_array_element::type type; + 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; + 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); @@ -200,15 +191,16 @@ allocate_local_shared_noinit(const A& allocator, std::size_t count) } template -inline typename detail::lsp_if_size_array::type +inline typename enable_if_::value, + local_shared_ptr >::type allocate_local_shared_noinit(const A& allocator) { - enum { - size = detail::sp_array_count::value - }; - typedef typename detail::sp_array_element::type type; + 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); diff --git a/include/boost/smart_ptr/allocate_shared_array.hpp b/include/boost/smart_ptr/allocate_shared_array.hpp index 4968db0..5aab81a 100644 --- a/include/boost/smart_ptr/allocate_shared_array.hpp +++ b/include/boost/smart_ptr/allocate_shared_array.hpp @@ -1,5 +1,5 @@ /* -Copyright 2012-2018 Glen Joseph Fernandes +Copyright 2012-2019 Glen Joseph Fernandes (glenjofe@gmail.com) Distributed under the Boost Software License, Version 1.0. @@ -10,99 +10,30 @@ Distributed under the Boost Software License, Version 1.0. #include #include +#include +#include +#include #include #include #include +#include +#include +#include #include namespace boost { namespace detail { -template -struct sp_if_array { }; - -template -struct sp_if_array { - typedef boost::shared_ptr type; -}; - -template -struct sp_if_size_array { }; - -template -struct sp_if_size_array { - typedef boost::shared_ptr type; -}; - -template -struct sp_array_element { }; - -template -struct sp_array_element { - typedef T type; -}; - -template -struct sp_array_element { - typedef T type; -}; - template struct sp_array_scalar { - typedef T type; + typedef typename boost::remove_cv::type>::type type; }; -template -struct sp_array_scalar { - typedef typename sp_array_scalar::type type; -}; - -template -struct sp_array_scalar { - typedef typename sp_array_scalar::type type; -}; - -template -struct sp_array_scalar { - typedef typename sp_array_scalar::type type; -}; - -template -struct sp_array_scalar { - typedef typename sp_array_scalar::type type; -}; - -template -struct sp_array_scalar { - typedef typename sp_array_scalar::type type; -}; - -template -struct sp_array_scalar { - typedef typename sp_array_scalar::type type; -}; - -template -struct sp_array_scalar { - typedef typename sp_array_scalar::type type; -}; - -template -struct sp_array_scalar { - typedef typename sp_array_scalar::type type; -}; - -template +template struct sp_array_count { enum { - value = 1 - }; -}; - -template -struct sp_array_count { - enum { - value = N * sp_array_count::value + value = sizeof(T) / sizeof(U) }; }; @@ -139,20 +70,13 @@ sp_objects(std::size_t size) BOOST_SP_NOEXCEPT return (size + sizeof(T) - 1) / sizeof(T); } -template -struct sp_enable { }; - -template -struct sp_enable { - typedef T type; -}; - template -inline typename sp_enable::value>::type +inline typename boost::enable_if_::value>::type sp_array_destroy(A&, T*, std::size_t) BOOST_SP_NOEXCEPT { } template -inline typename sp_enable::value>::type sp_array_destroy(A&, T* ptr, std::size_t size) { @@ -163,7 +87,7 @@ sp_array_destroy(A&, T* ptr, std::size_t size) #if !defined(BOOST_NO_CXX11_ALLOCATOR) template -inline typename sp_enable::type +inline typename boost::enable_if_::type sp_array_destroy(A& allocator, T* ptr, std::size_t size) { while (size > 0) { @@ -198,7 +122,7 @@ private: }; template -inline typename sp_enable::value && boost::has_trivial_assign::value && boost::has_trivial_destructor::value>::type @@ -210,7 +134,7 @@ sp_array_construct(A&, T* ptr, std::size_t size) } template -inline typename sp_enable::value && boost::has_trivial_assign::value && boost::has_trivial_destructor::value>::type @@ -223,7 +147,7 @@ sp_array_construct(A&, T* ptr, std::size_t size, const T* list, } template -inline typename sp_enable::value && boost::has_trivial_assign::value && boost::has_trivial_destructor::value)>::type @@ -237,7 +161,7 @@ sp_array_construct(A& none, T* ptr, std::size_t size) } template -inline typename sp_enable::value && boost::has_trivial_assign::value && boost::has_trivial_destructor::value)>::type @@ -253,7 +177,7 @@ sp_array_construct(A& none, T* ptr, std::size_t size, const T* list, #if !defined(BOOST_NO_CXX11_ALLOCATOR) template -inline typename sp_enable::type +inline typename boost::enable_if_::type sp_array_construct(A& allocator, T* ptr, std::size_t size) { sp_destroyer hold(allocator, ptr); @@ -264,7 +188,7 @@ sp_array_construct(A& allocator, T* ptr, std::size_t size) } template -inline typename sp_enable::type +inline typename boost::enable_if_::type sp_array_construct(A& allocator, T* ptr, std::size_t size, const T* list, std::size_t count) { @@ -278,11 +202,13 @@ sp_array_construct(A& allocator, T* ptr, std::size_t size, const T* list, #endif template -inline typename sp_enable::value>::type +inline typename + boost::enable_if_::value>::type sp_array_default(A&, T*, std::size_t) BOOST_SP_NOEXCEPT { } template -inline typename sp_enable::value>::type +inline typename + boost::enable_if_::value>::type sp_array_default(A& none, T* ptr, std::size_t size) { sp_destroyer hold(none, ptr); @@ -516,15 +442,15 @@ private: } /* detail */ template -inline typename detail::sp_if_array::type +inline typename enable_if_::value, shared_ptr >::type allocate_shared(const A& allocator, std::size_t count) { - typedef typename detail::sp_array_element::type type; + 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; + 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); @@ -535,15 +461,15 @@ allocate_shared(const A& allocator, std::size_t count) } template -inline typename detail::sp_if_size_array::type +inline typename enable_if_::value, shared_ptr >::type allocate_shared(const A& allocator) { - enum { - size = detail::sp_array_count::value - }; - typedef typename detail::sp_array_element::type type; + 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); @@ -556,38 +482,40 @@ allocate_shared(const A& allocator) } template -inline typename detail::sp_if_array::type +inline typename enable_if_::value, shared_ptr >::type allocate_shared(const A& allocator, std::size_t count, - const typename detail::sp_array_element::type& value) + const typename remove_extent::type& value) { - typedef typename detail::sp_array_element::type type; + 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; + enum { + total = detail::sp_array_count::value + }; + std::size_t size = count * total; 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(allocator, size, - reinterpret_cast(&value), - detail::sp_array_count::value, start); + reinterpret_cast(&value), total, start); result.release(); return shared_ptr(detail::sp_internal_constructor_tag(), reinterpret_cast(start), detail::shared_count(node)); } template -inline typename detail::sp_if_size_array::type +inline typename enable_if_::value, shared_ptr >::type allocate_shared(const A& allocator, - const typename detail::sp_array_element::type& value) + const typename remove_extent::type& value) { - enum { - size = detail::sp_array_count::value - }; - typedef typename detail::sp_array_element::type type; + 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); @@ -595,22 +523,22 @@ allocate_shared(const A& allocator, scalar* start = detail::sp_array_start(node); ::new(static_cast(node)) base(allocator, size, reinterpret_cast(&value), - detail::sp_array_count::value, start); + detail::sp_array_count::value, start); result.release(); return shared_ptr(detail::sp_internal_constructor_tag(), reinterpret_cast(start), detail::shared_count(node)); } template -inline typename detail::sp_if_array::type +inline typename enable_if_::value, shared_ptr >::type allocate_shared_noinit(const A& allocator, std::size_t count) { - typedef typename detail::sp_array_element::type type; + 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; + 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); @@ -622,15 +550,15 @@ allocate_shared_noinit(const A& allocator, std::size_t count) } template -inline typename detail::sp_if_size_array::type +inline typename enable_if_::value, shared_ptr >::type allocate_shared_noinit(const A& allocator) { - enum { - size = detail::sp_array_count::value - }; - typedef typename detail::sp_array_element::type type; + 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); diff --git a/include/boost/smart_ptr/make_local_shared_array.hpp b/include/boost/smart_ptr/make_local_shared_array.hpp index 663f834..1d50102 100644 --- a/include/boost/smart_ptr/make_local_shared_array.hpp +++ b/include/boost/smart_ptr/make_local_shared_array.hpp @@ -1,6 +1,6 @@ /* Copyright 2017 Peter Dimov -Copyright 2017 Glen Joseph Fernandes +Copyright 2017-2019 Glen Joseph Fernandes (glenjofe@gmail.com) Distributed under the Boost Software License, Version 1.0. @@ -14,7 +14,8 @@ Distributed under the Boost Software License, Version 1.0. namespace boost { template -inline typename detail::lsp_if_size_array::type +inline typename enable_if_::value, + local_shared_ptr >::type make_local_shared() { return boost::allocate_local_shared(std::allocator -inline typename detail::lsp_if_size_array::type -make_local_shared(const typename detail::sp_array_element::type& value) +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::type>(), value); } template -inline typename detail::lsp_if_array::type +inline typename enable_if_::value, + local_shared_ptr >::type make_local_shared(std::size_t size) { return boost::allocate_local_shared(std::allocator -inline typename detail::lsp_if_array::type +inline typename enable_if_::value, + local_shared_ptr >::type make_local_shared(std::size_t size, - const typename detail::sp_array_element::type& value) + const typename remove_extent::type& value) { return boost::allocate_local_shared(std::allocator::type>(), size, value); } template -inline typename detail::lsp_if_size_array::type +inline typename enable_if_::value, + local_shared_ptr >::type make_local_shared_noinit() { - return allocate_local_shared_noinit(std::allocator(std::allocator::type>()); } template -inline typename detail::lsp_if_array::type +inline typename enable_if_::value, + local_shared_ptr >::type make_local_shared_noinit(std::size_t size) { - return allocate_local_shared_noinit(std::allocator(std::allocator::type>(), size); } diff --git a/include/boost/smart_ptr/make_shared_array.hpp b/include/boost/smart_ptr/make_shared_array.hpp index 2eaf4db..1b40c4d 100644 --- a/include/boost/smart_ptr/make_shared_array.hpp +++ b/include/boost/smart_ptr/make_shared_array.hpp @@ -1,5 +1,5 @@ /* -Copyright 2012-2017 Glen Joseph Fernandes +Copyright 2012-2019 Glen Joseph Fernandes (glenjofe@gmail.com) Distributed under the Boost Software License, Version 1.0. @@ -13,7 +13,7 @@ Distributed under the Boost Software License, Version 1.0. namespace boost { template -inline typename detail::sp_if_size_array::type +inline typename enable_if_::value, shared_ptr >::type make_shared() { return boost::allocate_shared(std::allocator -inline typename detail::sp_if_size_array::type -make_shared(const typename detail::sp_array_element::type& value) +inline typename enable_if_::value, shared_ptr >::type +make_shared(const typename remove_extent::type& value) { return boost::allocate_shared(std::allocator::type>(), value); } template -inline typename detail::sp_if_array::type +inline typename enable_if_::value, shared_ptr >::type make_shared(std::size_t size) { return boost::allocate_shared(std::allocator -inline typename detail::sp_if_array::type -make_shared(std::size_t size, - const typename detail::sp_array_element::type& value) +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::type>(), size, value); } template -inline typename detail::sp_if_size_array::type +inline typename enable_if_::value, shared_ptr >::type make_shared_noinit() { - return allocate_shared_noinit(std::allocator(std::allocator::type>()); } template -inline typename detail::sp_if_array::type +inline typename enable_if_::value, shared_ptr >::type make_shared_noinit(std::size_t size) { - return allocate_shared_noinit(std::allocator(std::allocator::type>(), size); } diff --git a/include/boost/smart_ptr/make_unique.hpp b/include/boost/smart_ptr/make_unique.hpp index eed5033..1834007 100644 --- a/include/boost/smart_ptr/make_unique.hpp +++ b/include/boost/smart_ptr/make_unique.hpp @@ -1,5 +1,5 @@ /* -Copyright 2012-2015 Glen Joseph Fernandes +Copyright 2012-2019 Glen Joseph Fernandes (glenjofe@gmail.com) Distributed under the Boost Software License, Version 1.0. @@ -8,59 +8,18 @@ Distributed under the Boost Software License, Version 1.0. #ifndef BOOST_SMART_PTR_MAKE_UNIQUE_HPP #define BOOST_SMART_PTR_MAKE_UNIQUE_HPP -#include +#include +#include +#include +#include +#include #include #include namespace boost { -namespace detail { template -struct up_if_object { - typedef std::unique_ptr type; -}; - -template -struct up_if_object { }; - -template -struct up_if_object { }; - -template -struct up_if_array { }; - -template -struct up_if_array { - typedef std::unique_ptr type; -}; - -template -struct up_remove_reference { - typedef T type; -}; - -template -struct up_remove_reference { - typedef T type; -}; - -template -struct up_remove_reference { - typedef T type; -}; - -template -struct up_element { }; - -template -struct up_element { - typedef T type; -}; - -} /* detail */ - -template -inline typename detail::up_if_object::type +inline typename enable_if_::value, std::unique_ptr >::type make_unique() { return std::unique_ptr(new T()); @@ -68,7 +27,7 @@ make_unique() #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) template -inline typename detail::up_if_object::type +inline typename enable_if_::value, std::unique_ptr >::type make_unique(Args&&... args) { return std::unique_ptr(new T(std::forward(args)...)); @@ -76,33 +35,33 @@ make_unique(Args&&... args) #endif template -inline typename detail::up_if_object::type -make_unique(typename detail::up_remove_reference::type&& value) +inline typename enable_if_::value, std::unique_ptr >::type +make_unique(typename remove_reference::type&& value) { return std::unique_ptr(new T(std::move(value))); } template -inline typename detail::up_if_object::type +inline typename enable_if_::value, std::unique_ptr >::type make_unique_noinit() { return std::unique_ptr(new T); } template -inline typename detail::up_if_array::type +inline typename enable_if_::value, + std::unique_ptr >::type make_unique(std::size_t size) { - return std::unique_ptr(new typename - detail::up_element::type[size]()); + return std::unique_ptr(new typename remove_extent::type[size]()); } template -inline typename detail::up_if_array::type +inline typename enable_if_::value, + std::unique_ptr >::type make_unique_noinit(std::size_t size) { - return std::unique_ptr(new typename - detail::up_element::type[size]); + return std::unique_ptr(new typename remove_extent::type[size]); } } /* boost */