diff --git a/include/boost/core/pointer_traits.hpp b/include/boost/core/pointer_traits.hpp index 2e78598..6dae716 100644 --- a/include/boost/core/pointer_traits.hpp +++ b/include/boost/core/pointer_traits.hpp @@ -106,43 +106,74 @@ struct ptr_rebind type; }; -template -struct ptr_void { +#if !defined(BOOST_NO_CXX11_DECLTYPE_N3276) +template +class ptr_to_expr { + template + struct result { + char x, y; + }; + + static E& source(); + + template + static auto check(int) -> result; + + template + static char check(long); + +public: + BOOST_STATIC_CONSTEXPR bool value = sizeof(check(0)) != 1; +}; + +template +struct ptr_to_expr { + BOOST_STATIC_CONSTEXPR bool value = true; +}; + +template +struct ptr_has_to { + BOOST_STATIC_CONSTEXPR bool value = ptr_to_expr::value; +}; +#else +template +struct ptr_has_to { + BOOST_STATIC_CONSTEXPR bool value = true; +}; +#endif + +template +struct ptr_has_to { BOOST_STATIC_CONSTEXPR bool value = false; }; -template<> -struct ptr_void { - BOOST_STATIC_CONSTEXPR bool value = true; +template +struct ptr_has_to { + BOOST_STATIC_CONSTEXPR bool value = false; }; -template<> -struct ptr_void { - BOOST_STATIC_CONSTEXPR bool value = true; +template +struct ptr_has_to { + BOOST_STATIC_CONSTEXPR bool value = false; }; -template<> -struct ptr_void { - BOOST_STATIC_CONSTEXPR bool value = true; +template +struct ptr_has_to { + BOOST_STATIC_CONSTEXPR bool value = false; }; -template<> -struct ptr_void { - BOOST_STATIC_CONSTEXPR bool value = true; -}; - -template::value> +template::value> struct ptr_to { }; template -struct ptr_to { +struct ptr_to { static T pointer_to(E& v) { return T::pointer_to(v); } }; template -struct ptr_to { +struct ptr_to { static T* pointer_to(T& v) BOOST_NOEXCEPT { return boost::addressof(v); } diff --git a/test/pointer_traits_pointer_to_sfinae_test.cpp b/test/pointer_traits_pointer_to_sfinae_test.cpp index 30f6cec..65a0f72 100644 --- a/test/pointer_traits_pointer_to_sfinae_test.cpp +++ b/test/pointer_traits_pointer_to_sfinae_test.cpp @@ -6,17 +6,15 @@ Distributed under the Boost Software License, Version 1.0. (http://www.boost.org/LICENSE_1_0.txt) */ #include -#if !defined(BOOST_NO_CXX11_DECLTYPE_N3276) || !defined(BOOST_MSVC) +#if !defined(BOOST_NO_CXX11_DECLTYPE_N3276) #include #include -#if !defined(BOOST_NO_CXX11_DECLTYPE_N3276) template class has_pointer_to { template struct result { - char one; - char two; + char x, y; }; template @@ -28,41 +26,40 @@ class has_pointer_to { public: static const bool value = sizeof(check(0)) != 1; }; -#else -template -class has_pointer_to { - template - struct result { - char one; - char two; - }; - - template - static result check(int); - - template - static char check(long); - -public: - static const bool value = sizeof(check(0)) != 1; -}; -#endif struct P1 { }; struct P2 { typedef int element_type; + + static int* pointer_to(int& value) { + return &value; + } }; struct P3 { typedef void element_type; }; +struct P4 { + typedef int element_type; +}; + +struct P5 { + typedef int element_type; + + static int* pointer_to() { + return 0; + } +}; + int main() { BOOST_TEST((!has_pointer_to >::value)); BOOST_TEST(has_pointer_to >::value); BOOST_TEST(!has_pointer_to >::value); + BOOST_TEST(!has_pointer_to >::value); + BOOST_TEST(!has_pointer_to >::value); BOOST_TEST(has_pointer_to >::value); BOOST_TEST(!has_pointer_to >::value); return boost::report_errors();