| 
									
										
										
										
											2005-04-01 16:58:09 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | //  (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)
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-21 23:43:51 +00:00
										 |  |  | #include <boost/config.hpp>
 | 
					
						
							|  |  |  | #include <cstddef>
 | 
					
						
							| 
									
										
										
										
											2005-04-01 16:58:09 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace test | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     struct custom | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         int value_; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-21 23:43:51 +00:00
										 |  |  |         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
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-01 16:58:09 +00:00
										 |  |  |         custom(int x) : value_(x) {} | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-21 23:43:51 +00:00
										 |  |  | #if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)
 | 
					
						
							| 
									
										
										
										
											2005-04-01 16:58:09 +00:00
										 |  |  | namespace boost | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2005-04-01 22:47:36 +00:00
										 |  |  |     std::size_t hash_value(test::custom x) | 
					
						
							| 
									
										
										
										
											2005-04-01 16:58:09 +00:00
										 |  |  |     { | 
					
						
							|  |  |  |         return x.hash(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2005-04-21 23:43:51 +00:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "./config.hpp"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef TEST_EXTENSIONS
 | 
					
						
							|  |  |  | #  ifdef TEST_STD_INCLUDES
 | 
					
						
							|  |  |  | #    include <functional>
 | 
					
						
							|  |  |  | #  else
 | 
					
						
							|  |  |  | #    include <boost/functional/hash/hash.hpp>
 | 
					
						
							|  |  |  | #  endif
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define BOOST_AUTO_TEST_MAIN
 | 
					
						
							|  |  |  | #include <boost/test/auto_unit_test.hpp>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef TEST_EXTENSIONS
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <vector>
 | 
					
						
							|  |  |  | #include <string>
 | 
					
						
							|  |  |  | #include <cctype>
 | 
					
						
							| 
									
										
										
										
											2005-04-01 16:58:09 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | BOOST_AUTO_UNIT_TEST(custom_tests) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2005-04-07 21:57:22 +00:00
										 |  |  |     HASH_NAMESPACE::hash<test::custom> custom_hasher; | 
					
						
							| 
									
										
										
										
											2005-04-07 20:53:20 +00:00
										 |  |  |     BOOST_CHECK(custom_hasher(10) == 100u); | 
					
						
							| 
									
										
										
										
											2005-04-01 16:58:09 +00:00
										 |  |  |     test::custom x(55); | 
					
						
							| 
									
										
										
										
											2005-04-07 20:53:20 +00:00
										 |  |  |     BOOST_CHECK(custom_hasher(x) == 550u); | 
					
						
							| 
									
										
										
										
											2005-04-01 16:58:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-16 16:56:27 +00:00
										 |  |  |     { | 
					
						
							|  |  |  |         using namespace HASH_NAMESPACE; | 
					
						
							|  |  |  |         BOOST_CHECK(custom_hasher(x) == hash_value(x)); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-01 16:58:09 +00:00
										 |  |  |     std::vector<test::custom> custom_vector; | 
					
						
							|  |  |  |     custom_vector.push_back(5); | 
					
						
							|  |  |  |     custom_vector.push_back(25); | 
					
						
							|  |  |  |     custom_vector.push_back(35); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     std::size_t seed = 0; | 
					
						
							| 
									
										
										
										
											2005-04-07 21:57:22 +00:00
										 |  |  |     HASH_NAMESPACE::hash_combine(seed, test::custom(5)); | 
					
						
							|  |  |  |     HASH_NAMESPACE::hash_combine(seed, test::custom(25)); | 
					
						
							|  |  |  |     HASH_NAMESPACE::hash_combine(seed, test::custom(35)); | 
					
						
							| 
									
										
										
										
											2005-04-01 16:58:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-21 23:43:51 +00:00
										 |  |  |     std::size_t seed2 = 0; | 
					
						
							|  |  |  |     HASH_NAMESPACE::hash_combine(seed2, 50u); | 
					
						
							|  |  |  |     HASH_NAMESPACE::hash_combine(seed2, 250u); | 
					
						
							|  |  |  |     HASH_NAMESPACE::hash_combine(seed2, 350u); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-07 20:53:20 +00:00
										 |  |  |     BOOST_CHECK(seed == | 
					
						
							| 
									
										
										
										
											2005-04-07 21:57:22 +00:00
										 |  |  |             HASH_NAMESPACE::hash_range(custom_vector.begin(), custom_vector.end())); | 
					
						
							| 
									
										
										
										
											2005-04-21 23:43:51 +00:00
										 |  |  |     BOOST_CHECK(seed == seed2); | 
					
						
							| 
									
										
										
										
											2005-04-01 16:58:09 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-07 21:57:22 +00:00
										 |  |  | #endif // TEST_EXTENSIONS
 |