// (C) Copyright Daniel James 2005. // Use, modification and distribution are subject to 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 #define BOOST_AUTO_TEST_MAIN #include #include #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) { boost::hash custom_hasher; BOOST_CHECK(custom_hasher(10) == 100u); test::custom x(55); BOOST_CHECK(custom_hasher(x) == 550u); std::vector custom_vector; custom_vector.push_back(5); custom_vector.push_back(25); custom_vector.push_back(35); std::size_t seed = 0; boost::hash_combine(seed, test::custom(5)); boost::hash_combine(seed, test::custom(25)); boost::hash_combine(seed, test::custom(35)); BOOST_CHECK(seed == boost::hash_range(custom_vector.begin(), custom_vector.end())); }