diff --git a/include/boost/container_hash/hash/hash.hpp b/include/boost/container_hash/hash/hash.hpp index f648205..f7cd21d 100644 --- a/include/boost/container_hash/hash/hash.hpp +++ b/include/boost/container_hash/hash/hash.hpp @@ -5,7 +5,7 @@ // Based on Peter Dimov's proposal // http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2005/n1756.pdf -// issue 6.18. +// issue 6.18. // // This also contains public domain code from MurmurHash. From the // MurmurHash header: @@ -34,6 +34,10 @@ #include #endif +#if !defined(BOOST_NO_CXX11_HDR_SYSTEM_ERROR) +#include +#endif + #if defined(BOOST_MSVC) #pragma warning(push) @@ -211,6 +215,11 @@ namespace boost std::size_t hash_value(std::type_index); #endif +#if !defined(BOOST_NO_CXX11_HDR_SYSTEM_ERROR) + std::size_t hash_value(std::error_code const&); + std::size_t hash_value(std::error_condition const&); +#endif + // Implementation namespace hash_detail @@ -460,14 +469,30 @@ namespace boost } #endif +#if !defined(BOOST_NO_CXX11_HDR_SYSTEM_ERROR) + inline std::size_t hash_value(std::error_code const& v) { + std::size_t seed = 0; + hash_combine(seed, v.value()); + hash_combine(seed, &v.category()); + return seed; + } + + inline std::size_t hash_value(std::error_condition const& v) { + std::size_t seed = 0; + hash_combine(seed, v.value()); + hash_combine(seed, &v.category()); + return seed; + } +#endif + // // boost::hash // - + // Define the specializations required by the standard. The general purpose // boost::hash is defined later in extensions.hpp if // BOOST_HASH_NO_EXTENSIONS is not defined. - + // BOOST_HASH_SPECIALIZE - define a specialization for a type which is // passed by copy. // diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index ed2fc49..6b11b7f 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -44,6 +44,7 @@ test-suite container_hash/hash [ run hash_map_test.cpp ] [ run hash_complex_test.cpp ] [ run hash_type_index_test.cpp ] + [ run hash_system_error_test.cpp ] [ run hash_std_array_test.cpp ] [ run hash_std_tuple_test.cpp ] [ run hash_std_smart_ptr_test.cpp ] diff --git a/test/hash_info.cpp b/test/hash_info.cpp index 21425c3..8a906c3 100644 --- a/test/hash_info.cpp +++ b/test/hash_info.cpp @@ -78,4 +78,17 @@ int main() { std::cout << "BOOST_HASH_HAS_STRING_VIEW: " << BOOST_HASH_HAS_STRING_VIEW << std::endl; + +#if defined(BOOST_NO_CXX11_HDR_TYPEINDEX) + std::cout << "No " << std::endl; +#else + std::cout << "" << std::endl; +#endif + +#if defined(BOOST_NO_CXX11_HDR_SYSTEM_ERROR) + std::cout << "No " << std::endl; +#else + std::cout << "" << std::endl; +#endif + } diff --git a/test/hash_system_error_test.cpp b/test/hash_system_error_test.cpp new file mode 100644 index 0000000..71eb714 --- /dev/null +++ b/test/hash_system_error_test.cpp @@ -0,0 +1,55 @@ + +// Copyright 2018 Daniel James +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include "./config.hpp" + +#ifndef BOOST_HASH_TEST_STD_INCLUDES +# include +#endif +#include +#include + +#if !defined(BOOST_NO_CXX11_HDR_SYSTEM_ERROR) + +#include + +void test_error_code() +{ + std::error_code err1a = std::make_error_code(std::errc::address_family_not_supported); + std::error_code err1b = std::make_error_code(std::errc::address_family_not_supported); + std::error_code err2 = std::make_error_code(std::errc::address_in_use); + + boost::hash hasher; + + BOOST_TEST(hasher(err1a) == hasher(err1a)); + BOOST_TEST(hasher(err1a) == hasher(err1b)); + BOOST_TEST(hasher(err1a) != hasher(err2)); +} + +void test_error_condition() +{ + std::error_condition err1a = std::make_error_condition(std::errc::address_family_not_supported); + std::error_condition err1b = std::make_error_condition(std::errc::address_family_not_supported); + std::error_condition err2 = std::make_error_condition(std::errc::address_in_use); + + boost::hash hasher; + + BOOST_TEST(hasher(err1a) == hasher(err1a)); + BOOST_TEST(hasher(err1a) == hasher(err1b)); + BOOST_TEST(hasher(err1a) != hasher(err2)); +} + +#endif + +int main() +{ +#if !defined(BOOST_NO_CXX11_HDR_SYSTEM_ERROR) + test_error_code(); + test_error_condition(); +#else + BOOST_LIGHTWEIGHT_TEST_OSTREAM << " not available." << std::endl; +#endif + return boost::report_errors(); +}