Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/functional/hash/examples/books.cpp @ 29

Last change on this file since 29 was 29, checked in by landauf, 16 years ago

updated boost from 1_33_1 to 1_34_1

File size: 1.4 KB
Line 
1
2//  Copyright Daniel James 2005-2006. Use, modification, and distribution are
3//  subject to 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
16int 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
24    // If std::unordered_set was available:
25    //
26    //std::unordered_set<library::book, boost::hash<library::book> > books;
27    //books.insert(knife);
28    //books.insert(library::book(2443, "Lindgren, Torgny", "Hash"));
29    //books.insert(library::book(1953, "Snyder, Bernadette M.",
30    //    "Heavenly Hash: A Tasty Mix of a Mother's Meditations"));
31
32    //assert(books.find(knife) != books.end());
33    //assert(books.find(dandelion) == books.end());
34
35    return 0;
36}
37
38namespace library
39{
40    bool operator==(book const& a, book const& b)
41    {
42        return a.id == b.id;
43    }
44
45    std::size_t hash_value(book const& b)
46    {
47        boost::hash<int> hasher;
48        return hasher(b.id);
49    }
50}
Note: See TracBrowser for help on using the repository browser.