From 86bff4c2d381c1832b6ff61fabe90635ff91d9fc Mon Sep 17 00:00:00 2001 From: Glen Fernandes Date: Mon, 15 Feb 2021 17:23:42 -0500 Subject: [PATCH] Revise allocator access utilities Now supports MSVC 2013, and no workarounds use allocator_traits. --- include/boost/core/allocator_access.hpp | 238 +++++++++++------------- 1 file changed, 105 insertions(+), 133 deletions(-) diff --git a/include/boost/core/allocator_access.hpp b/include/boost/core/allocator_access.hpp index b3ea62b..8347959 100644 --- a/include/boost/core/allocator_access.hpp +++ b/include/boost/core/allocator_access.hpp @@ -11,11 +11,7 @@ Distributed under the Boost Software License, Version 1.0. #include #if !defined(BOOST_NO_CXX11_ALLOCATOR) #include -#if !defined(BOOST_MSVC) #include -#else -#include -#endif #include #endif #include @@ -23,21 +19,20 @@ Distributed under the Boost Software License, Version 1.0. #include #endif -namespace boost { -namespace detail { - -#if defined(BOOST_NO_CXX11_ALLOCATOR) -struct alloc_false { - BOOST_STATIC_CONSTEXPR bool value = false; -}; -#else -template -struct alloc_void { - typedef void type; -}; +#if defined(_LIBCPP_SUPPRESS_DEPRECATED_PUSH) +_LIBCPP_SUPPRESS_DEPRECATED_PUSH #endif -} /* detail */ +#if defined(_STL_DISABLE_DEPRECATED_WARNING) +_STL_DISABLE_DEPRECATED_WARNING +#endif + +#if defined(_MSC_VER) +#pragma warning(push) +#pragma warning(disable:4996) +#endif + +namespace boost { template struct allocator_value_type { @@ -49,17 +44,21 @@ template struct allocator_pointer { typedef typename A::pointer type; }; -#elif defined(BOOST_MSVC) -template -struct allocator_pointer { - typedef typename std::allocator_traits::pointer type; -}; #else template struct allocator_pointer { typedef typename A::value_type* type; }; +namespace detail { + +template +struct alloc_void { + typedef void type; +}; + +} /* detail */ + template struct allocator_pointer::type> { @@ -72,11 +71,6 @@ template struct allocator_const_pointer { typedef typename A::const_pointer type; }; -#elif defined(BOOST_MSVC) -template -struct allocator_const_pointer { - typedef typename std::allocator_traits::const_pointer type; -}; #else template struct allocator_const_pointer { @@ -137,11 +131,6 @@ template struct allocator_difference_type { typedef typename A::difference_type type; }; -#elif defined(BOOST_MSVC) -template -struct allocator_difference_type { - typedef typename std::allocator_traits::difference_type type; -}; #else template struct allocator_difference_type { @@ -161,11 +150,6 @@ template struct allocator_size_type { typedef typename A::size_type type; }; -#elif defined(BOOST_MSVC) -template -struct allocator_size_type { - typedef typename std::allocator_traits::size_type type; -}; #else template struct allocator_size_type { @@ -181,6 +165,14 @@ struct allocator_size_type struct allocator_propagate_on_container_copy_assignment { typedef detail::alloc_false type; @@ -260,11 +252,6 @@ template struct allocator_rebind { typedef typename A::template rebind::other type; }; -#elif defined(BOOST_MSVC) -template -struct allocator_rebind { - typedef typename std::allocator_traits::template rebind_alloc type; -}; #else namespace detail { @@ -313,36 +300,31 @@ allocator_allocate(A& a, typename allocator_size_type::type n, { return a.allocate(n, h); } -#elif defined(BOOST_MSVC) -template -inline typename allocator_pointer::type -allocator_allocate(A& a, typename allocator_size_type::type n, - typename allocator_const_void_pointer::type h) -{ - return std::allocator_traits::allocate(a, n, h); -} #else namespace detail { -template -struct alloc_has_allocate { - BOOST_STATIC_CONSTEXPR bool value = false; -}; +struct alloc_none { }; -template -struct alloc_has_allocate().allocate(std::declval(), - std::declval()))>::type> { - BOOST_STATIC_CONSTEXPR bool value = true; +template +class alloc_has_allocate { + template + static auto check(int) -> decltype(std::declval().allocate( + std::declval::type>(), + std::declval::type>())); + + template + static alloc_none check(long); + +public: + BOOST_STATIC_CONSTEXPR bool value = + !std::is_same(0)), alloc_none>::value; }; } /* detail */ template -inline typename std::enable_if::type, - typename allocator_const_void_pointer::type>::value, - typename allocator_pointer::type>::type +inline typename std::enable_if::value, + typename allocator_pointer::type>::type allocator_allocate(A& a, typename allocator_size_type::type n, typename allocator_const_void_pointer::type h) { @@ -350,10 +332,8 @@ allocator_allocate(A& a, typename allocator_size_type::type n, } template -inline typename std::enable_if::type, - typename allocator_const_void_pointer::type>::value, - typename allocator_pointer::type>::type +inline typename std::enable_if::value, + typename allocator_pointer::type>::type allocator_allocate(A& a, typename allocator_size_type::type n, typename allocator_const_void_pointer::type) { @@ -400,32 +380,28 @@ allocator_construct(A&, T* p, V& v) ::new((void*)p) T(v); } #endif -#elif defined(BOOST_MSVC) -template -inline void -allocator_construct(A& a, T* p, Args&&... args) -{ - std::allocator_traits::construct(a, p, std::forward(args)...); -} #else namespace detail { -template -struct alloc_has_construct { - BOOST_STATIC_CONSTEXPR bool value = false; -}; - template -struct alloc_has_construct().construct(std::declval(), std::declval()...))>::type, - A, T, Args...> { - BOOST_STATIC_CONSTEXPR bool value = true; +class alloc_has_construct { + template + static auto check(int) + -> decltype(std::declval().construct(std::declval(), + std::declval()...)); + + template + static alloc_none check(long); + +public: + BOOST_STATIC_CONSTEXPR bool value = + !std::is_same(0)), alloc_none>::value; }; } /* detail */ template -inline typename std::enable_if::value>::type allocator_construct(A& a, T* p, Args&&... args) { @@ -433,7 +409,7 @@ allocator_construct(A& a, T* p, Args&&... args) } template -inline typename std::enable_if::value>::type allocator_construct(A&, T* p, Args&&... args) { @@ -449,26 +425,21 @@ allocator_destroy(A&, T* p) p->~T(); (void)p; } -#elif defined(BOOST_MSVC) -template -inline void -allocator_destroy(A& a, T* p) -{ - std::allocator_traits::destroy(a, p); -} #else namespace detail { -template -struct alloc_has_destroy { - BOOST_STATIC_CONSTEXPR bool value = false; -}; - template -struct alloc_has_destroy().destroy(std::declval()))>::type> { - BOOST_STATIC_CONSTEXPR bool value = true; +class alloc_has_destroy { + template + static auto check(int) + -> decltype(std::declval().destroy(std::declval())); + + template + static alloc_none check(long); + +public: + BOOST_STATIC_CONSTEXPR bool value = + !std::is_same(0)), alloc_none>::value; }; } /* detail */ @@ -496,26 +467,20 @@ allocator_max_size(const A& a) { return a.max_size(); } -#elif defined(BOOST_MSVC) -template -inline typename allocator_size_type::type -allocator_max_size(const A& a) -{ - return std::allocator_traits::max_size(a); -} #else namespace detail { -template -struct alloc_has_max_size { - BOOST_STATIC_CONSTEXPR bool value = false; -}; - template -struct alloc_has_max_size().max_size())>::type> { - BOOST_STATIC_CONSTEXPR bool value = true; +class alloc_has_max_size { + template + static auto check(int) -> decltype(std::declval().max_size()); + + template + static alloc_none check(long); + +public: + BOOST_STATIC_CONSTEXPR bool value = + !std::is_same(0)), alloc_none>::value; }; } /* detail */ @@ -545,26 +510,21 @@ allocator_select_on_container_copy_construction(const A& a) { return a; } -#elif defined(BOOST_MSVC) -template -inline A -allocator_select_on_container_copy_construction(const A& a) -{ - return std::allocator_traits::select_on_container_copy_construction(a); -} #else namespace detail { -template -struct alloc_has_soccc { - BOOST_STATIC_CONSTEXPR bool value = false; -}; - template -struct alloc_has_soccc().select_on_container_copy_construction())>::type> { - BOOST_STATIC_CONSTEXPR bool value = true; +class alloc_has_soccc { + template + static auto check(int) + -> decltype(std::declval().select_on_container_copy_construction()); + + template + static alloc_none check(long); + +public: + BOOST_STATIC_CONSTEXPR bool value = + !std::is_same(0)), alloc_none>::value; }; } /* detail */ @@ -630,4 +590,16 @@ using allocator_rebind_t = typename allocator_rebind::type; } /* boost */ +#if defined(_LIBCPP_SUPPRESS_DEPRECATED_POP) +_LIBCPP_SUPPRESS_DEPRECATED_POP +#endif + +#if defined(_STL_RESTORE_DEPRECATED_WARNING) +_STL_RESTORE_DEPRECATED_WARNING +#endif + +#if defined(_MSC_VER) +#pragma warning(pop) +#endif + #endif