From 02b3f91fc3cc482ed89c96b662b37427cda152f1 Mon Sep 17 00:00:00 2001 From: Glen Fernandes Date: Wed, 15 Dec 2021 15:30:42 -0500 Subject: [PATCH] Use same style of detection in pointer_traits and allocator_traits --- include/boost/core/allocator_access.hpp | 54 +++++++++---------- include/boost/core/pointer_traits.hpp | 2 +- .../pointer_traits_pointer_to_sfinae_test.cpp | 2 +- 3 files changed, 28 insertions(+), 30 deletions(-) diff --git a/include/boost/core/allocator_access.hpp b/include/boost/core/allocator_access.hpp index ab5363a..247ad75 100644 --- a/include/boost/core/allocator_access.hpp +++ b/include/boost/core/allocator_access.hpp @@ -386,22 +386,24 @@ allocator_allocate(A& a, typename allocator_size_type::type n, #else namespace detail { -struct alloc_none { }; +template +struct alloc_no { + char x, y; +}; template class alloc_has_allocate { template static auto check(int) - -> decltype(std::declval().allocate(std::declval alloc_no().allocate(std::declval::type>(), std::declval::type>())); + boost::allocator_const_void_pointer::type>()))>; template - static alloc_none check(long); + static char check(long); public: - BOOST_STATIC_CONSTEXPR bool value = - !std::is_same(0)), alloc_none>::value; + BOOST_STATIC_CONSTEXPR bool value = sizeof(check(0)) > 1; }; } /* detail */ @@ -471,15 +473,14 @@ template class alloc_has_construct { template static auto check(int) - -> decltype(std::declval().construct(std::declval(), - std::declval()...)); + -> alloc_no().construct(std::declval(), + std::declval()...))>; template - static alloc_none check(long); + static char check(long); public: - BOOST_STATIC_CONSTEXPR bool value = - !std::is_same(0)), alloc_none>::value; + BOOST_STATIC_CONSTEXPR bool value = sizeof(check(0)) > 1; }; } /* detail */ @@ -516,14 +517,13 @@ template class alloc_has_destroy { template static auto check(int) - -> decltype(std::declval().destroy(std::declval())); + -> alloc_no().destroy(std::declval()))>; template - static alloc_none check(long); + static char check(long); public: - BOOST_STATIC_CONSTEXPR bool value = - !std::is_same(0)), alloc_none>::value; + BOOST_STATIC_CONSTEXPR bool value = sizeof(check(0)) > 1; }; } /* detail */ @@ -549,8 +549,7 @@ namespace detail { #if defined(BOOST_NO_CXX11_ALLOCATOR) template struct alloc_no { - char x; - char y; + char x, y; }; template @@ -571,20 +570,20 @@ class alloc_has_max_size { static char check(long); public: - BOOST_STATIC_CONSTEXPR bool value = sizeof(check(0)) != 1; + BOOST_STATIC_CONSTEXPR bool value = sizeof(check(0)) > 1; }; #else template class alloc_has_max_size { template - static auto check(int) -> decltype(std::declval().max_size()); + static auto check(int) + -> alloc_no().max_size())>; template - static alloc_none check(long); + static char check(long); public: - BOOST_STATIC_CONSTEXPR bool value = - !std::is_same(0)), alloc_none>::value; + BOOST_STATIC_CONSTEXPR bool value = sizeof(check(0)) > 1; }; #endif @@ -637,21 +636,20 @@ class alloc_has_soccc { static char check(long); public: - BOOST_STATIC_CONSTEXPR bool value = sizeof(check(0)) != 1; + BOOST_STATIC_CONSTEXPR bool value = sizeof(check(0)) > 1; }; #else template class alloc_has_soccc { template - static auto check(int) -> decltype(std::declval().select_on_container_copy_construction()); + static auto check(int) -> alloc_no().select_on_container_copy_construction())>; template - static alloc_none check(long); + static char check(long); public: - BOOST_STATIC_CONSTEXPR bool value = - !std::is_same(0)), alloc_none>::value; + BOOST_STATIC_CONSTEXPR bool value = sizeof(check(0)) > 1; }; #endif diff --git a/include/boost/core/pointer_traits.hpp b/include/boost/core/pointer_traits.hpp index 6dae716..71c9df6 100644 --- a/include/boost/core/pointer_traits.hpp +++ b/include/boost/core/pointer_traits.hpp @@ -123,7 +123,7 @@ class ptr_to_expr { static char check(long); public: - BOOST_STATIC_CONSTEXPR bool value = sizeof(check(0)) != 1; + BOOST_STATIC_CONSTEXPR bool value = sizeof(check(0)) > 1; }; template diff --git a/test/pointer_traits_pointer_to_sfinae_test.cpp b/test/pointer_traits_pointer_to_sfinae_test.cpp index 65a0f72..479bfce 100644 --- a/test/pointer_traits_pointer_to_sfinae_test.cpp +++ b/test/pointer_traits_pointer_to_sfinae_test.cpp @@ -24,7 +24,7 @@ class has_pointer_to { static char check(long); public: - static const bool value = sizeof(check(0)) != 1; + static const bool value = sizeof(check(0)) > 1; }; struct P1 { };