1 
2 // Copyright 2012 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 // This is an example of how to write a hash function for a template
7 // class.
8 
9 #include <boost/container_hash/hash_fwd.hpp>
10 
11 template <typename A, typename B>
12 class my_pair
13 {
14     A value1;
15     B value2;
16 public:
my_pair(A const & v1,B const & v2)17     my_pair(A const& v1, B const& v2)
18         : value1(v1), value2(v2)
19     {}
20 
operator ==(my_pair const & other) const21     bool operator==(my_pair const& other) const
22     {
23         return value1 == other.value1 &&
24             value2 == other.value2;
25     }
26 
hash_value(my_pair const & p)27     friend std::size_t hash_value(my_pair const& p)
28     {
29         std::size_t seed = 0;
30         boost::hash_combine(seed, p.value1);
31         boost::hash_combine(seed, p.value2);
32 
33         return seed;
34     }
35 };
36 
37