1 
2 // Copyright 2005-2009 Daniel James.
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5 
6 #include "./books.hpp"
7 #include <boost/functional/hash.hpp>
8 #include <cassert>
9 
10 // If std::unordered_set was available:
11 //#include <unordered_set>
12 
13 // This example illustrates how to use boost::hash with a custom hash function.
14 // For full details, see the tutorial.
15 
main()16 int main()
17 {
18     library::book knife(3458, "Zane Grey", "The Hash Knife Outfit");
19     library::book dandelion(1354, "Paul J. Shanley", "Hash & Dandelion Greens");
20 
21     boost::hash<library::book> book_hasher;
22     std::size_t knife_hash_value = book_hasher(knife);
23     (void)knife_hash_value; // suppress unused variable warning
24 
25     // If std::unordered_set was available:
26     //
27     //std::unordered_set<library::book, boost::hash<library::book> > books;
28     //books.insert(knife);
29     //books.insert(library::book(2443, "Lindgren, Torgny", "Hash"));
30     //books.insert(library::book(1953, "Snyder, Bernadette M.",
31     //    "Heavenly Hash: A Tasty Mix of a Mother's Meditations"));
32 
33     //assert(books.find(knife) != books.end());
34     //assert(books.find(dandelion) == books.end());
35 
36     return 0;
37 }
38 
39 namespace library
40 {
operator ==(book const & a,book const & b)41     bool operator==(book const& a, book const& b)
42     {
43         return a.id == b.id;
44     }
45 
hash_value(book const & b)46     std::size_t hash_value(book const& b)
47     {
48         boost::hash<int> hasher;
49         return hasher(b.id);
50     }
51 }
52