From d0ee8e13bdc6db90c4e56c483175d5f4c7742279 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Tue, 1 Nov 2016 16:31:21 +0000 Subject: [PATCH 1/6] Support for removed function objects in C++17 std::unary_function and std::binary_function are removed in C++17, and Visual C++ is the first compiler to do this (when the appropriate macro is defined). I'm not sure what the long term solution should be, but hopefully this will work for now. --- .travis.yml | 3 +++ include/boost/functional/hash/extensions.hpp | 6 +++--- include/boost/functional/hash/hash.hpp | 20 ++++++++++++++++---- test/compile_time.hpp | 2 ++ 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5e9d8ff..2a280e4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,6 +24,8 @@ matrix: env: BJAM_TOOLSET=clang-std03 - compiler: clang env: BJAM_TOOLSET=clang-std11 + - compiler: clang + env: BJAM_TOOLSET=clang-pretend_no_auto_ptr_etc before_script: - | @@ -31,6 +33,7 @@ before_script: echo "using gcc : std11 : g++-4.8 -Werror --std=c++11 ;" >> ~/user-config.jam echo "using clang : std03 : clang++ -Werror --std=c++03 ;" >> ~/user-config.jam echo "using clang : std11 : clang++ -Werror --std=c++11 ;" >> ~/user-config.jam + echo "using clang : pretend_no_auto_ptr_etc : clang++ -Werror --std=c++11 -D_HAS_AUTO_PTR_ETC=0 ;" >> ~/user-config.jam - cat ~/user-config.jam - touch Jamroot.jam diff --git a/include/boost/functional/hash/extensions.hpp b/include/boost/functional/hash/extensions.hpp index eafaefe..cb3c856 100644 --- a/include/boost/functional/hash/extensions.hpp +++ b/include/boost/functional/hash/extensions.hpp @@ -254,7 +254,7 @@ namespace boost #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) template struct hash - : std::unary_function + : boost::hash_detail::hash_base { #if !defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING) std::size_t operator()(T const& val) const @@ -271,7 +271,7 @@ namespace boost #if BOOST_WORKAROUND(__DMC__, <= 0x848) template struct hash - : std::unary_function + : boost::hash_detail::hash_base { std::size_t operator()(const T* val) const { @@ -296,7 +296,7 @@ namespace boost { template struct inner - : std::unary_function + : boost::hash_detail::hash_base { #if !defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING) std::size_t operator()(T const& val) const diff --git a/include/boost/functional/hash/hash.hpp b/include/boost/functional/hash/hash.hpp index 2e21091..a6c8181 100644 --- a/include/boost/functional/hash/hash.hpp +++ b/include/boost/functional/hash/hash.hpp @@ -62,6 +62,18 @@ namespace boost { namespace hash_detail { +#if defined(_HAS_AUTO_PTR_ETC) && !_HAS_AUTO_PTR_ETC + template + struct hash_base + { + typedef T argument_type; + typedef std::size_t result_type; + }; +#else + template + struct hash_base : std::unary_function {}; +#endif + struct enable_hash_value { typedef std::size_t type; }; template struct basic_numbers {}; @@ -419,7 +431,7 @@ namespace boost #define BOOST_HASH_SPECIALIZE(type) \ template <> struct hash \ - : public std::unary_function \ + : public boost::hash_detail::hash_base \ { \ std::size_t operator()(type v) const \ { \ @@ -429,7 +441,7 @@ namespace boost #define BOOST_HASH_SPECIALIZE_REF(type) \ template <> struct hash \ - : public std::unary_function \ + : public boost::hash_detail::hash_base \ { \ std::size_t operator()(type const& v) const \ { \ @@ -483,7 +495,7 @@ namespace boost template struct hash - : public std::unary_function + : public boost::hash_detail::hash_base { std::size_t operator()(T* v) const { @@ -516,7 +528,7 @@ namespace boost { template struct inner - : public std::unary_function + : public boost::hash_detail::hash_base { std::size_t operator()(T val) const { diff --git a/test/compile_time.hpp b/test/compile_time.hpp index 40f39d8..db6bc59 100644 --- a/test/compile_time.hpp +++ b/test/compile_time.hpp @@ -10,7 +10,9 @@ template void compile_time_tests(T*) { +#if !defined(_HAS_AUTO_PTR_ETC) || _HAS_AUTO_PTR_ETC BOOST_STATIC_ASSERT((boost::is_base_and_derived< std::unary_function, BOOST_HASH_TEST_NAMESPACE::hash >::value)); +#endif } From 7159a8616606b1ded4a671a347ad568abc148f11 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Fri, 18 Nov 2016 14:53:12 +0000 Subject: [PATCH 2/6] Only support std::wstring when wchar_t is available This hopefuly fixes #8552. https://svn.boost.org/trac/boost/ticket/8552 --- include/boost/functional/hash/hash.hpp | 2 +- test/hash_string_test.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/boost/functional/hash/hash.hpp b/include/boost/functional/hash/hash.hpp index a6c8181..76c4897 100644 --- a/include/boost/functional/hash/hash.hpp +++ b/include/boost/functional/hash/hash.hpp @@ -468,7 +468,7 @@ namespace boost BOOST_HASH_SPECIALIZE(long double) BOOST_HASH_SPECIALIZE_REF(std::string) -#if !defined(BOOST_NO_STD_WSTRING) +#if !defined(BOOST_NO_STD_WSTRING) && !defined(BOOST_NO_INTRINSIC_WCHAR_T) BOOST_HASH_SPECIALIZE_REF(std::wstring) #endif diff --git a/test/hash_string_test.cpp b/test/hash_string_test.cpp index 5f72d4e..3c83007 100644 --- a/test/hash_string_test.cpp +++ b/test/hash_string_test.cpp @@ -55,7 +55,7 @@ void string0_tests() BOOST_TEST(hasher(x3) != hasher(x4)); } -#if !defined(BOOST_NO_STD_WSTRING) +#if !defined(BOOST_NO_STD_WSTRING) && !defined(BOOST_NO_INTRINSIC_WCHAR_T) void wstring_tests() { compile_time_tests((std::wstring*) 0); @@ -84,7 +84,7 @@ int main() { string_tests(); string0_tests(); -#if !defined(BOOST_NO_STD_WSTRING) +#if !defined(BOOST_NO_STD_WSTRING) && !defined(BOOST_NO_INTRINSIC_WCHAR_T) wstring_tests(); #endif return boost::report_errors(); From ab9f98455a933728bffecce61ff8880daeafa367 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Fri, 18 Nov 2016 14:57:16 +0000 Subject: [PATCH 3/6] Fix cast issue in poor_quality_tests The comparison in the if statement and the test didn't match, which I think is why this test was sometimes failling. But should still try to write something that will work for floats. --- test/hash_number_test.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/test/hash_number_test.cpp b/test/hash_number_test.cpp index 9adb5c6..ebfe4d4 100644 --- a/test/hash_number_test.cpp +++ b/test/hash_number_test.cpp @@ -127,9 +127,13 @@ void poor_quality_tests(T*) BOOST_TEST(x1(T(1)) != x2(T(-1))); if(T(1) != T(2)) BOOST_TEST(x1(T(1)) != x2(T(2))); - if((limits::max)() != (limits::max)() - 1) - BOOST_TEST(x1(static_cast((limits::max)())) - != x2(static_cast((limits::max)() - 1))); + + // TODO: This test is useless for floating point numbers. + T max_number = static_cast((limits::max)()); + T max_minus_one = static_cast(max_number - 1); + if (max_number != max_minus_one) { + BOOST_TEST(x1(max_number) != x1(max_minus_one)); + } } void bool_test() From a489b08e270b8b2415d73efbfd11688e48533ef8 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Mon, 5 Dec 2016 22:42:44 +0000 Subject: [PATCH 4/6] Add changelog entry for 1.63.0 --- doc/changes.qbk | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/changes.qbk b/doc/changes.qbk index ba870de..3195ac8 100644 --- a/doc/changes.qbk +++ b/doc/changes.qbk @@ -182,5 +182,8 @@ [h2 Boost 1.63.0] * Fixed some warnings. +* Only define hash for `std::wstring` when we know we have a `wchar_t`. + Otherwise there's a compile error as there's no overload for hashing + the characters in wide strings. [endsect] From 4b99dbdb644d87318333c3ded37979f3e0c3fa9c Mon Sep 17 00:00:00 2001 From: Daniel James Date: Mon, 5 Dec 2016 23:00:20 +0000 Subject: [PATCH 5/6] Link to ticket in changelog --- doc/changes.qbk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/changes.qbk b/doc/changes.qbk index 3195ac8..f7409c7 100644 --- a/doc/changes.qbk +++ b/doc/changes.qbk @@ -184,6 +184,6 @@ * Fixed some warnings. * Only define hash for `std::wstring` when we know we have a `wchar_t`. Otherwise there's a compile error as there's no overload for hashing - the characters in wide strings. + the characters in wide strings ([ticket 8552]). [endsect] From babb4f8f73546117329e6da826b6eef32cd422cb Mon Sep 17 00:00:00 2001 From: Daniel James Date: Sun, 1 Jan 2017 16:03:48 +0000 Subject: [PATCH 6/6] Hash changelog entry --- doc/changes.qbk | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/doc/changes.qbk b/doc/changes.qbk index f7409c7..8918e0e 100644 --- a/doc/changes.qbk +++ b/doc/changes.qbk @@ -186,4 +186,9 @@ Otherwise there's a compile error as there's no overload for hashing the characters in wide strings ([ticket 8552]). +[h2 Boost 1.64.0] + +* Fix for recent versions of Visual C++ which have removed `std::unary_function` + and `std::binary_function`. + [endsect]