From 65ece8bac069e1c437244a3954b52e86727bc977 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Thu, 21 Apr 2005 23:43:51 +0000 Subject: [PATCH] Change hash_custom_test to have a cleaner implementation (along the lines of Peter Dimov's suggestion) and to only include the hash headers after declaring the class. [SVN r28394] --- hash/test/hash_custom_test.cpp | 64 ++++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 23 deletions(-) diff --git a/hash/test/hash_custom_test.cpp b/hash/test/hash_custom_test.cpp index f11fba6..3cbe6e9 100644 --- a/hash/test/hash_custom_test.cpp +++ b/hash/test/hash_custom_test.cpp @@ -4,6 +4,41 @@ // 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 +#include + +namespace test +{ + struct custom + { + int value_; + + std::size_t hash() const + { + return value_ * 10; + } + +#if !defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP) + friend std::size_t hash_value(custom const& x ) + { + return x.hash(); + } +#endif + + custom(int x) : value_(x) {} + }; +} + +#if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP) +namespace boost +{ + std::size_t hash_value(test::custom x) + { + return x.hash(); + } +} +#endif + #include "./config.hpp" #ifdef TEST_EXTENSIONS @@ -23,29 +58,6 @@ #include #include -namespace test -{ - struct custom - { - int value_; - - custom(int x) : value_(x) {} - std::size_t hash() const { return value_ * 10; } - }; -} - -#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) -namespace test -#else -namespace boost -#endif -{ - std::size_t hash_value(test::custom x) - { - return x.hash(); - } -} - BOOST_AUTO_UNIT_TEST(custom_tests) { HASH_NAMESPACE::hash custom_hasher; @@ -68,8 +80,14 @@ BOOST_AUTO_UNIT_TEST(custom_tests) HASH_NAMESPACE::hash_combine(seed, test::custom(25)); HASH_NAMESPACE::hash_combine(seed, test::custom(35)); + std::size_t seed2 = 0; + HASH_NAMESPACE::hash_combine(seed2, 50u); + HASH_NAMESPACE::hash_combine(seed2, 250u); + HASH_NAMESPACE::hash_combine(seed2, 350u); + BOOST_CHECK(seed == HASH_NAMESPACE::hash_range(custom_vector.begin(), custom_vector.end())); + BOOST_CHECK(seed == seed2); } #endif // TEST_EXTENSIONS