From 67fc40922dff33fd434762e77f5279919e70fbf0 Mon Sep 17 00:00:00 2001 From: Antony Polukhin Date: Tue, 6 Oct 2026 13:16:56 +0300 Subject: [PATCH] Fixes for hash_value() --- include/boost/pfr/detail/detectors.hpp | 2 +- test/core/run/functions_for.cpp | 1 + test/core/run/ops.cpp | 9 +++++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/include/boost/pfr/detail/detectors.hpp b/include/boost/pfr/detail/detectors.hpp index 6b8972ec..5774c2d0 100644 --- a/include/boost/pfr/detail/detectors.hpp +++ b/include/boost/pfr/detail/detectors.hpp @@ -54,7 +54,7 @@ namespace boost { namespace pfr { namespace detail { template auto hash_detector_msvc_helper(long) -> decltype(std::hash{}(std::declval())); template can_not_apply hash_detector_msvc_helper(int); - template using hash_detector = decltype(hash_detector_msvc_helper(1L)); + template using hash_detector = decltype(hash_detector_msvc_helper(1L)); template auto ostreamable_detector_msvc_helper(long) -> decltype(std::declval() << std::declval()); diff --git a/test/core/run/functions_for.cpp b/test/core/run/functions_for.cpp index 49555237..8a53d591 100644 --- a/test/core/run/functions_for.cpp +++ b/test/core/run/functions_for.cpp @@ -56,6 +56,7 @@ void test_some_comparable_struct() { ss >> s4; std::cout << s4 << std::endl; BOOST_TEST_EQ(s1, s4); + BOOST_TEST_EQ(hash_value(s1), hash_value(s4)); int i = 1, j = 2; BOOST_TEST_NE(i, j); } diff --git a/test/core/run/ops.cpp b/test/core/run/ops.cpp index 662cb840..ef6c4b71 100644 --- a/test/core/run/ops.cpp +++ b/test/core/run/ops.cpp @@ -66,6 +66,7 @@ void test_comparable_struct() { void test_empty_struct() { struct empty {}; + BOOST_TEST_EQ(boost::pfr::hash_value(empty{}), boost::pfr::hash_value(empty{})); std::cout << boost::pfr::io(empty{}); BOOST_TEST(boost::pfr::eq(empty{}, empty{})); } @@ -85,11 +86,19 @@ struct comparable_struct { int main() { test_comparable_struct(); + BOOST_TEST_EQ( + boost::pfr::hash_value(foo::comparable_struct{}), + boost::pfr::hash_value(foo::comparable_struct{}) + ); struct local_comparable_struct { int i; short s; bool bl; int a,b,c,d,e,f; }; test_comparable_struct(); + BOOST_TEST_EQ( + boost::pfr::hash_value(local_comparable_struct{}), + boost::pfr::hash_value(local_comparable_struct{}) + ); struct local_comparable_struct_with_union { int i; short s; bool bl; int a,b,c,d,e; test_union u;