From 27715ed01a3e0bf0d0f9f26ddf4b70da23dc8c1d Mon Sep 17 00:00:00 2001 From: Glen Fernandes Date: Sun, 24 May 2020 00:03:14 -0400 Subject: [PATCH] Simplify alloc_construct using allocator_access --- include/boost/core/alloc_construct.hpp | 102 ++++--------------------- test/alloc_construct_cxx11_test.cpp | 2 +- 2 files changed, 14 insertions(+), 90 deletions(-) diff --git a/include/boost/core/alloc_construct.hpp b/include/boost/core/alloc_construct.hpp index 7b87525..e390730 100644 --- a/include/boost/core/alloc_construct.hpp +++ b/include/boost/core/alloc_construct.hpp @@ -12,12 +12,11 @@ Distributed under the Boost Software License, Version 1.0. namespace boost { -#if !defined(BOOST_NO_CXX11_ALLOCATOR) template inline void alloc_destroy(A& a, T* p) { - std::allocator_traits::destroy(a, p); + boost::allocator_destroy(a, p); } template @@ -25,26 +24,25 @@ inline void alloc_destroy_n(A& a, T* p, std::size_t n) { while (n > 0) { - std::allocator_traits::destroy(a, p + --n); + boost::allocator_destroy(a, p + --n); } } -#else + template inline void -alloc_destroy(A&, T* p) +alloc_destroy(noinit_adaptor&, T* p) { p->~T(); } template inline void -alloc_destroy_n(A&, T* p, std::size_t n) +alloc_destroy_n(noinit_adaptor&, T* p, std::size_t n) { while (n > 0) { p[--n].~T(); } } -#endif namespace detail { @@ -75,12 +73,11 @@ private: } /* detail */ -#if !defined(BOOST_NO_CXX11_ALLOCATOR) template inline void alloc_construct(A& a, T* p) { - std::allocator_traits::construct(a, p); + boost::allocator_construct(a, p); } #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) @@ -89,7 +86,7 @@ template inline void alloc_construct(A& a, T* p, U&& u, V&&... v) { - std::allocator_traits::construct(a, p, std::forward(u), + boost::allocator_construct(a, p, std::forward(u), std::forward(v)...); } #else @@ -97,7 +94,7 @@ template inline void alloc_construct(A& a, T* p, U&& u) { - std::allocator_traits::construct(a, p, std::forward(u)); + boost::allocator_construct(a, p, std::forward(u)); } #endif #else @@ -105,14 +102,14 @@ template inline void alloc_construct(A& a, T* p, const U& u) { - std::allocator_traits::construct(a, p, u); + boost::allocator_construct(a, p, u); } template inline void alloc_construct(A& a, T* p, U& u) { - std::allocator_traits::construct(a, p, u); + boost::allocator_construct(a, p, u); } #endif @@ -122,7 +119,7 @@ alloc_construct_n(A& a, T* p, std::size_t n) { detail::alloc_destroyer hold(a, p); for (std::size_t& i = hold.size(); i < n; ++i) { - std::allocator_traits::construct(a, p + i); + boost::allocator_construct(a, p + i); } hold.size() = 0; } @@ -133,7 +130,7 @@ alloc_construct_n(A& a, T* p, std::size_t n, const T* l, std::size_t m) { detail::alloc_destroyer hold(a, p); for (std::size_t& i = hold.size(); i < n; ++i) { - std::allocator_traits::construct(a, p + i, l[i % m]); + boost::allocator_construct(a, p + i, l[i % m]); } hold.size() = 0; } @@ -144,17 +141,10 @@ alloc_construct_n(A& a, T* p, std::size_t n, I b) { detail::alloc_destroyer hold(a, p); for (std::size_t& i = hold.size(); i < n; void(++i), void(++b)) { - std::allocator_traits::construct(a, p + i, *b); + boost::allocator_construct(a, p + i, *b); } hold.size() = 0; } -#else -template -inline void -alloc_construct(A&, T* p) -{ - ::new(static_cast(p)) T(); -} template inline void @@ -163,49 +153,6 @@ alloc_construct(noinit_adaptor&, T* p) ::new(static_cast(p)) T; } -#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) -#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) -template -inline void -alloc_construct(A&, T* p, U&& u, V&&... v) -{ - ::new(static_cast(p)) T(std::forward(u), std::forward(v)...); -} -#else -template -inline void -alloc_construct(A& a, T* p, U&& u) -{ - ::new(static_cast(p)) T(std::forward(u)); -} -#endif -#else -template -inline void -alloc_construct(A&, T* p, const U& u) -{ - ::new(static_cast(p)) T(u); -} - -template -inline void -alloc_construct(A&, T* p, U& u) -{ - ::new(static_cast(p)) T(u); -} -#endif - -template -inline void -alloc_construct_n(A& a, T* p, std::size_t n) -{ - detail::alloc_destroyer hold(a, p); - for (std::size_t& i = hold.size(); i < n; ++i) { - ::new(static_cast(p + i)) T(); - } - hold.size() = 0; -} - template inline void alloc_construct_n(noinit_adaptor& a, T* p, std::size_t n) @@ -217,29 +164,6 @@ alloc_construct_n(noinit_adaptor& a, T* p, std::size_t n) hold.size() = 0; } -template -inline void -alloc_construct_n(A& a, T* p, std::size_t n, const T* l, std::size_t m) -{ - detail::alloc_destroyer hold(a, p); - for (std::size_t& i = hold.size(); i < n; ++i) { - ::new(static_cast(p + i)) T(l[i % m]); - } - hold.size() = 0; -} - -template -inline void -alloc_construct_n(A& a, T* p, std::size_t n, I b) -{ - detail::alloc_destroyer hold(a, p); - for (std::size_t& i = hold.size(); i < n; void(++i), void(++b)) { - ::new(static_cast(p + i)) T(*b); - } - hold.size() = 0; -} -#endif - } /* boost */ #endif diff --git a/test/alloc_construct_cxx11_test.cpp b/test/alloc_construct_cxx11_test.cpp index 2075d7a..9bdabb9 100644 --- a/test/alloc_construct_cxx11_test.cpp +++ b/test/alloc_construct_cxx11_test.cpp @@ -6,7 +6,7 @@ Distributed under the Boost Software License, Version 1.0. (http://www.boost.org/LICENSE_1_0.txt) */ #include -#if !defined(BOOST_NO_CXX11_ALLOCATOR) +#if defined(BOOST_CORE_ALLOCATOR_DETECTION) #include #include