diff --git a/include/boost/core/allocator_access.hpp b/include/boost/core/allocator_access.hpp index b51569b..22e47c5 100644 --- a/include/boost/core/allocator_access.hpp +++ b/include/boost/core/allocator_access.hpp @@ -295,106 +295,142 @@ allocator_deallocate(A& a, typename allocator_pointer::type p, namespace detail { -#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) -template -struct alloc_types { }; -#else -template -struct alloc_types { }; -#endif - -template +template struct alloc_has_construct { BOOST_STATIC_CONSTEXPR bool value = false; }; #if defined(BOOST_CORE_ALLOCATOR_DETECTION) -#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) -template -struct alloc_has_construct, typename - alloc_void().construct(alloc_declval(), - alloc_declval()...))>::type> { - BOOST_STATIC_CONSTEXPR bool value = true; -}; -#else -template -struct alloc_has_construct, typename - alloc_void().construct(alloc_declval(), - alloc_declval()))>::type> { +template +struct alloc_has_construct() + .construct(alloc_declval()))>::type> { BOOST_STATIC_CONSTEXPR bool value = true; }; #endif + +} /* detail */ + +template +inline typename detail::alloc_if::value>::type +allocator_construct(A& a, T* p) +{ + a.construct(p); +} + +template +inline typename detail::alloc_if::value>::type +allocator_construct(A&, T* p) +{ + ::new((void*)p) T(); +} + +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && \ + !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) +namespace detail { + +template +struct alloc_has_construct_args { + BOOST_STATIC_CONSTEXPR bool value = false; +}; + +#if defined(BOOST_CORE_ALLOCATOR_DETECTION) +template +struct alloc_has_construct_args().construct(alloc_declval(), + alloc_declval()...))>::type, A, T, Args...> { + BOOST_STATIC_CONSTEXPR bool value = true; +}; +#endif + +} /* detail */ + +template +inline typename detail::alloc_if::value>::type +allocator_construct(A& a, T* p, V&& v, Args&&... args) +{ + a.construct(p, std::forward(v), std::forward(args)...); +} + +template +inline typename detail::alloc_if::value>::type +allocator_construct(A&, T* p, V&& v, Args&&... args) +{ + ::new((void*)p) T(std::forward(v), std::forward(args)...); +} +#else +namespace detail { + +template +struct alloc_has_construct_arg { + BOOST_STATIC_CONSTEXPR bool value = false; +}; + +#if defined(BOOST_CORE_ALLOCATOR_DETECTION) +template +struct alloc_has_construct_arg().construct(alloc_declval(), + alloc_declval()))>::type> { + BOOST_STATIC_CONSTEXPR bool value = true; +}; #endif } /* detail */ #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) -#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) -template -inline typename detail::alloc_if >::value>::type -allocator_construct(A& a, T*p, Args&&... args) -{ - a.construct(p, std::forward(args)...); -} - -template -inline typename detail::alloc_if >::value>::type -allocator_construct(A&, T* p, Args&&... args) -{ - ::new(static_cast(p)) T(std::forward(args)...); -} -#else template -inline typename detail::alloc_if >::value>::type -allocator_construct(A& a, T*p, V&& v) +inline typename detail::alloc_if::value>::type +allocator_construct(A& a, T* p, V&& v) { a.construct(p, std::forward(v)); } template -inline typename detail::alloc_if >::value>::type +inline typename detail::alloc_if::value>::type allocator_construct(A&, T* p, V&& v) { - ::new(static_cast(p)) T(std::forward(v)); + ::new((void*)p) T(std::forward(v)); } -#endif #else template -inline typename detail::alloc_if >::value>::type -allocator_construct(A& a, T*p, const V& v) +inline typename detail::alloc_if::value>::type +allocator_construct(A& a, T* p, const V& v) { a.construct(p, v); } template -inline typename detail::alloc_if >::value>::type +inline typename detail::alloc_if::value>::type allocator_construct(A&, T* p, const V& v) { - ::new(static_cast(p)) T(v); + ::new((void*)p) T(v); } template -inline typename detail::alloc_if >::value>::type -allocator_construct(A& a, T*p, V& v) +inline typename detail::alloc_if::value>::type +allocator_construct(A& a, T* p, V& v) { a.construct(p, v); } template -inline typename detail::alloc_if >::value>::type +inline typename detail::alloc_if::value>::type allocator_construct(A&, T* p, V& v) { - ::new(static_cast(p)) T(v); + ::new((void*)p) T(v); } #endif +#endif namespace detail { @@ -416,7 +452,7 @@ struct alloc_has_destroy inline typename detail::alloc_if::value>::type -allocator_destroy(A& a, T*p) +allocator_destroy(A& a, T* p) { a.destroy(p); } @@ -460,8 +496,8 @@ inline typename detail::alloc_if::value, typename allocator_size_type::type>::type allocator_max_size(const A&) { - return (std::numeric_limits::type>::max)() / - sizeof(typename A::value_type); + return (std::numeric_limits::type>::max)() / sizeof(typename A::value_type); } namespace detail {