rippled
hash_pair.h
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of Beast: https://github.com/vinniefalco/Beast
4  Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
5 
6  Permission to use, copy, modify, and/or distribute this software for any
7  purpose with or without fee is hereby granted, provided that the above
8  copyright notice and this permission notice appear in all copies.
9 
10  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18 //==============================================================================
19 
20 #ifndef BEAST_UTILITY_HASH_PAIR_H_INCLUDED
21 #define BEAST_UTILITY_HASH_PAIR_H_INCLUDED
22 
23 #include <functional>
24 #include <utility>
25 
26 #include <boost/functional/hash.hpp>
27 #include <boost/utility/base_from_member.hpp>
28 
29 namespace std {
30 
32 template <class First, class Second>
33 struct hash<std::pair<First, Second>>
34  : private boost::base_from_member<std::hash<First>, 0>,
35  private boost::base_from_member<std::hash<Second>, 1>
36 {
37 private:
38  using first_hash = boost::base_from_member<std::hash<First>, 0>;
39  using second_hash = boost::base_from_member<std::hash<Second>, 1>;
40 
41 public:
42  hash()
43  {
44  }
45 
47  std::hash<First> const& first_hash_,
48  std::hash<Second> const& second_hash_)
49  : first_hash(first_hash_), second_hash(second_hash_)
50  {
51  }
52 
55  {
56  std::size_t result(first_hash::member(value.first));
57  boost::hash_combine(result, second_hash::member(value.second));
58  return result;
59  }
60 
63  {
64  std::size_t result(first_hash::member(value.first));
65  boost::hash_combine(result, second_hash::member(value.second));
66  return result;
67  }
68 };
69 
70 } // namespace std
71 
72 #endif
utility
functional
std::pair
std::hash< std::pair< First, Second > >::operator()
std::size_t operator()(std::pair< First, Second > const &value)
Definition: hash_pair.h:54
std::hash< std::pair< First, Second > >::hash
hash(std::hash< First > const &first_hash_, std::hash< Second > const &second_hash_)
Definition: hash_pair.h:46
std::hash< std::pair< First, Second > >::hash
hash()
Definition: hash_pair.h:42
std
STL namespace.
std::size_t
std::hash< std::pair< First, Second > >::operator()
std::size_t operator()(std::pair< First, Second > const &value) const
Definition: hash_pair.h:62
std::hash< std::pair< First, Second > >::second_hash
boost::base_from_member< std::hash< Second >, 1 > second_hash
Definition: hash_pair.h:39
std::hash
std::hash< std::pair< First, Second > >::first_hash
boost::base_from_member< std::hash< First >, 0 > first_hash
Definition: hash_pair.h:38